#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;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int next_term(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int last = 1000000;
  int max = 0;
  int maxi = 0;
  int i;
  for (i = (last >> 1); i < last; ++i) {
    int counter = 0;
    uint64_t j = i;
    while (j != 1) {
      j = next_term(j);
      counter++;
    }
    counter++;
    if (counter > max) {
      max = counter;
      maxi = i;
    }
  }
  printf("%d\n", maxi);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf4240,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11cd <main+0x9d>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     1199 <main+0x69>
mov    -0x1c(%rbp),%edi
call   1040 <next_term@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1176 <main+0x46>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11ba <main+0x8a>
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11bf <main+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <main+0x2d>
mov    -0x10(%rbp),%esi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
mov    $0x7a120,%ebp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%ebx
mov    %ebp,%eax
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1040 <next_term@plt>
add    $0x1,%ebx
cmp    $0x1,%eax
jne    1160 <main+0x30>
lea    -0x1(%rbx),%eax
cmp    %r15d,%eax
cmovl  %r15d,%ebx
cmovge %ebp,%r14d
add    $0x1,%ebp
mov    %ebx,%r15d
cmp    $0xf4240,%ebp
jne    1150 <main+0x20>
lea    0xe6e(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %11
%2 = phi i32 [ 500000, %0 ], [ %16, %11 ]
%3 = phi i32 [ 0, %0 ], [ %15, %11 ]
%4 = phi i32 [ 0, %0 ], [ %14, %11 ]
br label %5
5: ; preds = %1, %5
%6 = phi i32 [ %2, %1 ], [ %8, %5 ]
%7 = phi i32 [ 0, %1 ], [ %9, %5 ]
%8 = tail call i32 @next_term(i32 %6)
%9 = add nuw nsw i32 %7, 1
%10 = icmp eq i32 %8, 1
br i1 %10, label %11, label %5
11: ; preds = %5
%12 = icmp slt i32 %9, %4
%13 = add nuw nsw i32 %7, 2
%14 = select i1 %12, i32 %4, i32 %13
%15 = select i1 %12, i32 %3, i32 %2
%16 = add nuw nsw i32 %2, 1
%17 = icmp eq i32 %16, 1000000
br i1 %17, label %18, label %1
18: ; preds = %11
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
%20 = tail call i32 @exit(i32 0)
unreachable
}