#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*/ printf(char *, float);
long double sqrt(long long);
float timeit();
int main(int argc, char *argv[]) {
  float start = timeit();
  int base = 1001;
  int divisors = 2;
  long long tri_num = 0;
  long double root;
  for (int i = 1; i <= base; i++)
    tri_num += i;
  while (divisors <= 500) {
    root = sqrt(tri_num);
    for (int i = 2; i <= root + 1; i++) {
      if (tri_num % i == 0)
        divisors += 2;
    }
    if (divisors <= 500) {
      tri_num += (++base);
      divisors = 2;
    }
  }
  float stop = timeit();
  printf("Answer: %lld\n", tri_num);
  printf("Time: %f\n", stop - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <timeit@plt>
movss  %xmm0,-0x14(%rbp)
movl   $0x3e9,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1195 <main+0x65>
movslq -0x44(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    116f <main+0x3f>
jmp    119a <main+0x6a>
cmpl   $0x1f4,-0x1c(%rbp)
jg     1238 <main+0x108>
mov    -0x28(%rbp),%rdi
call   1050 <sqrt@plt>
fstpt  -0x40(%rbp)
movl   $0x2,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x50(%rbp)
fildl  -0x50(%rbp)
fldt   -0x40(%rbp)
fld1
faddp  %st,%st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     120c <main+0xdc>
jmp    11d9 <main+0xa9>
mov    -0x28(%rbp),%rax
movslq -0x48(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11f9 <main+0xc9>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fe <main+0xce>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11ba <main+0x8a>
cmpl   $0x1f4,-0x1c(%rbp)
jg     1233 <main+0x103>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cltq
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x1c(%rbp)
jmp    119a <main+0x6a>
mov    $0x0,%al
call   1040 <timeit@plt>
movss  %xmm0,-0x4c(%rbp)
cvtsi2ssq -0x28(%rbp),%xmm0
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
movss  -0x4c(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
lea    0xda7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1040 <timeit@plt>
movss  %xmm0,(%rsp)
mov    $0x7a6fd,%r15d
mov    $0x3e9,%r14d
fld1
fstpt  0x8(%rsp)
flds   0xea3(%rip)
fstpt  0x14(%rsp)
jmp    117d <main+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
fstp   %st(0)
add    %r14,%r15
add    $0x1,%r15
add    $0x1,%r14
mov    $0x2,%ebx
fldz
jmp    119c <main+0x6c>
cs nopw 0x0(%rax,%rax,1)
fstp   %st(0)
cmp    $0x1f5,%ebx
fldz
jl     1170 <main+0x40>
fstp   %st(0)
cmp    $0x1f4,%ebx
ja     120a <main+0xda>
mov    %r15,%rdi
call   1050 <sqrt@plt>
fldt   0x8(%rsp)
faddp  %st,%st(1)
mov    $0x2,%ecx
fldt   0x14(%rsp)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jae    11f5 <main+0xc5>
jmp    1170 <main+0x40>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rax
xor    %edx,%edx
div    %rcx
lea    0x2(%rbx),%eax
test   %rdx,%rdx
cmove  %eax,%ebx
add    $0x1,%rcx
mov    %ecx,0x4(%rsp)
fildl  0x4(%rsp)
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jb     1190 <main+0x60>
mov    %r15,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    11d0 <main+0xa0>
mov    %r15d,%eax
xor    %edx,%edx
div    %ecx
jmp    11d8 <main+0xa8>
xor    %eax,%eax
call   1040 <timeit@plt>
movss  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %r15,%xmm0
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
movss  0x8(%rsp),%xmm0
subss  (%rsp),%xmm0
lea    0xdd5(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Answer: %lld\0A\00"
@.str.1 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca x86_fp80
%11 = alloca i32
%12 = alloca i32
%13 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call float (...) @timeit()
store float %14, float* %6
store i32 1001, i32* %7
store i32 2, i32* %8
store i64 0, i64* %9
store i32 1, i32* %11
br label %15
15: ; preds = %24, %2
%16 = load i32, i32* %11
%17 = load i32, i32* %7
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = load i64, i64* %9
%23 = add nsw i64 %22, %21
store i64 %23, i64* %9
br label %24
24: ; preds = %19
%25 = load i32, i32* %11
%26 = add nsw i32 %25, 1
store i32 %26, i32* %11
br label %15
27: ; preds = %15
br label %28
28: ; preds = %62, %27
%29 = load i32, i32* %8
%30 = icmp sle i32 %29, 500
br i1 %30, label %31, label %63
31: ; preds = %28
%32 = load i64, i64* %9
%33 = call x86_fp80 @sqrt(i64 %32)
store x86_fp80 %33, x86_fp80* %10
store i32 2, i32* %12
br label %34
34: ; preds = %50, %31
%35 = load i32, i32* %12
%36 = sitofp i32 %35 to x86_fp80
%37 = load x86_fp80, x86_fp80* %10
%38 = fadd x86_fp80 %37, 0xK3FFF8000000000000000
%39 = fcmp ole x86_fp80 %36, %38
br i1 %39, label %40, label %53
40: ; preds = %34
%41 = load i64, i64* %9
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = srem i64 %41, %43
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 2
store i32 %48, i32* %8
br label %49
49: ; preds = %46, %40
br label %50
50: ; preds = %49
%51 = load i32, i32* %12
%52 = add nsw i32 %51, 1
store i32 %52, i32* %12
br label %34
53: ; preds = %34
%54 = load i32, i32* %8
%55 = icmp sle i32 %54, 500
br i1 %55, label %56, label %62
56: ; preds = %53
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
%59 = sext i32 %58 to i64
%60 = load i64, i64* %9
%61 = add nsw i64 %60, %59
store i64 %61, i64* %9
store i32 2, i32* %8
br label %62
62: ; preds = %56, %53
br label %28
63: ; preds = %28
%64 = call float (...) @timeit()
store float %64, float* %13
%65 = load i64, i64* %9
%66 = sitofp i64 %65 to float
%67 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float %66)
%68 = load float, float* %13
%69 = load float, float* %6
%70 = fsub float %68, %69
%71 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), float %70)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Answer: %lld\0A\00"
@.str.1 = [10 x i8] c"Time: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call float (...) @timeit()
br label %7
4: ; preds = %13, %17
%5 = add nuw i64 %8, 1
%6 = add nuw nsw i64 %9, %5
br label %7
7: ; preds = %2, %4
%8 = phi i64 [ 1001, %2 ], [ %5, %4 ]
%9 = phi i64 [ 501501, %2 ], [ %6, %4 ]
br label %10
10: ; preds = %7, %17
%11 = phi i32 [ %25, %17 ], [ 2, %7 ]
%12 = icmp ult i32 %11, 501
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = tail call x86_fp80 @sqrt(i64 %9)
%15 = fadd x86_fp80 %14, 0xK3FFF8000000000000000
%16 = fcmp ult x86_fp80 %15, 0xK40008000000000000000
br i1 %16, label %4, label %19
17: ; preds = %19
%18 = icmp slt i32 %25, 501
br i1 %18, label %4, label %10
19: ; preds = %13, %19
%20 = phi i64 [ %26, %19 ], [ 2, %13 ]
%21 = phi i32 [ %25, %19 ], [ %11, %13 ]
%22 = urem i64 %9, %20
%23 = icmp eq i64 %22, 0
%24 = add nsw i32 %21, 2
%25 = select i1 %23, i32 %24, i32 %21
%26 = add nuw i64 %20, 1
%27 = trunc i64 %26 to i32
%28 = sitofp i32 %27 to x86_fp80
%29 = fcmp ult x86_fp80 %15, %28
br i1 %29, label %17, label %19
30: ; preds = %10
%31 = tail call float (...) @timeit()
%32 = sitofp i64 %9 to float
%33 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float %32)
%34 = fsub float %31, %3
%35 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), float %34)
ret i32 0
}