#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 */
double CLOCKS_PER_SEC;
double clock();
unsigned int collatz(unsigned int);
int pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  double start, end;
  unsigned int longest = 0;
  unsigned int terms = 0;
  unsigned int j = 0;
  printf("Algorithm starts, please wait....\n");
  start = clock();
  for (unsigned int i = 1; i < (1 * pow(10, 6)); i++) {
    j = i;
    unsigned int actualTerms = 1;
    while (j != 1) {
      actualTerms++;
      if (actualTerms > terms) {
        terms = actualTerms;
        longest = i;
      }
      j = collatz(j);
    }
  }
  end = clock();
  printf("Algorithm end\n");
  printf("Time: %f\n", (end - start) / CLOCKS_PER_SEC);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    $0xa,%edi
mov    $0x6,%esi
call   1060 <pow@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
shl    $0x0,%ecx
cmp    %ecx,%eax
jae    120c <main+0xcc>
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x1,-0x34(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     11f9 <main+0xb9>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jbe    11e9 <main+0xa9>
mov    -0x34(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <collatz@plt>
mov    %eax,-0x2c(%rbp)
jmp    11be <main+0x7e>
jmp    11fe <main+0xbe>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    118c <main+0x4c>
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    0x2db1(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdf0(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeae(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xa,%edi
mov    $0x6,%esi
call   1070 <pow@plt>
cmp    $0x2,%eax
jb     11be <main+0x6e>
mov    $0x1,%ebx
jmp    11a6 <main+0x56>
nopl   0x0(%rax)
add    $0x1,%ebx
mov    $0xa,%edi
mov    $0x6,%esi
call   1070 <pow@plt>
cmp    %eax,%ebx
jae    11be <main+0x6e>
mov    %ebx,%eax
cmp    $0x1,%ebx
je     1190 <main+0x40>
nopl   (%rax)
mov    %eax,%edi
call   1030 <collatz@plt>
cmp    $0x1,%eax
jne    11b0 <main+0x60>
jmp    1190 <main+0x40>
xor    %eax,%eax
call   1050 <clock@plt>
movsd  %xmm0,(%rsp)
lea    0xe5b(%rip),%rdi
call   1040 <puts@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
mov    0x2e00(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe0d(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Algorithm starts, please wait....\0A\00"
@.str.1 = [15 x i8] c"Algorithm end\0A\00"
@.str.2 = [10 x i8] c"Time: %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%14 = call double (...) @clock()
store double %14, double* %6
store i32 1, i32* %11
br label %15
15: ; preds = %38, %2
%16 = load i32, i32* %11
%17 = call i32 @pow(i32 10, i32 6)
%18 = mul nsw i32 1, %17
%19 = icmp ult i32 %16, %18
br i1 %19, label %20, label %41
20: ; preds = %15
%21 = load i32, i32* %11
store i32 %21, i32* %10
store i32 1, i32* %12
br label %22
22: ; preds = %34, %20
%23 = load i32, i32* %10
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = load i32, i32* %12
%27 = add i32 %26, 1
store i32 %27, i32* %12
%28 = load i32, i32* %12
%29 = load i32, i32* %9
%30 = icmp ugt i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* %12
store i32 %32, i32* %9
%33 = load i32, i32* %11
store i32 %33, i32* %8
br label %34
34: ; preds = %31, %25
%35 = load i32, i32* %10
%36 = call i32 @collatz(i32 %35)
store i32 %36, i32* %10
br label %22
37: ; preds = %22
br label %38
38: ; preds = %37
%39 = load i32, i32* %11
%40 = add i32 %39, 1
store i32 %40, i32* %11
br label %15
41: ; preds = %15
%42 = call double (...) @clock()
store double %42, double* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%44 = load double, double* %7
%45 = load double, double* %6
%46 = fsub double %44, %45
%47 = load double, double* @CLOCKS_PER_SEC
%48 = fdiv double %46, %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %48)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [10 x i8] c"Time: %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@str = [34 x i8] c"Algorithm starts, please wait....\00"
@str.3 = [14 x i8] c"Algorithm end\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%4 = tail call double (...) @clock()
%5 = tail call i32 @pow(i32 10, i32 6)
%6 = icmp ugt i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %2, %21
%8 = phi i32 [ %22, %21 ], [ 1, %2 ]
%9 = icmp eq i32 %8, 1
br i1 %9, label %21, label %17
10: ; preds = %21, %2
%11 = tail call double (...) @clock()
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.3, i64 0, i64 0))
%13 = fsub double %11, %4
%14 = load double, double* @CLOCKS_PER_SEC
%15 = fdiv double %13, %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double %15)
ret i32 0
17: ; preds = %7, %17
%18 = phi i32 [ %19, %17 ], [ %8, %7 ]
%19 = tail call i32 @collatz(i32 %18)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %17
21: ; preds = %17, %7
%22 = add nuw i32 %8, 1
%23 = tail call i32 @pow(i32 10, i32 6)
%24 = icmp ult i32 %22, %23
br i1 %24, label %7, label %10
}