In C I have the following struct:
typedef struct _Node{
int data;
struct _Node *left;
struct _Node *right;
} Node;
and the following assembly code:
.section .text
.global _start
_start:
mov $8, %esi
mov $A, %rdi
call func
movq $60, %rax
movq $0, %rdi
syscall
func:
pushq %rbp
movq %rsp, %rbp
cmp (%rdi), %esi
jne continue
mov $1, %eax
jmp finish
continue:
cmpq $0, 4(%rdi)
je next
pushq %rdi
mov 4(%rdi), %rdi
call func
pop %rdi
cmp $1, %eax
je finish
next:
cmpq $0, 12(%rdi)
je fail
pushq %rid
mov 12(%rdi), %rdi
call func
pop %rdi
cmp $1, %eax
je finish
fail:
mov $0, %rax
finish:
leave
ret
Now trying to write it in C I have a question:
__long__ func ( Node *root, __int__ x){
if (root->data == __x__ )
return 1;
if (root->left != null)
if (_____??_____)
return ___ func(root->left, x)____;
if (root->right != null)
return ____func(root->right, x)____;
}
Why we have 2 if-if inside each other? If left isn't null the assembly code calls the function with the left son and doesn't do another condition check (ie cmp call).