#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 EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, unsigned long);
int main() {
  unsigned int max_terms = 0;
  unsigned long max_number = 1;
  for (unsigned long n = 1; n < 1000000; n++) {
    unsigned short terms = 1;
    for (unsigned long long m = n; m != 1;) {
      if (m % 2) {
        m = 3 * m + 1;
      } else {
        m /= 2;
      }
      terms++;
    }
    if (terms > max_terms) {
      max_terms = terms;
      max_number = n;
    }
  }
  printf("%lu\n", max_number);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
cmpq   $0xf4240,-0x18(%rbp)
jae    11d0 <main+0xc0>
movw   $0x1,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x28(%rbp)
je     119e <main+0x8e>
mov    -0x28(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1181 <main+0x71>
imul   $0x3,-0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    118d <main+0x7d>
mov    -0x28(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1a(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
jmp    1152 <main+0x42>
movzwl -0x1a(%rbp),%eax
cmp    -0x8(%rbp),%eax
jbe    11ba <main+0xaa>
movzwl -0x1a(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11bf <main+0xaf>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1136 <main+0x26>
mov    -0x10(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
xor    %r8d,%r8d
mov    $0x1,%ecx
mov    $0x1,%esi
jmp    113b <main+0x2b>
nop
movzwl %dx,%edx
cmp    %edx,%r8d
cmovb  %edx,%r8d
cmovb  %rcx,%rsi
add    $0x1,%rcx
cmp    $0xf4240,%rcx
je     116e <main+0x5e>
mov    $0x1,%dx
cmp    $0x1,%rcx
je     1120 <main+0x10>
mov    $0x1,%dx
mov    %rcx,%rdi
nopl   0x0(%rax)
mov    %rdi,%rax
shr    %rax
test   $0x1,%dil
lea    0x1(%rdi,%rdi,2),%rdi
cmove  %rax,%rdi
add    $0x1,%edx
cmp    $0x1,%rdi
jne    1150 <main+0x40>
jmp    1120 <main+0x10>
push   %rax
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lu\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i16
%6 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
store i64 1, i64* %3
store i64 1, i64* %4
br label %7
7: ; preds = %39, %0
%8 = load i64, i64* %4
%9 = icmp ult i64 %8, 1000000
br i1 %9, label %10, label %42
10: ; preds = %7
store i16 1, i16* %5
%11 = load i64, i64* %4
store i64 %11, i64* %6
br label %12
12: ; preds = %26, %10
%13 = load i64, i64* %6
%14 = icmp ne i64 %13, 1
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i64, i64* %6
%17 = urem i64 %16, 2
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i64, i64* %6
%21 = mul i64 3, %20
%22 = add i64 %21, 1
store i64 %22, i64* %6
br label %26
23: ; preds = %15
%24 = load i64, i64* %6
%25 = udiv i64 %24, 2
store i64 %25, i64* %6
br label %26
26: ; preds = %23, %19
%27 = load i16, i16* %5
%28 = add i16 %27, 1
store i16 %28, i16* %5
br label %12
29: ; preds = %12
%30 = load i16, i16* %5
%31 = zext i16 %30 to i32
%32 = load i32, i32* %2
%33 = icmp ugt i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i16, i16* %5
%36 = zext i16 %35 to i32
store i32 %36, i32* %2
%37 = load i64, i64* %4
store i64 %37, i64* %3
br label %38
38: ; preds = %34, %29
br label %39
39: ; preds = %38
%40 = load i64, i64* %4
%41 = add i64 %40, 1
store i64 %41, i64* %4
br label %7
42: ; preds = %7
%43 = load i64, i64* %3
%44 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %43)
%45 = load i32, i32* @EXIT_SUCCESS
ret i32 %45
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lu\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
br label %1
1: ; preds = %0, %9
%2 = phi i64 [ 1, %0 ], [ %15, %9 ]
%3 = phi i64 [ 1, %0 ], [ %14, %9 ]
%4 = phi i32 [ 0, %0 ], [ %13, %9 ]
%5 = icmp eq i64 %2, 1
br i1 %5, label %9, label %17
6: ; preds = %9
%7 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %14)
%8 = load i32, i32* @EXIT_SUCCESS
ret i32 %8
9: ; preds = %17, %1
%10 = phi i16 [ 1, %1 ], [ %26, %17 ]
%11 = zext i16 %10 to i32
%12 = icmp ult i32 %4, %11
%13 = select i1 %12, i32 %11, i32 %4
%14 = select i1 %12, i64 %2, i64 %3
%15 = add nuw nsw i64 %2, 1
%16 = icmp eq i64 %15, 1000000
br i1 %16, label %6, label %1
17: ; preds = %1, %17
%18 = phi i64 [ %25, %17 ], [ %2, %1 ]
%19 = phi i16 [ %26, %17 ], [ 1, %1 ]
%20 = and i64 %18, 1
%21 = icmp eq i64 %20, 0
%22 = mul i64 %18, 3
%23 = add i64 %22, 1
%24 = lshr i64 %18, 1
%25 = select i1 %21, i64 %24, i64 %23
%26 = add i16 %19, 1
%27 = icmp eq i64 %25, 1
br i1 %27, label %9, label %17
}