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

/* Variables and functions */
struct bstree_node *get_first(struct bstree_node *);
struct bstree_node *get_next(struct bstree_node const *);
struct bstree_node *get_right(struct bstree_node const *);
struct bstree_node *bstree_next(const struct bstree_node *node) {
  struct bstree_node *right = get_right(node);
  if (right)
    return get_first(right);
  return get_next(node);
}


x86 assembly (clang, -O0):
<bstree_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <get_right@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1166 <bstree_next+0x36>
mov    -0x18(%rbp),%rdi
call   1030 <get_first@plt>
mov    %rax,-0x8(%rbp)
jmp    1173 <bstree_next+0x43>
mov    -0x10(%rbp),%rdi
call   1050 <get_next@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bstree_next>:
push   %rbx
mov    %rdi,%rbx
call   1040 <get_right@plt>
test   %rax,%rax
je     1147 <bstree_next+0x17>
mov    %rax,%rdi
pop    %rbx
jmp    1030 <get_first@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <get_next@plt>

LLVM IR (-O0):
%struct.bstree_node = type { i32 }
define %struct.bstree_node* @bstree_next(%struct.bstree_node* %0) {
%2 = alloca %struct.bstree_node*
%3 = alloca %struct.bstree_node*
%4 = alloca %struct.bstree_node*
store %struct.bstree_node* %0, %struct.bstree_node** %3
%5 = load %struct.bstree_node*, %struct.bstree_node** %3
%6 = call %struct.bstree_node* @get_right(%struct.bstree_node* %5)
store %struct.bstree_node* %6, %struct.bstree_node** %4
%7 = load %struct.bstree_node*, %struct.bstree_node** %4
%8 = icmp ne %struct.bstree_node* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load %struct.bstree_node*, %struct.bstree_node** %4
%11 = call %struct.bstree_node* @get_first(%struct.bstree_node* %10)
store %struct.bstree_node* %11, %struct.bstree_node** %2
br label %15
12: ; preds = %1
%13 = load %struct.bstree_node*, %struct.bstree_node** %3
%14 = call %struct.bstree_node* @get_next(%struct.bstree_node* %13)
store %struct.bstree_node* %14, %struct.bstree_node** %2
br label %15
15: ; preds = %12, %9
%16 = load %struct.bstree_node*, %struct.bstree_node** %2
ret %struct.bstree_node* %16
}

LLVM IR (-O2):
%struct.bstree_node = type { i32 }
define %struct.bstree_node* @bstree_next(%struct.bstree_node* %0) {
%2 = tail call %struct.bstree_node* @get_right(%struct.bstree_node* %0)
%3 = icmp eq %struct.bstree_node* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call %struct.bstree_node* @get_first(%struct.bstree_node* %2)
br label %8
6: ; preds = %1
%7 = tail call %struct.bstree_node* @get_next(%struct.bstree_node* %0)
br label %8
8: ; preds = %6, %4
%9 = phi %struct.bstree_node* [ %5, %4 ], [ %7, %6 ]
ret %struct.bstree_node* %9
}