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

/* Variables and functions */
struct rb3_head *rb3_get_prevnext_ancestor(struct rb3_head *, int);
struct rb3_head *rb3_get_prevnext_descendant(struct rb3_head *, int);
scalar_t__ rb3_has_child(struct rb3_head *, int);
extern struct rb3_head *rb3_get_prevnext(struct rb3_head *head, int dir) {
  if (rb3_has_child(head, dir))
    return rb3_get_prevnext_descendant(head, dir);
  else
    return rb3_get_prevnext_ancestor(head, dir);
}


x86 assembly (clang, -O0):
<rb3_get_prevnext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <rb3_has_child@plt>
cmp    $0x0,%rax
je     116a <rb3_get_prevnext+0x3a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <rb3_get_prevnext_descendant@plt>
mov    %rax,-0x8(%rbp)
jmp    117a <rb3_get_prevnext+0x4a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <rb3_get_prevnext_ancestor@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rb3_get_prevnext>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <rb3_has_child@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
test   %rax,%rax
je     1152 <rb3_get_prevnext+0x22>
pop    %rbx
pop    %rbp
jmp    1040 <rb3_get_prevnext_descendant@plt>
pop    %rbx
pop    %rbp
jmp    1030 <rb3_get_prevnext_ancestor@plt>

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

LLVM IR (-O2):
%struct.rb3_head = type { i32 }
define %struct.rb3_head* @rb3_get_prevnext(%struct.rb3_head* %0, i32 %1) {
%3 = tail call i64 @rb3_has_child(%struct.rb3_head* %0, i32 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call %struct.rb3_head* @rb3_get_prevnext_descendant(%struct.rb3_head* %0, i32 %1)
br label %9
7: ; preds = %2
%8 = tail call %struct.rb3_head* @rb3_get_prevnext_ancestor(%struct.rb3_head* %0, i32 %1)
br label %9
9: ; preds = %7, %5
%10 = phi %struct.rb3_head* [ %6, %5 ], [ %8, %7 ]
ret %struct.rb3_head* %10
}