#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 += (i % 2 == 0 ? 4.0 : -4.0) / (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    $0x40,%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    11c7 <main+0xa7>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movsd  0xe8c(%rip),%xmm0
movsd  0xe8c(%rip),%xmm1
movsd  %xmm1,-0x30(%rbp)
cmp    $0x0,%edx
movsd  %xmm0,-0x28(%rbp)
je     1199 <main+0x79>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%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,-0x34(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
lea    0xe18(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%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 = %26, %0
%10 = load i32, i32* %6
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = load i32, i32* %6
%15 = srem i32 %14, 2
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, double 4.000000e+00, double -4.000000e+00
%19 = load i32, i32* %6
%20 = mul nsw i32 2, %19
%21 = add nsw i32 %20, 1
%22 = sitofp i32 %21 to double
%23 = fdiv double %18, %22
%24 = load double, double* %5
%25 = fadd double %24, %23
store double %25, double* %5
br label %26
26: ; preds = %13
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %9
29: ; preds = %9
%30 = call i32 (...) @clock()
%31 = load i32, i32* %2
%32 = sub nsw i32 %30, %31
%33 = load i32, i32* @CLOCKS_PER_SEC
%34 = sdiv i32 %33, 1000
%35 = sdiv i32 %32, %34
%36 = sitofp i32 %35 to double
%37 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %36)
%38 = load double, double* %5
%39 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %38)
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
}