#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 */
typedef void rb3_head;

/* Variables and functions */
void *rb3_get_child(void *, int);
scalar_t__ rb3_has_child(void *, int);
__attribute__((no)) struct rb3_head *
rb3_get_minmax_in_subtree(struct rb3_head *head, int dir) {
  if (!head)
    return ((void *)0);
  while (rb3_has_child(head, dir))
    head = rb3_get_child(head, dir);
  return head;
}


x86 assembly (clang, -O0):
<rb3_get_minmax_in_subtree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <rb3_get_minmax_in_subtree+0x27>
movq   $0x0,-0x8(%rbp)
jmp    117f <rb3_get_minmax_in_subtree+0x5f>
jmp    114c <rb3_get_minmax_in_subtree+0x2c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <rb3_has_child@plt>
cmp    $0x0,%rax
je     1177 <rb3_get_minmax_in_subtree+0x57>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <rb3_get_child@plt>
mov    %rax,-0x10(%rbp)
jmp    114c <rb3_get_minmax_in_subtree+0x2c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rb3_get_minmax_in_subtree>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     114e <rb3_get_minmax_in_subtree+0x2e>
mov    %esi,%ebp
mov    %rdi,%rbx
nopl   (%rax)
mov    %ebp,%esi
call   1040 <rb3_has_child@plt>
test   %rax,%rax
je     1150 <rb3_get_minmax_in_subtree+0x30>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <rb3_get_child@plt>
mov    %rax,%rbx
mov    %rax,%rdi
jmp    1130 <rb3_get_minmax_in_subtree+0x10>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.rb3_head = type opaque
define %struct.rb3_head* @rb3_get_minmax_in_subtree(%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 = icmp ne %struct.rb3_head* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
store %struct.rb3_head* null, %struct.rb3_head** %3
br label %24
9: ; preds = %2
br label %10
10: ; preds = %16, %9
%11 = load %struct.rb3_head*, %struct.rb3_head** %4
%12 = bitcast %struct.rb3_head* %11 to i8*
%13 = load i32, i32* %5
%14 = call i64 @rb3_has_child(i8* %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %10
%17 = load %struct.rb3_head*, %struct.rb3_head** %4
%18 = bitcast %struct.rb3_head* %17 to i8*
%19 = load i32, i32* %5
%20 = call i8* @rb3_get_child(i8* %18, i32 %19)
%21 = bitcast i8* %20 to %struct.rb3_head*
store %struct.rb3_head* %21, %struct.rb3_head** %4
br label %10
22: ; preds = %10
%23 = load %struct.rb3_head*, %struct.rb3_head** %4
store %struct.rb3_head* %23, %struct.rb3_head** %3
br label %24
24: ; preds = %22, %8
%25 = load %struct.rb3_head*, %struct.rb3_head** %3
ret %struct.rb3_head* %25
}

LLVM IR (-O2):
%struct.rb3_head = type opaque
define %struct.rb3_head* @rb3_get_minmax_in_subtree(%struct.rb3_head* %0, i32 %1) {
%3 = icmp eq %struct.rb3_head* %0, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = bitcast %struct.rb3_head* %0 to i8*
%6 = tail call i64 @rb3_has_child(i8* %5, i32 %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %4, %8
%9 = phi i8* [ %10, %8 ], [ %5, %4 ]
%10 = tail call i8* @rb3_get_child(i8* %9, i32 %1)
%11 = tail call i64 @rb3_has_child(i8* %10, i32 %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %8
13: ; preds = %8
%14 = bitcast i8* %10 to %struct.rb3_head*
br label %15
15: ; preds = %4, %13, %2
%16 = phi %struct.rb3_head* [ null, %2 ], [ %14, %13 ], [ %0, %4 ]
ret %struct.rb3_head* %16
}