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

/* Variables and functions */
struct trie_node *begin(struct trie_node *);
struct trie_node *trie_node_get_negative(struct trie_node *);
struct trie_node *trie_node_get_parent(struct trie_node *);
struct trie_node *trie_next(struct trie_node *node) {
  while (node) {
    struct trie_node *negative = trie_node_get_negative(node);
    while (negative) {
      struct trie_node *res = begin(negative);
      if (res)
        return res;
      negative = trie_node_get_negative(negative);
    }
    node = trie_node_get_parent(node);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<trie_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a8 <trie_next+0x78>
mov    -0x10(%rbp),%rdi
call   1030 <trie_node_get_negative@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1196 <trie_next+0x66>
mov    -0x18(%rbp),%rdi
call   1050 <begin@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1184 <trie_next+0x54>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b0 <trie_next+0x80>
mov    -0x18(%rbp),%rdi
call   1030 <trie_node_get_negative@plt>
mov    %rax,-0x18(%rbp)
jmp    1154 <trie_next+0x24>
mov    -0x10(%rbp),%rdi
call   1040 <trie_node_get_parent@plt>
mov    %rax,-0x10(%rbp)
jmp    113c <trie_next+0xc>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trie_next>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117f <trie_next+0x4f>
mov    %rdi,%r14
jmp    1150 <trie_next+0x20>
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <trie_node_get_parent@plt>
mov    %rax,%r14
test   %rax,%rax
je     117f <trie_next+0x4f>
mov    %r14,%rdi
call   1030 <trie_node_get_negative@plt>
test   %rax,%rax
je     1140 <trie_next+0x10>
mov    %rax,%rbx
mov    %rbx,%rdi
call   1050 <begin@plt>
test   %rax,%rax
jne    1181 <trie_next+0x51>
mov    %rbx,%rdi
call   1030 <trie_node_get_negative@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <trie_next+0x30>
jmp    1140 <trie_next+0x10>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.trie_node = type { i32 }
define %struct.trie_node* @trie_next(%struct.trie_node* %0) {
%2 = alloca %struct.trie_node*
%3 = alloca %struct.trie_node*
%4 = alloca %struct.trie_node*
%5 = alloca %struct.trie_node*
store %struct.trie_node* %0, %struct.trie_node** %3
br label %6
6: ; preds = %25, %1
%7 = load %struct.trie_node*, %struct.trie_node** %3
%8 = icmp ne %struct.trie_node* %7, null
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = load %struct.trie_node*, %struct.trie_node** %3
%11 = call %struct.trie_node* @trie_node_get_negative(%struct.trie_node* %10)
store %struct.trie_node* %11, %struct.trie_node** %4
br label %12
12: ; preds = %22, %9
%13 = load %struct.trie_node*, %struct.trie_node** %4
%14 = icmp ne %struct.trie_node* %13, null
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load %struct.trie_node*, %struct.trie_node** %4
%17 = call %struct.trie_node* @begin(%struct.trie_node* %16)
store %struct.trie_node* %17, %struct.trie_node** %5
%18 = load %struct.trie_node*, %struct.trie_node** %5
%19 = icmp ne %struct.trie_node* %18, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load %struct.trie_node*, %struct.trie_node** %5
store %struct.trie_node* %21, %struct.trie_node** %2
br label %29
22: ; preds = %15
%23 = load %struct.trie_node*, %struct.trie_node** %4
%24 = call %struct.trie_node* @trie_node_get_negative(%struct.trie_node* %23)
store %struct.trie_node* %24, %struct.trie_node** %4
br label %12
25: ; preds = %12
%26 = load %struct.trie_node*, %struct.trie_node** %3
%27 = call %struct.trie_node* @trie_node_get_parent(%struct.trie_node* %26)
store %struct.trie_node* %27, %struct.trie_node** %3
br label %6
28: ; preds = %6
store %struct.trie_node* null, %struct.trie_node** %2
br label %29
29: ; preds = %28, %20
%30 = load %struct.trie_node*, %struct.trie_node** %2
ret %struct.trie_node* %30
}

LLVM IR (-O2):
%struct.trie_node = type { i32 }
define %struct.trie_node* @trie_next(%struct.trie_node* %0) {
%2 = icmp eq %struct.trie_node* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1, %14
%4 = phi %struct.trie_node* [ %15, %14 ], [ %0, %1 ]
%5 = tail call %struct.trie_node* @trie_node_get_negative(%struct.trie_node* %4)
%6 = icmp eq %struct.trie_node* %5, null
br i1 %6, label %14, label %7
7: ; preds = %3, %11
%8 = phi %struct.trie_node* [ %12, %11 ], [ %5, %3 ]
%9 = tail call %struct.trie_node* @begin(%struct.trie_node* %8)
%10 = icmp eq %struct.trie_node* %9, null
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = tail call %struct.trie_node* @trie_node_get_negative(%struct.trie_node* %8)
%13 = icmp eq %struct.trie_node* %12, null
br i1 %13, label %14, label %7
14: ; preds = %11, %3
%15 = tail call %struct.trie_node* @trie_node_get_parent(%struct.trie_node* %4)
%16 = icmp eq %struct.trie_node* %15, null
br i1 %16, label %17, label %3
17: ; preds = %14, %7, %1
%18 = phi %struct.trie_node* [ null, %1 ], [ %9, %7 ], [ null, %14 ]
ret %struct.trie_node* %18
}