#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 */
struct timeval {
  long long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int numberofDivisors(long long);
int /*<<< orphan*/ printf(char *, long long);
int main(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  long long trianglenumber = 1, i = 2;
  int divcounter = 0;
  while (divcounter < 500) {
    trianglenumber += i;
    i++;
    divcounter = numberofDivisors(trianglenumber);
  }
  printf("%d\n", divcounter);
  printf("%lld", trianglenumber);
  gettimeofday(&stop, NULL);
  printf("\ntook %lu usec\n", stop.tv_usec - start.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movq   $0x1,-0x20(%rbp)
movq   $0x2,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1f4,-0x2c(%rbp)
jge    1199 <main+0x69>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <numberofDivisors@plt>
mov    %eax,-0x2c(%rbp)
jmp    1163 <main+0x33>
movslq -0x2c(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rsi
sub    -0x18(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x1,%r14d
mov    $0x2,%ebx
xchg   %ax,%ax
add    %rbx,%r14
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <numberofDivisors@plt>
cmp    $0x1f4,%eax
jl     1150 <main+0x20>
mov    %eax,%esi
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
lea    0xe89(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x10(%rsp),%rsi
sub    0x8(%rsp),%rsi
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
store i64 1, i64* %4
store i64 2, i64* %5
store i32 0, i32* %6
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 500
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i64, i64* %5
%13 = load i64, i64* %4
%14 = add nsw i64 %13, %12
store i64 %14, i64* %4
%15 = load i64, i64* %5
%16 = add nsw i64 %15, 1
store i64 %16, i64* %5
%17 = load i64, i64* %4
%18 = call i32 @numberofDivisors(i64 %17)
store i32 %18, i32* %6
br label %8
19: ; preds = %8
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %21)
%23 = load i64, i64* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %23)
%25 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%27 = load i64, i64* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%29 = load i64, i64* %28
%30 = sub nsw i64 %27, %29
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 %30)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %6
6: ; preds = %0, %6
%7 = phi i64 [ 2, %0 ], [ %10, %6 ]
%8 = phi i64 [ 1, %0 ], [ %9, %6 ]
%9 = add nuw nsw i64 %7, %8
%10 = add nuw nsw i64 %7, 1
%11 = tail call i32 @numberofDivisors(i64 %9)
%12 = icmp slt i32 %11, 500
br i1 %12, label %6, label %13
13: ; preds = %6
%14 = zext i32 %11 to i64
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %9)
%17 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%21 = load i64, i64* %20
%22 = sub nsw i64 %19, %21
%23 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 %22)
ret i32 0
}