#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 cl_tree {
  int dummy;
};
struct cl_node {
  int dummy;
};

/* Variables and functions */
void const *cl_node_key(struct cl_node *);
struct cl_node *cl_node_left(struct cl_node *);
int /*<<< orphan*/ cl_tree_is_leaf(struct cl_tree *, struct cl_node *);
const void *cl_tree_peek_sub(struct cl_tree *tree, struct cl_node *n) {
  while (!cl_tree_is_leaf(tree, cl_node_left(n)))
    n = cl_node_left(n);
  return cl_node_key(n);
}


x86 assembly (clang, -O0):
<cl_tree_peek_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <cl_node_left@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rsi
call   1050 <cl_tree_is_leaf@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1172 <cl_tree_peek_sub+0x42>
jmp    1184 <cl_tree_peek_sub+0x54>
mov    -0x10(%rbp),%rdi
call   1040 <cl_node_left@plt>
mov    %rax,-0x10(%rbp)
jmp    1140 <cl_tree_peek_sub+0x10>
mov    -0x10(%rbp),%rdi
call   1030 <cl_node_key@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cl_tree_peek_sub>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
nopl   (%rax)
call   1040 <cl_node_left@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <cl_tree_is_leaf@plt>
mov    %rbx,%rdi
test   %eax,%eax
jne    1164 <cl_tree_peek_sub+0x34>
call   1040 <cl_node_left@plt>
mov    %rax,%rbx
mov    %rax,%rdi
jmp    1140 <cl_tree_peek_sub+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <cl_node_key@plt>

LLVM IR (-O0):
%struct.cl_tree = type { i32 }
%struct.cl_node = type { i32 }
define i8* @cl_tree_peek_sub(%struct.cl_tree* %0, %struct.cl_node* %1) {
%3 = alloca %struct.cl_tree*
%4 = alloca %struct.cl_node*
store %struct.cl_tree* %0, %struct.cl_tree** %3
store %struct.cl_node* %1, %struct.cl_node** %4
br label %5
5: ; preds = %12, %2
%6 = load %struct.cl_tree*, %struct.cl_tree** %3
%7 = load %struct.cl_node*, %struct.cl_node** %4
%8 = call %struct.cl_node* @cl_node_left(%struct.cl_node* %7)
%9 = call i32 @cl_tree_is_leaf(%struct.cl_tree* %6, %struct.cl_node* %8)
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = load %struct.cl_node*, %struct.cl_node** %4
%14 = call %struct.cl_node* @cl_node_left(%struct.cl_node* %13)
store %struct.cl_node* %14, %struct.cl_node** %4
br label %5
15: ; preds = %5
%16 = load %struct.cl_node*, %struct.cl_node** %4
%17 = call i8* @cl_node_key(%struct.cl_node* %16)
ret i8* %17
}

LLVM IR (-O2):
%struct.cl_tree = type { i32 }
%struct.cl_node = type { i32 }
define i8* @cl_tree_peek_sub(%struct.cl_tree* %0, %struct.cl_node* %1) {
%3 = tail call %struct.cl_node* @cl_node_left(%struct.cl_node* %1)
%4 = tail call i32 @cl_tree_is_leaf(%struct.cl_tree* %0, %struct.cl_node* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %2, %6
%7 = phi %struct.cl_node* [ %8, %6 ], [ %1, %2 ]
%8 = tail call %struct.cl_node* @cl_node_left(%struct.cl_node* %7)
%9 = tail call %struct.cl_node* @cl_node_left(%struct.cl_node* %8)
%10 = tail call i32 @cl_tree_is_leaf(%struct.cl_tree* %0, %struct.cl_node* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %6, %2
%13 = phi %struct.cl_node* [ %1, %2 ], [ %8, %6 ]
%14 = tail call i8* @cl_node_key(%struct.cl_node* %13)
ret i8* %14
}