#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 num_divisors(int, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int tri_num(int);
int problem12(void) {
  int i, num, found = 0;
  for (i = 1; !found; i++)
    if (num_divisors((num = tri_num(i)), 500 / 2) > 500)
      found = 1;
  printf("The first triangle number to have over %d divisors is %d with %d "
         "divisors\n",
         500, num, num_divisors(num, 500 / 2));
  return 0;
}


x86 assembly (clang, -O0):
<problem12>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x4(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    115c <problem12+0x2c>
jmp    1198 <problem12+0x68>
mov    -0x4(%rbp),%edi
call   1030 <tri_num@plt>
mov    %eax,%edi
mov    %edi,-0x8(%rbp)
mov    $0xfa,%esi
call   1050 <num_divisors@plt>
cmp    $0x1f4,%eax
jle    1185 <problem12+0x55>
movl   $0x1,-0xc(%rbp)
jmp    118a <problem12+0x5a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1146 <problem12+0x16>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0xfa,%esi
call   1050 <num_divisors@plt>
mov    -0x10(%rbp),%edx
mov    %eax,%ecx
lea    0xe49(%rip),%rdi
mov    $0x1f4,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<problem12>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <tri_num@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0xfa,%esi
call   1050 <num_divisors@plt>
add    $0x1,%ebp
cmp    $0x1f5,%eax
jl     1140 <problem12+0x10>
mov    %ebx,%edi
mov    $0xfa,%esi
call   1050 <num_divisors@plt>
lea    0xe8e(%rip),%rdi
mov    $0x1f4,%esi
mov    %ebx,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [75 x i8] c"The first triangle number to have over %d divisors is %d with %d divisors\0A\00"
define i32 @problem12() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
store i32 1, i32* %1
br label %4
4: ; preds = %15, %0
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
%7 = xor i1 %6, true
br i1 %7, label %8, label %18
8: ; preds = %4
%9 = load i32, i32* %1
%10 = call i32 @tri_num(i32 %9)
store i32 %10, i32* %2
%11 = call i32 @num_divisors(i32 %10, i32 250)
%12 = icmp sgt i32 %11, 500
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 1, i32* %3
br label %14
14: ; preds = %13, %8
br label %15
15: ; preds = %14
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %4
18: ; preds = %4
%19 = load i32, i32* %2
%20 = load i32, i32* %2
%21 = call i32 @num_divisors(i32 %20, i32 250)
%22 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 500, i32 %19, i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [75 x i8] c"The first triangle number to have over %d divisors is %d with %d divisors\0A\00"
define i32 @problem12() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 1, %0 ], [ %6, %1 ]
%3 = tail call i32 @tri_num(i32 %2)
%4 = tail call i32 @num_divisors(i32 %3, i32 250)
%5 = icmp slt i32 %4, 501
%6 = add nuw nsw i32 %2, 1
br i1 %5, label %1, label %7
7: ; preds = %1
%8 = tail call i32 @num_divisors(i32 %3, i32 250)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 500, i32 %3, i32 %8)
ret i32 0
}