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

/* Variables and functions */
int cursor_advance_down(struct cursor *);
int /*<<< orphan*/ cursor_advance_up(struct cursor *);
scalar_t__ cursor_level_finished(struct cursor *);
int cursor_advance(struct cursor *cursor) {
  int ret;
  do {
    if (!cursor_advance_up(cursor))
      return 0;
  } while (cursor_level_finished(cursor));
  do {
    ret = cursor_advance_down(cursor);
    if (ret < 0)
      return ret;
  } while (ret);
  return 1;
}


x86 assembly (clang, -O0):
<cursor_advance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <cursor_advance_up@plt>
cmp    $0x0,%eax
jne    115a <cursor_advance+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11ae <cursor_advance+0x7e>
jmp    115f <cursor_advance+0x2f>
mov    -0x10(%rbp),%rdi
call   1040 <cursor_level_finished@plt>
cmp    $0x0,%rax
jne    113c <cursor_advance+0xc>
jmp    1177 <cursor_advance+0x47>
mov    -0x10(%rbp),%rdi
call   1050 <cursor_advance_down@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1198 <cursor_advance+0x68>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <cursor_advance+0x7e>
jmp    119d <cursor_advance+0x6d>
cmpl   $0x0,-0x14(%rbp)
jne    1177 <cursor_advance+0x47>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cursor_advance>:
push   %rbx
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <cursor_advance_up@plt>
test   %eax,%eax
je     1170 <cursor_advance+0x40>
mov    %rbx,%rdi
call   1040 <cursor_level_finished@plt>
test   %rax,%rax
jne    1140 <cursor_advance+0x10>
jmp    1162 <cursor_advance+0x32>
nopl   0x0(%rax,%rax,1)
je     1174 <cursor_advance+0x44>
mov    %rbx,%rdi
call   1050 <cursor_advance_down@plt>
test   %eax,%eax
jns    1160 <cursor_advance+0x30>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.cursor = type { i32 }
define i32 @cursor_advance(%struct.cursor* %0) {
br label %2
2: ; preds = %5, %1
%3 = tail call i32 @cursor_advance_up(%struct.cursor* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i64 @cursor_level_finished(%struct.cursor* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %2
8: ; preds = %5, %11
%9 = tail call i32 @cursor_advance_down(%struct.cursor* %0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = icmp eq i32 %9, 0
br i1 %12, label %13, label %8
13: ; preds = %2, %11, %8
%14 = phi i32 [ 1, %11 ], [ %9, %8 ], [ 0, %2 ]
ret i32 %14
}