#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 clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int clock();
int /*<<< orphan*/ printf(char *, double);
int main() {
  clock_t clock_start;
  int nrOfElements = 1000 * 1000 * 100;
  int start = 0;
  double acc = 0;
  register int i;
  clock_start = clock();
  for (i = start; i < (nrOfElements); ++i)
    acc += 4.0 * (1 - (i % 2) * 2) / (2 * i + 1);
  printf("%d ms\n", (int)((clock() - clock_start) / (CLOCKS_PER_SEC / 1000)));
  printf("%.8lf\n", acc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5f5e100,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11af <main+0x8f>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
shl    $0x1,%edx
mov    $0x1,%eax
sub    %edx,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe7e(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <main+0x35>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <clock@plt>
mov    %eax,%ebx
xorpd  %xmm4,%xmm4
mov    $0x3,%eax
movsd  0xec1(%rip),%xmm0
movsd  0xec1(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rax),%ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
movapd %xmm0,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm4,%xmm3
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movapd %xmm1,%xmm4
divsd  %xmm2,%xmm4
addsd  %xmm3,%xmm4
add    $0x4,%eax
cmp    $0xbebc203,%eax
jne    1150 <main+0x30>
xor    %eax,%eax
movsd  %xmm4,0x8(%rsp)
call   1030 <clock@plt>
sub    %ebx,%eax
mov    0x2e4f(%rip),%rcx
movslq (%rcx),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe4a(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d ms\0A\00"
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [7 x i8] c"%.8lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store i32 0, i32* %1
store i32 100000000, i32* %3
store i32 0, i32* %4
store double 0.000000e+00, double* %5
%7 = call i32 (...) @clock()
store i32 %7, i32* %2
%8 = load i32, i32* %4
store i32 %8, i32* %6
br label %9
9: ; preds = %27, %0
%10 = load i32, i32* %6
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = load i32, i32* %6
%15 = srem i32 %14, 2
%16 = mul nsw i32 %15, 2
%17 = sub nsw i32 1, %16
%18 = sitofp i32 %17 to double
%19 = fmul double 4.000000e+00, %18
%20 = load i32, i32* %6
%21 = mul nsw i32 2, %20
%22 = add nsw i32 %21, 1
%23 = sitofp i32 %22 to double
%24 = fdiv double %19, %23
%25 = load double, double* %5
%26 = fadd double %25, %24
store double %26, double* %5
br label %27
27: ; preds = %13
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %9
30: ; preds = %9
%31 = call i32 (...) @clock()
%32 = load i32, i32* %2
%33 = sub nsw i32 %31, %32
%34 = load i32, i32* @CLOCKS_PER_SEC
%35 = sdiv i32 %34, 1000
%36 = sdiv i32 %33, %35
%37 = sitofp i32 %36 to double
%38 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %37)
%39 = load double, double* %5
%40 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d ms\0A\00"
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [7 x i8] c"%.8lf\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @clock()
br label %2
2: ; preds = %2, %0
%3 = phi i32 [ 0, %0 ], [ %15, %2 ]
%4 = phi double [ 0.000000e+00, %0 ], [ %14, %2 ]
%5 = shl nuw nsw i32 %3, 1
%6 = or i32 %5, 1
%7 = sitofp i32 %6 to double
%8 = fdiv double 4.000000e+00, %7
%9 = fadd double %4, %8
%10 = shl nuw i32 %3, 1
%11 = or i32 %10, 3
%12 = sitofp i32 %11 to double
%13 = fdiv double -4.000000e+00, %12
%14 = fadd double %9, %13
%15 = add nuw nsw i32 %3, 2
%16 = icmp eq i32 %15, 100000000
br i1 %16, label %17, label %2
17: ; preds = %2
%18 = tail call i32 (...) @clock()
%19 = sub nsw i32 %18, %1
%20 = load i32, i32* @CLOCKS_PER_SEC
%21 = sdiv i32 %20, 1000
%22 = sdiv i32 %19, %21
%23 = sitofp i32 %22 to double
%24 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %23)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %14)
ret i32 0
}