#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 countTerms(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int maxTerms = 0;
  int number;
  int terms = 0;
  int i;
  for (i = 1; i < 1000000; i++) {
    terms = countTerms(i);
    if (terms > maxTerms) {
      maxTerms = terms;
      number = i;
    }
  }
  printf("result: %d\n", number);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jge    1187 <main+0x67>
mov    -0x14(%rbp),%edi
call   1040 <countTerms@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1174 <main+0x54>
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1179 <main+0x59>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <main+0x24>
mov    -0xc(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1040 <countTerms@plt>
cmp    %ebx,%eax
cmovg  %eax,%ebx
cmovg  %ebp,%r14d
add    $0x1,%ebp
cmp    $0xf4240,%ebp
jne    1130 <main+0x10>
lea    0xeae(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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