#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int count_divisors_of_triangular_num(int /*<<< orphan*/);
int /*<<< orphan*/ gmp_printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_triangular(int /*<<< orphan*/, int /*<<< orphan*/);
int Problem012(void) {
  mpz_t test_triangle_no, n;
  int divisor_count;
  mpz_init(test_triangle_no);
  mpz_init_set_ui(n, 1);
  while (1) {
    mpz_triangular(test_triangle_no, n);
    divisor_count = count_divisors_of_triangular_num(n);
    if (divisor_count >= 500) {
      gmp_printf("%30Zd", test_triangle_no);
      break;
    }
    mpz_add_ui(n, n, 1);
  }
  mpz_clear(test_triangle_no);
  mpz_clear(n);
  return 0;
}


x86 assembly (clang, -O0):
<Problem012>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    -0x4(%rbp),%edi
call   1050 <mpz_init@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1060 <mpz_init_set_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <mpz_triangular@plt>
mov    -0x8(%rbp),%edi
call   1030 <count_divisors_of_triangular_num@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1f4,-0xc(%rbp)
jl     11c4 <Problem012+0x54>
mov    -0x4(%rbp),%esi
lea    0xe46(%rip),%rdi
call   1090 <gmp_printf@plt>
jmp    11d9 <Problem012+0x69>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
jmp    118d <Problem012+0x1d>
mov    -0x4(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x8(%rbp),%edi
call   1080 <mpz_clear@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Problem012>:
push   %rax
call   1050 <mpz_init@plt>
mov    $0x1,%esi
call   1060 <mpz_init_set_ui@plt>
call   1070 <mpz_triangular@plt>
call   1030 <count_divisors_of_triangular_num@plt>
cmp    $0x1f3,%eax
jg     119d <Problem012+0x2d>
mov    $0x1,%edx
call   1040 <mpz_add_ui@plt>
jmp    1180 <Problem012+0x10>
lea    0xe5c(%rip),%rdi
call   1090 <gmp_printf@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%30Zd\00"
define i32 @Problem012() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* %1
%5 = call i32 @mpz_init(i32 %4)
%6 = load i32, i32* %2
%7 = call i32 @mpz_init_set_ui(i32 %6, i32 1)
br label %8
8: ; preds = %0, %19
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = call i32 @mpz_triangular(i32 %9, i32 %10)
%12 = load i32, i32* %2
%13 = call i32 @count_divisors_of_triangular_num(i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 500
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i32, i32* %1
%18 = call i32 @gmp_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %23
19: ; preds = %8
%20 = load i32, i32* %2
%21 = load i32, i32* %2
%22 = call i32 @mpz_add_ui(i32 %20, i32 %21, i32 1)
br label %8
23: ; preds = %16
%24 = load i32, i32* %1
%25 = call i32 @mpz_clear(i32 %24)
%26 = load i32, i32* %2
%27 = call i32 @mpz_clear(i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%30Zd\00"
define i32 @Problem012() {
%1 = tail call i32 @mpz_init(i32 undef)
%2 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%3 = tail call i32 @mpz_triangular(i32 undef, i32 undef)
%4 = tail call i32 @count_divisors_of_triangular_num(i32 undef)
%5 = icmp sgt i32 %4, 499
br i1 %5, label %6, label %10
6: ; preds = %10, %0
%7 = tail call i32 @gmp_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 undef)
%8 = tail call i32 @mpz_clear(i32 undef)
%9 = tail call i32 @mpz_clear(i32 undef)
ret i32 0
10: ; preds = %0, %10
%11 = tail call i32 @mpz_add_ui(i32 undef, i32 undef, i32 1)
%12 = tail call i32 @mpz_triangular(i32 undef, i32 undef)
%13 = tail call i32 @count_divisors_of_triangular_num(i32 undef)
%14 = icmp sgt i32 %13, 499
br i1 %14, label %6, label %10
}