#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 collatz(int);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int max = 0, i, n = 0, t;
  for (i = 2; i <= 1e6; ++i) {
    t = collatz(i);
    if (max < t) {
      max = t;
      n = i;
    }
  }
  printf("%d, %d\n", n, max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x2,-0xc(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xeaf(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1191 <main+0x71>
mov    -0xc(%rbp),%edi
call   1030 <collatz@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117e <main+0x5e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1183 <main+0x63>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <main+0x24>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x2,%ebp
xor    %ebx,%ebx
xor    %r14d,%r14d
xchg   %ax,%ax
mov    %ebp,%edi
call   1030 <collatz@plt>
cmp    %eax,%ebx
cmovl  %ebp,%r14d
cmovl  %eax,%ebx
add    $0x1,%ebp
cmp    $0xf4241,%ebp
jne    1130 <main+0x10>
lea    0xeae(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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