#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct node {
  int dummy;
};

/* Variables and functions */
scalar_t__ isExternal(struct node *);
int key(struct node *);
struct node *leftChild(struct node *);
struct node *rightChild(struct node *);
struct node *treeSearch(int k, struct node *node) {
  if (isExternal(node))
    return node;
  if (key(node) == k)
    return node;
  else if (k < key(node))
    return treeSearch(k, leftChild(node));
  else
    return treeSearch(k, rightChild(node));
}


x86 assembly (clang, -O0):
<treeSearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <isExternal@plt>
cmp    $0x0,%rax
je     117f <treeSearch+0x2f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <treeSearch+0xab>
mov    -0x18(%rbp),%rdi
call   1030 <key@plt>
cmp    -0xc(%rbp),%eax
jne    119e <treeSearch+0x4e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <treeSearch+0xab>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <key@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11dd <treeSearch+0x8d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <leftChild@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rsi
call   1040 <treeSearch@plt>
mov    %rax,-0x8(%rbp)
jmp    11fb <treeSearch+0xab>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <rightChild@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rsi
call   1040 <treeSearch@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<treeSearch>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
jmp    115b <treeSearch+0x1b>
nopl   (%rax)
call   1050 <leftChild@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <isExternal@plt>
test   %rax,%rax
jne    1187 <treeSearch+0x47>
mov    %rbx,%rdi
call   1030 <key@plt>
cmp    %ebp,%eax
je     1187 <treeSearch+0x47>
mov    %rbx,%rdi
call   1030 <key@plt>
mov    %rbx,%rdi
cmp    %ebp,%eax
jg     1150 <treeSearch+0x10>
call   1040 <rightChild@plt>
jmp    1155 <treeSearch+0x15>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
define %struct.node* @treeSearch(i32 %0, %struct.node* %1) {
%3 = alloca %struct.node*
%4 = alloca i32
%5 = alloca %struct.node*
store i32 %0, i32* %4
store %struct.node* %1, %struct.node** %5
%6 = load %struct.node*, %struct.node** %5
%7 = call i64 @isExternal(%struct.node* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load %struct.node*, %struct.node** %5
store %struct.node* %10, %struct.node** %3
br label %33
11: ; preds = %2
%12 = load %struct.node*, %struct.node** %5
%13 = call i32 @key(%struct.node* %12)
%14 = load i32, i32* %4
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load %struct.node*, %struct.node** %5
store %struct.node* %17, %struct.node** %3
br label %33
18: ; preds = %11
%19 = load i32, i32* %4
%20 = load %struct.node*, %struct.node** %5
%21 = call i32 @key(%struct.node* %20)
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i32, i32* %4
%25 = load %struct.node*, %struct.node** %5
%26 = call %struct.node* @leftChild(%struct.node* %25)
%27 = call %struct.node* @treeSearch(i32 %24, %struct.node* %26)
store %struct.node* %27, %struct.node** %3
br label %33
28: ; preds = %18
%29 = load i32, i32* %4
%30 = load %struct.node*, %struct.node** %5
%31 = call %struct.node* @rightChild(%struct.node* %30)
%32 = call %struct.node* @treeSearch(i32 %29, %struct.node* %31)
store %struct.node* %32, %struct.node** %3
br label %33
33: ; preds = %28, %23, %16, %9
%34 = load %struct.node*, %struct.node** %3
ret %struct.node* %34
}

LLVM IR (-O2):
%struct.node = type { i32 }
define %struct.node* @treeSearch(i32 %0, %struct.node* %1) {
%3 = tail call i64 @isExternal(%struct.node* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %20
5: ; preds = %2, %14
%6 = phi %struct.node* [ %15, %14 ], [ %1, %2 ]
%7 = tail call i32 @key(%struct.node* %6)
%8 = icmp eq i32 %7, %0
br i1 %8, label %20, label %9
9: ; preds = %5
%10 = tail call i32 @key(%struct.node* %6)
%11 = icmp sgt i32 %10, %0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = tail call %struct.node* @leftChild(%struct.node* %6)
br label %14
14: ; preds = %12, %18
%15 = phi %struct.node* [ %13, %12 ], [ %19, %18 ]
%16 = tail call i64 @isExternal(%struct.node* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %5, label %20
18: ; preds = %9
%19 = tail call %struct.node* @rightChild(%struct.node* %6)
br label %14
20: ; preds = %14, %5, %2
%21 = phi %struct.node* [ %1, %2 ], [ %6, %5 ], [ %15, %14 ]
ret %struct.node* %21
}