#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(long);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  long int i;
  int actual;
  int largest = 0;
  int sequence = 0;
  for (i = 2; i < 1000000; i++) {
    actual = collatz(i);
    if (actual > largest) {
      largest = actual;
      sequence = i;
    }
  }
  printf("largest: %d\nsequence: %d\n", largest, sequence);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x2,-0x10(%rbp)
cmpq   $0xf4240,-0x10(%rbp)
jge    118e <main+0x6e>
mov    -0x10(%rbp),%rdi
call   1030 <collatz@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1178 <main+0x58>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x1c(%rbp)
jmp    117d <main+0x5d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1145 <main+0x25>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe65(%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,%ebx
xor    %r14d,%r14d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <collatz@plt>
cmp    %ebp,%eax
cmovg  %eax,%ebp
cmovg  %ebx,%r14d
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    1130 <main+0x10>
lea    0xeab(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [26 x i8] c"largest: %d\0Asequence: %d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %9, %1 ]
%3 = phi i32 [ 0, %0 ], [ %8, %1 ]
%4 = phi i64 [ 2, %0 ], [ %10, %1 ]
%5 = tail call i32 @collatz(i64 %4)
%6 = icmp sgt i32 %5, %3
%7 = trunc i64 %4 to i32
%8 = select i1 %6, i32 %5, i32 %3
%9 = select i1 %6, i32 %7, i32 %2
%10 = add nuw nsw i64 %4, 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 ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
ret i32 0
}