#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 avl_tree_node {
  int dummy;
};

/* Variables and functions */
struct avl_tree_node *avl_get_child(struct avl_tree_node const *, int);
__attribute__((always_)) struct avl_tree_node *
avl_tree_first_or_last_in_order(const struct avl_tree_node *root, int sign) {
  const struct avl_tree_node *first = root;
  if (first) {
    while (avl_get_child(first, +sign)) {
      first = avl_get_child(first, +sign);
    }
  }
  return (struct avl_tree_node *)first;
}


x86 assembly (clang, -O0):
<avl_tree_first_or_last_in_order>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1167 <avl_tree_first_or_last_in_order+0x57>
jmp    1137 <avl_tree_first_or_last_in_order+0x27>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <avl_get_child@plt>
cmp    $0x0,%rax
je     1162 <avl_tree_first_or_last_in_order+0x52>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <avl_get_child@plt>
mov    %rax,-0x18(%rbp)
jmp    1137 <avl_tree_first_or_last_in_order+0x27>
jmp    1167 <avl_tree_first_or_last_in_order+0x57>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<avl_tree_first_or_last_in_order>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     113e <avl_tree_first_or_last_in_order+0x2e>
mov    %esi,%ebp
mov    %rdi,%rbx
nopl   (%rax)
mov    %ebp,%esi
call   1030 <avl_get_child@plt>
test   %rax,%rax
je     1140 <avl_tree_first_or_last_in_order+0x30>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <avl_get_child@plt>
mov    %rax,%rbx
mov    %rax,%rdi
jmp    1120 <avl_tree_first_or_last_in_order+0x10>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.avl_tree_node = type { i32 }
define %struct.avl_tree_node* @avl_tree_first_or_last_in_order(%struct.avl_tree_node* %0, i32 %1) {
%3 = alloca %struct.avl_tree_node*
%4 = alloca i32
%5 = alloca %struct.avl_tree_node*
store %struct.avl_tree_node* %0, %struct.avl_tree_node** %3
store i32 %1, i32* %4
%6 = load %struct.avl_tree_node*, %struct.avl_tree_node** %3
store %struct.avl_tree_node* %6, %struct.avl_tree_node** %5
%7 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%8 = icmp ne %struct.avl_tree_node* %7, null
br i1 %8, label %9, label %20
9: ; preds = %2
br label %10
10: ; preds = %15, %9
%11 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%12 = load i32, i32* %4
%13 = call %struct.avl_tree_node* @avl_get_child(%struct.avl_tree_node* %11, i32 %12)
%14 = icmp ne %struct.avl_tree_node* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
%17 = load i32, i32* %4
%18 = call %struct.avl_tree_node* @avl_get_child(%struct.avl_tree_node* %16, i32 %17)
store %struct.avl_tree_node* %18, %struct.avl_tree_node** %5
br label %10
19: ; preds = %10
br label %20
20: ; preds = %19, %2
%21 = load %struct.avl_tree_node*, %struct.avl_tree_node** %5
ret %struct.avl_tree_node* %21
}

LLVM IR (-O2):
%struct.avl_tree_node = type { i32 }
define %struct.avl_tree_node* @avl_tree_first_or_last_in_order(%struct.avl_tree_node* %0, i32 %1) {
%3 = icmp eq %struct.avl_tree_node* %0, null
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = tail call %struct.avl_tree_node* @avl_get_child(%struct.avl_tree_node* %0, i32 %1)
%6 = icmp eq %struct.avl_tree_node* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4, %7
%8 = phi %struct.avl_tree_node* [ %9, %7 ], [ %0, %4 ]
%9 = tail call %struct.avl_tree_node* @avl_get_child(%struct.avl_tree_node* %8, i32 %1)
%10 = tail call %struct.avl_tree_node* @avl_get_child(%struct.avl_tree_node* %9, i32 %1)
%11 = icmp eq %struct.avl_tree_node* %10, null
br i1 %11, label %12, label %7
12: ; preds = %7, %4, %2
%13 = phi %struct.avl_tree_node* [ null, %2 ], [ %0, %4 ], [ %9, %7 ]
ret %struct.avl_tree_node* %13
}