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

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


x86 assembly (clang, -O0):
<splaytree_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 <splaytree_next+0x36>
mov    -0x18(%rbp),%rdi
call   1030 <get_first@plt>
mov    %rax,-0x8(%rbp)
jmp    1173 <splaytree_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):
<splaytree_next>:
push   %rbx
mov    %rdi,%rbx
call   1040 <get_right@plt>
test   %rax,%rax
je     1147 <splaytree_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.splaytree_node = type { i32 }
define %struct.splaytree_node* @splaytree_next(%struct.splaytree_node* %0) {
%2 = alloca %struct.splaytree_node*
%3 = alloca %struct.splaytree_node*
%4 = alloca %struct.splaytree_node*
store %struct.splaytree_node* %0, %struct.splaytree_node** %3
%5 = load %struct.splaytree_node*, %struct.splaytree_node** %3
%6 = call %struct.splaytree_node* @get_right(%struct.splaytree_node* %5)
store %struct.splaytree_node* %6, %struct.splaytree_node** %4
%7 = load %struct.splaytree_node*, %struct.splaytree_node** %4
%8 = icmp ne %struct.splaytree_node* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load %struct.splaytree_node*, %struct.splaytree_node** %4
%11 = call %struct.splaytree_node* @get_first(%struct.splaytree_node* %10)
store %struct.splaytree_node* %11, %struct.splaytree_node** %2
br label %15
12: ; preds = %1
%13 = load %struct.splaytree_node*, %struct.splaytree_node** %3
%14 = call %struct.splaytree_node* @get_next(%struct.splaytree_node* %13)
store %struct.splaytree_node* %14, %struct.splaytree_node** %2
br label %15
15: ; preds = %12, %9
%16 = load %struct.splaytree_node*, %struct.splaytree_node** %2
ret %struct.splaytree_node* %16
}

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