#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 count_factors(int);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int num = 0;
  int natural = 0;
  while (1) {
    num += ++natural;
    int factors = count_factors(num);
    printf("natural: %d, num: %d, factors: %d\n", natural, num, factors);
    if (factors > 500) {
      printf("answer: %d\n", num);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <count_factors@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1f4,-0x10(%rbp)
jle    1194 <main+0x74>
mov    -0x8(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret
jmp    113d <main+0x1d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebp
lea    0xecd(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
add    %ebp,%ebx
mov    %ebx,%edi
call   1040 <count_factors@plt>
mov    %eax,%r15d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    $0x1f5,%r15d
jl     1140 <main+0x20>
lea    0xeb4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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