#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 */
unsigned int calc_tnum(unsigned int);
unsigned int factor_count(unsigned int);
int /*<<< orphan*/ printf(char *, int, unsigned int);
int main(int argc, char *argv[]) {
  unsigned num = 0;
  unsigned t_num = 0;
  unsigned fact_count = 0;
  while (true) {
    num++;
    t_num = calc_tnum(num);
    fact_count = factor_count(t_num);
    if (fact_count >= 500)
      break;
  }
  printf("First triangular number with more than %d divisors: %u\n", 500,
         t_num);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <calc_tnum@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <factor_count@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1f4,-0x1c(%rbp)
jb     118c <main+0x5c>
jmp    1191 <main+0x61>
jmp    115b <main+0x2b>
mov    -0x18(%rbp),%edx
lea    0xe65(%rip),%rdi
mov    $0x1f4,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <calc_tnum@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <factor_count@plt>
add    $0x1,%ebx
cmp    $0x1f4,%eax
jb     1140 <main+0x10>
lea    0xe9f(%rip),%rdi
mov    $0x1f4,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"First triangular number with more than %d divisors: %u\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %2, %19
%10 = load i32, i32* %6
%11 = add i32 %10, 1
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = call i32 @calc_tnum(i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = call i32 @factor_count(i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp uge i32 %16, 500
br i1 %17, label %18, label %19
18: ; preds = %9
br label %20
19: ; preds = %9
br label %9
20: ; preds = %18
%21 = load i32, i32* %7
%22 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 500, i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [56 x i8] c"First triangular number with more than %d divisors: %u\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 0, %2 ], [ %5, %3 ]
%5 = add i32 %4, 1
%6 = tail call i32 @calc_tnum(i32 %5)
%7 = tail call i32 @factor_count(i32 %6)
%8 = icmp ugt i32 %7, 499
br i1 %8, label %9, label %3
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 500, i32 %6)
ret i32 0
}