#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 chain(int, long);
int /*<<< orphan*/ printf(char *, long);
int main() {
  long num, max = 0, maxchain = 0;
  for (num = 1; num < 1000000; num++) {
    int i = chain(1, num);
    if (i > maxchain) {
      maxchain = i;
      max = num;
    }
  }
  printf("%ld\n", max);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x1,-0x10(%rbp)
cmpq   $0xf4240,-0x10(%rbp)
jge    119a <main+0x7a>
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
call   1040 <chain@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    1184 <main+0x64>
movslq -0x24(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1189 <main+0x69>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1147 <main+0x27>
mov    -0x18(%rbp),%rsi
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x1,%ebx
xor    %r15d,%r15d
xor    %r14d,%r14d
mov    $0x1,%edi
mov    %rbx,%rsi
call   1040 <chain@plt>
cltq
cmp    %rax,%r15
cmovl  %rbx,%r14
cmovl  %rax,%r15
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    1130 <main+0x10>
lea    0xea2(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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