#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 */
unsigned int CollatzSequenceCount(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int);
int main() {
  unsigned int longest_sequence = 0, tmp_sequence = 0, num = 0, i = 0;
  const unsigned int LIMIT = 1000000;
  for (i = 1; i < LIMIT; i++) {
    tmp_sequence = CollatzSequenceCount(i);
    if (tmp_sequence > longest_sequence) {
      longest_sequence = tmp_sequence;
      num = i;
    }
  }
  printf("%d", num);
  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,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xf4240,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jae    119c <main+0x7c>
mov    -0x14(%rbp),%edi
call   1040 <CollatzSequenceCount@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jbe    1189 <main+0x69>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    118e <main+0x6e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <main+0x39>
mov    -0x10(%rbp),%esi
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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