#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 /*<<< orphan*/ free(int *);
int numDivisors(int, int *, int);
int /*<<< orphan*/ printf(char *, int);
int sieve(int, int **);
int main(int argc, char *argv[]) {
  int number = 0, i = 1;
  int sizeOfPrimes = 1000, sizeOfPrimesSqr = 1000000;
  int *primes;
  int numPrimes = sieve(sizeOfPrimes, &primes);
  while (numDivisors(number, primes, numPrimes) < 500) {
    if (sizeOfPrimesSqr < number) {
      sizeOfPrimes *= 5;
      sizeOfPrimesSqr = sizeOfPrimes * sizeOfPrimes;
      numPrimes = sieve(sizeOfPrimes, &primes);
    }
    number += i++;
  }
  printf("Triangle number: %d\n", number);
  free(primes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x3e8,-0x1c(%rbp)
movl   $0xf4240,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <sieve@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <numDivisors@plt>
cmp    $0x1f4,%eax
jge    11dd <main+0x9d>
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c7 <main+0x87>
imul   $0x5,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <sieve@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <main+0x41>
mov    -0x14(%rbp),%esi
lea    0xe19(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x3e8,%r12d
mov    %rsp,%rsi
mov    $0x3e8,%edi
call   1060 <sieve@plt>
mov    %eax,%r14d
mov    (%rsp),%rsi
xor    %ebp,%ebp
xor    %edi,%edi
mov    %eax,%edx
call   1040 <numDivisors@plt>
cmp    $0x1f3,%eax
jg     11ce <main+0x8e>
xor    %ebp,%ebp
mov    $0x1,%ebx
mov    $0xf4240,%r13d
jmp    11ae <main+0x6e>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rbx),%r15d
add    %ebx,%ebp
mov    (%rsp),%rsi
mov    %ebp,%edi
mov    %r14d,%edx
call   1040 <numDivisors@plt>
mov    %r15d,%ebx
cmp    $0x1f4,%eax
jge    11ce <main+0x8e>
cmp    %ebp,%r13d
jge    1190 <main+0x50>
lea    (%r12,%r12,4),%r12d
mov    %r12d,%r13d
imul   %r12d,%r13d
mov    %r12d,%edi
mov    %rsp,%rsi
call   1060 <sieve@plt>
mov    %eax,%r14d
jmp    1190 <main+0x50>
lea    0xe2b(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Triangle number: %d\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
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %7
store i32 1000, i32* %8
store i32 1000000, i32* %9
%12 = load i32, i32* %8
%13 = call i32 @sieve(i32 %12, i32** %10)
store i32 %13, i32* %11
br label %14
14: ; preds = %32, %2
%15 = load i32, i32* %6
%16 = load i32*, i32** %10
%17 = load i32, i32* %11
%18 = call i32 @numDivisors(i32 %15, i32* %16, i32 %17)
%19 = icmp slt i32 %18, 500
br i1 %19, label %20, label %37
20: ; preds = %14
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i32, i32* %8
%26 = mul nsw i32 %25, 5
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = load i32, i32* %8
%29 = mul nsw i32 %27, %28
store i32 %29, i32* %9
%30 = load i32, i32* %8
%31 = call i32 @sieve(i32 %30, i32** %10)
store i32 %31, i32* %11
br label %32
32: ; preds = %24, %20
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
%35 = load i32, i32* %6
%36 = add nsw i32 %35, %33
store i32 %36, i32* %6
br label %14
37: ; preds = %14
%38 = load i32, i32* %6
%39 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32*, i32** %10
%41 = call i32 @free(i32* %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"Triangle number: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = call i32 @sieve(i32 1000, i32** %3)
%6 = load i32*, i32** %3
%7 = call i32 @numDivisors(i32 0, i32* %6, i32 %5)
%8 = icmp slt i32 %7, 500
br i1 %8, label %9, label %29
9: ; preds = %2, %20
%10 = phi i32 [ %23, %20 ], [ %5, %2 ]
%11 = phi i32 [ %22, %20 ], [ 1000000, %2 ]
%12 = phi i32 [ %21, %20 ], [ 1000, %2 ]
%13 = phi i32 [ %24, %20 ], [ 1, %2 ]
%14 = phi i32 [ %25, %20 ], [ 0, %2 ]
%15 = icmp slt i32 %11, %14
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = mul nsw i32 %12, 5
%18 = mul nsw i32 %17, %17
%19 = call i32 @sieve(i32 %17, i32** %3)
br label %20
20: ; preds = %16, %9
%21 = phi i32 [ %17, %16 ], [ %12, %9 ]
%22 = phi i32 [ %18, %16 ], [ %11, %9 ]
%23 = phi i32 [ %19, %16 ], [ %10, %9 ]
%24 = add nuw nsw i32 %13, 1
%25 = add nuw nsw i32 %13, %14
%26 = load i32*, i32** %3
%27 = call i32 @numDivisors(i32 %25, i32* %26, i32 %23)
%28 = icmp slt i32 %27, 500
br i1 %28, label %9, label %29
29: ; preds = %20, %2
%30 = phi i32 [ 0, %2 ], [ %25, %20 ]
%31 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i32*, i32** %3
%33 = call i32 @free(i32* %32)
ret i32 0
}