#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 collatz(int);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int i, l_no, l_seq, cur, n, flag = 0;
  l_no = 1;
  l_seq = 1;
  for (i = 1000000 - 1; i > 1; i--) {
    cur = collatz(i);
    if (l_seq < cur) {
      l_seq = cur;
      l_no = i;
    }
  }
  printf("\nLargest collatz sequence gerating no : %d and no in seq %d", l_no,
         l_seq);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0xf423f,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    118b <main+0x6b>
mov    -0x8(%rbp),%edi
call   1030 <collatz@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1178 <main+0x58>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    117d <main+0x5d>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    114b <main+0x2b>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x1,%r14d
mov    $0xf4240,%ebx
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ebx
mov    %ebx,%edi
call   1030 <collatz@plt>
cmp    %eax,%ebp
cmovl  %eax,%ebp
cmovl  %ebx,%r14d
cmp    $0x2,%ebx
ja     1140 <main+0x20>
lea    0xea1(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [60 x i8] c"\0ALargest collatz sequence gerating no : %d and no in seq %d\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 0, i32* %7
store i32 1, i32* %3
store i32 1, i32* %4
store i32 999999, i32* %2
br label %8
8: ; preds = %21, %0
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i32, i32* %2
%13 = call i32 @collatz(i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* %5
store i32 %18, i32* %4
%19 = load i32, i32* %2
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %11
br label %21
21: ; preds = %20
%22 = load i32, i32* %2
%23 = add nsw i32 %22, -1
store i32 %23, i32* %2
br label %8
24: ; preds = %8
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [60 x i8] c"\0ALargest collatz sequence gerating no : %d and no in seq %d\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 999999, %0 ], [ %9, %1 ]
%3 = phi i32 [ 1, %0 ], [ %8, %1 ]
%4 = phi i32 [ 1, %0 ], [ %7, %1 ]
%5 = tail call i32 @collatz(i32 %2)
%6 = icmp slt i32 %4, %5
%7 = select i1 %6, i32 %5, i32 %4
%8 = select i1 %6, i32 %2, i32 %3
%9 = add nsw i32 %2, -1
%10 = icmp ugt i32 %2, 2
br i1 %10, label %1, label %11
11: ; preds = %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %7)
ret i32 0
}