#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 collatzLength(int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char **argv) {
  int n = 0;
  int maxL = 0;
  for (int i = 100000; i < 1000000; i++) {
    int curL = 0;
    if (collatzLength(i) > maxL) {
      printf("num: %3i length:%3i\n", i, collatzLength(i));
      maxL = collatzLength(i);
      n = i;
    }
  }
  printf("longest: %i\n", n);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x186a0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    11b5 <main+0x95>
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <collatzLength@plt>
cmp    -0x18(%rbp),%eax
jle    11a2 <main+0x82>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <collatzLength@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1040 <collatzLength@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11a7 <main+0x87>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <main+0x2b>
mov    -0x14(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x186a0,%ebx
lea    0xecd(%rip),%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    114b <main+0x2b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    $0xf4240,%ebx
je     1179 <main+0x59>
mov    %ebx,%edi
call   1040 <collatzLength@plt>
cmp    %ebp,%eax
jle    1140 <main+0x20>
mov    %ebx,%edi
call   1040 <collatzLength@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <collatzLength@plt>
mov    %eax,%ebp
mov    %ebx,%r15d
jmp    1140 <main+0x20>
lea    0xe95(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"num: %3i length:%3i\0A\00"
@.str.1 = [13 x i8] c"longest: %i\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %5
3: ; preds = %15
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %17)
ret i32 0
5: ; preds = %2, %15
%6 = phi i32 [ 0, %2 ], [ %17, %15 ]
%7 = phi i32 [ 100000, %2 ], [ %18, %15 ]
%8 = phi i32 [ 0, %2 ], [ %16, %15 ]
%9 = tail call i32 @collatzLength(i32 %7)
%10 = icmp sgt i32 %9, %8
br i1 %10, label %11, label %15
11: ; preds = %5
%12 = tail call i32 @collatzLength(i32 %7)
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %12)
%14 = tail call i32 @collatzLength(i32 %7)
br label %15
15: ; preds = %11, %5
%16 = phi i32 [ %14, %11 ], [ %8, %5 ]
%17 = phi i32 [ %7, %11 ], [ %6, %5 ]
%18 = add nuw nsw i32 %7, 1
%19 = icmp eq i32 %18, 1000000
br i1 %19, label %3, label %5
}