#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *, long);
long recurse(char *, long);
int main(void) {
  long i, r;
  for (i = 0; i < 2000; i++) {
    printf("depth %ld: ", i);
    r = recurse("/proc/self", i);
    if (r > 1)
      r = 1;
    assert(r >= 1);
    printf("r = %ld\n", r);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x7d0,-0x10(%rbp)
jge    11bf <main+0x8f>
mov    -0x10(%rbp),%rsi
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe9c(%rip),%rdi
call   1030 <recurse@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jle    118c <main+0x5c>
movq   $0x1,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1147 <main+0x17>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
lea    0xebc(%rip),%r14
lea    0xec1(%rip),%r15
mov    $0x1,%ebp
lea    0xec0(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <recurse@plt>
mov    %rax,%r13
xor    %edi,%edi
test   %rax,%rax
cmovg  %rbp,%r13
setg   %dil
call   1050 <assert@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x7d0,%rbx
jne    1160 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"depth %ld: \00"
@.str.1 = [11 x i8] c"/proc/self\00"
@.str.2 = [9 x i8] c"r = %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %2
br label %4
4: ; preds = %22, %0
%5 = load i64, i64* %2
%6 = icmp slt i64 %5, 2000
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = load i64, i64* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = load i64, i64* %2
%11 = call i64 @recurse(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %10)
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = icmp sgt i64 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %7
store i64 1, i64* %3
br label %15
15: ; preds = %14, %7
%16 = load i64, i64* %3
%17 = icmp sge i64 %16, 1
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i64, i64* %3
%21 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64 %20)
br label %22
22: ; preds = %15
%23 = load i64, i64* %2
%24 = add nsw i64 %23, 1
store i64 %24, i64* %2
br label %4
25: ; preds = %4
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"depth %ld: \00"
@.str.1 = [11 x i8] c"/proc/self\00"
@.str.2 = [9 x i8] c"r = %ld\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i64 [ 0, %0 ], [ %11, %1 ]
%3 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %2)
%4 = tail call i64 @recurse(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %2)
%5 = icmp slt i64 %4, 1
%6 = select i1 %5, i64 %4, i64 1
%7 = icmp sgt i64 %4, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i64 %6)
%11 = add nuw nsw i64 %2, 1
%12 = icmp eq i64 %11, 2000
br i1 %12, label %13, label %1
13: ; preds = %1
ret i32 0
}