#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);
long seriesLen(long);
int main() {
  long i, largest, maxchain, currchain;
  maxchain = 0;
  for (i = 1000000; i > 0; i--) {
    currchain = seriesLen(i);
    if (currchain > maxchain) {
      largest = i;
      maxchain = currchain;
    }
  }
  printf("%i has produced the longest chain (%i items)\n", largest, maxchain);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0xf4240,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    118b <main+0x6b>
mov    -0x10(%rbp),%rdi
call   1040 <seriesLen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    1175 <main+0x55>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    117a <main+0x5a>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    113f <main+0x1f>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0xf4241,%ebx
xor    %r14d,%r14d
nopl   (%rax)
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rdi
call   1040 <seriesLen@plt>
cmp    %r14,%rax
cmovg  %rbx,%r15
cmovg  %rax,%r14
cmp    $0x1,%rbx
ja     1130 <main+0x10>
lea    0xeac(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [46 x i8] c"%i has produced the longest chain (%i items)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %4
store i64 1000000, i64* %2
br label %6
6: ; preds = %19, %0
%7 = load i64, i64* %2
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load i64, i64* %2
%11 = call i64 @seriesLen(i64 %10)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = load i64, i64* %4
%14 = icmp sgt i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i64, i64* %2
store i64 %16, i64* %3
%17 = load i64, i64* %5
store i64 %17, i64* %4
br label %18
18: ; preds = %15, %9
br label %19
19: ; preds = %18
%20 = load i64, i64* %2
%21 = add nsw i64 %20, -1
store i64 %21, i64* %2
br label %6
22: ; preds = %6
%23 = load i64, i64* %3
%24 = load i64, i64* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i64 %23, i64 %24)
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [46 x i8] c"%i has produced the longest chain (%i items)\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i64 [ 1000000, %0 ], [ %9, %1 ]
%3 = phi i64 [ 0, %0 ], [ %8, %1 ]
%4 = phi i64 [ undef, %0 ], [ %7, %1 ]
%5 = tail call i64 @seriesLen(i64 %2)
%6 = icmp sgt i64 %5, %3
%7 = select i1 %6, i64 %2, i64 %4
%8 = select i1 %6, i64 %5, i64 %3
%9 = add nsw i64 %2, -1
%10 = icmp ugt i64 %2, 1
br i1 %10, label %1, label %11
11: ; preds = %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i64 %7, i64 %8)
ret i32 0
}