#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 /*<<< orphan*/ printf(char *, long long, int);
long long ruleOne(long long);
long long ruleTwo(long long);
int main() {
  int chain, longestChain = 0;
  long long i, currentNumber, afterRule, longestNumber = 0;
  int target = 1000000;
  for (currentNumber = 1; currentNumber < target; currentNumber++) {
    afterRule = currentNumber;
    chain = 0;
    while (afterRule > 1) {
      if (afterRule % 2 == 0) {
        afterRule = ruleOne(afterRule);
        chain++;
      } else if (afterRule % 2 == 1) {
        afterRule = ruleTwo(afterRule);
        chain++;
      }
    }
    if (chain > longestChain) {
      longestChain = chain;
      longestNumber = currentNumber;
    }
  }
  printf("The starting number with the longest chain is %lld.\nThe longest "
         "chain is %d",
         longestNumber, longestChain);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0xf4240,-0x34(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
cmp    %rcx,%rax
jge    1223 <main+0xf3>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x8(%rbp)
cmpq   $0x1,-0x28(%rbp)
jle    11f3 <main+0xc3>
mov    -0x28(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11bb <main+0x8b>
mov    -0x28(%rbp),%rdi
call   1050 <ruleOne@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ee <main+0xbe>
mov    -0x28(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x1,%rdx
jne    11e9 <main+0xb9>
mov    -0x28(%rbp),%rdi
call   1030 <ruleTwo@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ee <main+0xbe>
jmp    117d <main+0x4d>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    120d <main+0xdd>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1212 <main+0xe2>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <main+0x2d>
mov    -0x30(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xdcf(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
mov    $0x1,%ebx
xor    %r15d,%r15d
jmp    1168 <main+0x38>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %r15d,%ebp
cmovg  %ebp,%r15d
cmovg  %rbx,%r14
add    $0x1,%rbx
cmp    $0xf4240,%rbx
je     119c <main+0x6c>
mov    $0x0,%ebp
cmp    $0x2,%rbx
jb     1150 <main+0x20>
xor    %ebp,%ebp
mov    %rbx,%rax
jmp    118e <main+0x5e>
nopw   0x0(%rax,%rax,1)
call   1030 <ruleTwo@plt>
add    $0x1,%ebp
cmp    $0x1,%rax
jle    1150 <main+0x20>
mov    %rax,%rdi
test   $0x1,%al
jne    1180 <main+0x50>
call   1050 <ruleOne@plt>
jmp    1185 <main+0x55>
lea    0xe5d(%rip),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [76 x i8] c"The starting number with the longest chain is %lld.\0AThe longest chain is %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i64 0, i64* %7
store i32 1000000, i32* %8
store i64 1, i64* %5
br label %9
9: ; preds = %47, %0
%10 = load i64, i64* %5
%11 = load i32, i32* %8
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %10, %12
br i1 %13, label %14, label %50
14: ; preds = %9
%15 = load i64, i64* %5
store i64 %15, i64* %6
store i32 0, i32* %2
br label %16
16: ; preds = %38, %14
%17 = load i64, i64* %6
%18 = icmp sgt i64 %17, 1
br i1 %18, label %19, label %39
19: ; preds = %16
%20 = load i64, i64* %6
%21 = srem i64 %20, 2
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i64, i64* %6
%25 = call i64 @ruleOne(i64 %24)
store i64 %25, i64* %6
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %38
28: ; preds = %19
%29 = load i64, i64* %6
%30 = srem i64 %29, 2
%31 = icmp eq i64 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i64, i64* %6
%34 = call i64 @ruleTwo(i64 %33)
store i64 %34, i64* %6
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %37
37: ; preds = %32, %28
br label %38
38: ; preds = %37, %23
br label %16
39: ; preds = %16
%40 = load i32, i32* %2
%41 = load i32, i32* %3
%42 = icmp sgt i32 %40, %41
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* %2
store i32 %44, i32* %3
%45 = load i64, i64* %5
store i64 %45, i64* %7
br label %46
46: ; preds = %43, %39
br label %47
47: ; preds = %46
%48 = load i64, i64* %5
%49 = add nsw i64 %48, 1
store i64 %49, i64* %5
br label %9
50: ; preds = %9
%51 = load i64, i64* %7
%52 = load i32, i32* %3
%53 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i64 %51, i32 %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [76 x i8] c"The starting number with the longest chain is %lld.\0AThe longest chain is %d\00"
define i32 @main() {
br label %1
1: ; preds = %0, %19
%2 = phi i64 [ 0, %0 ], [ %23, %19 ]
%3 = phi i64 [ 1, %0 ], [ %24, %19 ]
%4 = phi i32 [ 0, %0 ], [ %22, %19 ]
%5 = icmp ugt i64 %3, 1
br i1 %5, label %6, label %19
6: ; preds = %1, %15
%7 = phi i32 [ %17, %15 ], [ 0, %1 ]
%8 = phi i64 [ %16, %15 ], [ %3, %1 ]
%9 = and i64 %8, 1
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i64 @ruleOne(i64 %8)
br label %15
13: ; preds = %6
%14 = tail call i64 @ruleTwo(i64 %8)
br label %15
15: ; preds = %13, %11
%16 = phi i64 [ %12, %11 ], [ %14, %13 ]
%17 = add nuw nsw i32 %7, 1
%18 = icmp sgt i64 %16, 1
br i1 %18, label %6, label %19
19: ; preds = %15, %1
%20 = phi i32 [ 0, %1 ], [ %17, %15 ]
%21 = icmp sgt i32 %20, %4
%22 = select i1 %21, i32 %20, i32 %4
%23 = select i1 %21, i64 %3, i64 %2
%24 = add nuw nsw i64 %3, 1
%25 = icmp eq i64 %24, 1000000
br i1 %25, label %26, label %1
26: ; preds = %19
%27 = tail call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i64 %23, i32 %22)
ret i32 0
}