#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 */
double CLOCKS_PER_SEC;
double clock();
int divisible(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int);
int main(int argc, char *argv[]) {
  double start, end;
  unsigned int i = 1, summatory = 0;
  start = clock();
  do {
    summatory += i++;
    if (divisible(summatory) > 500)
      break;
  } while (true);
  end = clock();
  printf("Algorithm end, Time: %f\n", (end - start) / CLOCKS_PER_SEC);
  printf("%d\n", summatory);
  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   $0x1,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <divisible@plt>
cmp    $0x1f4,%eax
jle    1189 <main+0x59>
jmp    119d <main+0x6d>
jmp    118e <main+0x5e>
mov    $0x1,%al
test   $0x1,%al
jne    1160 <main+0x30>
jmp    119d <main+0x6d>
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
mov    0x2e2a(%rip),%rax
movsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%esi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,(%rsp)
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
add    %ebp,%ebx
add    $0x1,%ebp
mov    %ebx,%edi
call   1050 <divisible@plt>
cmp    $0x1f5,%eax
jl     1150 <main+0x20>
xor    %eax,%eax
call   1030 <clock@plt>
subsd  (%rsp),%xmm0
mov    0x2e72(%rip),%rax
divsd  (%rax),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe87(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Algorithm end, Time: %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
store i32 0, i32* %9
%10 = call double (...) @clock()
store double %10, double* %6
br label %11
11: ; preds = %21, %2
%12 = load i32, i32* %8
%13 = add i32 %12, 1
store i32 %13, i32* %8
%14 = load i32, i32* %9
%15 = add i32 %14, %12
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = call i32 @divisible(i32 %16)
%18 = icmp sgt i32 %17, 500
br i1 %18, label %19, label %20
19: ; preds = %11
br label %22
20: ; preds = %11
br label %21
21: ; preds = %20
br i1 true, label %11, label %22
22: ; preds = %21, %19
%23 = call double (...) @clock()
store double %23, double* %7
%24 = load double, double* %7
%25 = load double, double* %6
%26 = fsub double %24, %25
%27 = load double, double* @CLOCKS_PER_SEC
%28 = fdiv double %26, %27
%29 = fptoui double %28 to i32
%30 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %9
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Algorithm end, Time: %f\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double (...) @clock()
br label %4
4: ; preds = %4, %2
%5 = phi i32 [ 1, %2 ], [ %7, %4 ]
%6 = phi i32 [ 0, %2 ], [ %8, %4 ]
%7 = add i32 %5, 1
%8 = add i32 %6, %5
%9 = tail call i32 @divisible(i32 %8)
%10 = icmp sgt i32 %9, 500
br i1 %10, label %11, label %4
11: ; preds = %4
%12 = tail call double (...) @clock()
%13 = fsub double %12, %3
%14 = load double, double* @CLOCKS_PER_SEC
%15 = fdiv double %13, %14
%16 = fptoui double %15 to i32
%17 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
ret i32 0
}