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

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double, double);
int main(int argc, char *argv[]) {
  clock_t start = clock();
  double sum = 0.0;
  int i;
  for (i = 1; i < 10000000; i++) {
    sum += 1.0 / (double)i;
  }
  printf("sum = %.4f (computed in %.4f seconds)\n", sum,
         (double)(clock() - start) / CLOCKS_PER_SEC);
  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)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x989680,-0x24(%rbp)
jge    1186 <main+0x66>
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  0xe96(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1150 <main+0x30>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  -0x30(%rbp),%xmm0
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm1
mov    0x2e3c(%rip),%rax
divsd  (%rax),%xmm1
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
xorpd  %xmm4,%xmm4
movsd  0xec5(%rip),%xmm0
mov    $0x3,%eax
movsd  0xec0(%rip),%xmm1
movapd %xmm0,%xmm2
nopl   0x0(%rax)
movapd %xmm0,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm4,%xmm3
lea    -0x1(%rax),%ecx
xorps  %xmm4,%xmm4
cvtsi2sd %ecx,%xmm4
movapd %xmm0,%xmm5
divsd  %xmm4,%xmm5
addsd  %xmm3,%xmm5
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
movapd %xmm0,%xmm4
divsd  %xmm3,%xmm4
addsd  %xmm5,%xmm4
addsd  %xmm1,%xmm2
add    $0x3,%eax
cmp    $0x989682,%eax
jne    1150 <main+0x30>
xor    %eax,%eax
movsd  %xmm4,0x8(%rsp)
call   1030 <clock@plt>
sub    %rbx,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mov    0x2e36(%rip),%rax
divsd  (%rax),%xmm1
lea    0xe53(%rip),%rdi
movsd  0x8(%rsp),%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [39 x i8] c"sum = %.4f (computed in %.4f seconds)\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 (...) @clock()
store i64 %9, i64* %6
store double 0.000000e+00, double* %7
store i32 1, i32* %8
br label %10
10: ; preds = %19, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 10000000
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32, i32* %8
%15 = sitofp i32 %14 to double
%16 = fdiv double 1.000000e+00, %15
%17 = load double, double* %7
%18 = fadd double %17, %16
store double %18, double* %7
br label %19
19: ; preds = %13
%20 = load i32, i32* %8
%21 = add nsw i32 %20, 1
store i32 %21, i32* %8
br label %10
22: ; preds = %10
%23 = load double, double* %7
%24 = call i64 (...) @clock()
%25 = load i64, i64* %6
%26 = sub nsw i64 %24, %25
%27 = sitofp i64 %26 to double
%28 = load double, double* @CLOCKS_PER_SEC
%29 = fdiv double %27, %28
%30 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), double %23, double %29)
ret i32 0
}

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