#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 */
typedef int uint64_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int main(int argc, const char *argv[]) {
  uint32_t i;
  uint64_t n;
  uint32_t count;
  uint32_t max = 0;
  uint32_t maxi = 0;
  for (i = 1; i < 1000000; i++) {
    n = (uint64_t)i;
    count = 1;
    while (n != 1) {
      if (n & 1) {
        n = n * 3 + 1;
      } else {
        n /= 2;
      }
      count++;
    }
    if (count > max) {
      max = count;
      maxi = i;
      printf("%d\n", max);
    }
  }
  printf("%d\n", maxi);
  return 0;
}


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,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jge    11d3 <main+0xc3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     1199 <main+0x89>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     117d <main+0x6d>
imul   $0x3,-0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118b <main+0x7b>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <main+0x45>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    11c0 <main+0xb0>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
jmp    11c5 <main+0xb5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <main+0x2b>
mov    -0x24(%rbp),%esi
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%ebx
xor    %esi,%esi
lea    0xede(%rip),%r14
xor    %eax,%eax
jmp    113b <main+0x2b>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    $0xf4240,%ebx
je     1190 <main+0x80>
mov    $0x1,%ebp
cmp    $0x1,%ebx
jne    1160 <main+0x50>
cmp    %eax,%ebp
jle    1130 <main+0x20>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %ebp,%eax
mov    %ebx,%esi
jmp    1130 <main+0x20>
nopl   0x0(%rax)
mov    $0x1,%ebp
mov    %ebx,%ecx
jmp    1183 <main+0x73>
nopl   0x0(%rax)
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
mov    %edx,%ecx
add    $0x1,%ebp
cmp    $0x1,%ecx
je     1145 <main+0x35>
test   $0x1,%cl
je     1170 <main+0x60>
lea    (%rcx,%rcx,2),%ecx
add    $0x1,%ecx
jmp    117b <main+0x6b>
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %10
store i32 1, i32* %6
br label %11
11: ; preds = %43, %2
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 1000000
br i1 %13, label %14, label %46
14: ; preds = %11
%15 = load i32, i32* %6
store i32 %15, i32* %7
store i32 1, i32* %8
br label %16
16: ; preds = %30, %14
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %33
19: ; preds = %16
%20 = load i32, i32* %7
%21 = and i32 %20, 1
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %7
%25 = mul nsw i32 %24, 3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %30
27: ; preds = %19
%28 = load i32, i32* %7
%29 = sdiv i32 %28, 2
store i32 %29, i32* %7
br label %30
30: ; preds = %27, %23
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %16
33: ; preds = %16
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = icmp sgt i32 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32, i32* %8
store i32 %38, i32* %9
%39 = load i32, i32* %6
store i32 %39, i32* %10
%40 = load i32, i32* %9
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %37, %33
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %11
46: ; preds = %11
%47 = load i32, i32* %10
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %47)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %27
%4 = phi i32 [ 0, %2 ], [ %29, %27 ]
%5 = phi i32 [ 0, %2 ], [ %28, %27 ]
%6 = phi i32 [ 1, %2 ], [ %30, %27 ]
%7 = icmp eq i32 %6, 1
br i1 %7, label %22, label %8
8: ; preds = %3, %18
%9 = phi i32 [ %20, %18 ], [ 1, %3 ]
%10 = phi i32 [ %19, %18 ], [ %6, %3 ]
%11 = and i32 %10, 1
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = mul nsw i32 %10, 3
%15 = add nsw i32 %14, 1
br label %18
16: ; preds = %8
%17 = sdiv i32 %10, 2
br label %18
18: ; preds = %16, %13
%19 = phi i32 [ %15, %13 ], [ %17, %16 ]
%20 = add nuw nsw i32 %9, 1
%21 = icmp eq i32 %19, 1
br i1 %21, label %22, label %8
22: ; preds = %18, %3
%23 = phi i32 [ 1, %3 ], [ %20, %18 ]
%24 = icmp sgt i32 %23, %5
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %27
27: ; preds = %22, %25
%28 = phi i32 [ %23, %25 ], [ %5, %22 ]
%29 = phi i32 [ %6, %25 ], [ %4, %22 ]
%30 = add nuw nsw i32 %6, 1
%31 = icmp eq i32 %30, 1000000
br i1 %31, label %32, label %3
32: ; preds = %27
%33 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %29)
ret i32 0
}