#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 */
int /*<<< orphan*/ printf(char *, double);
int main() {
  int n1 = 100, n2 = 50, n3 = 10;
  double k, s1 = 0, s2 = 0, s3 = 0;
  for (k = 1; k <= n1; k++) {
    s1 = s1 + k;
  }
  for (k = 1; k <= n2; k++) {
    s2 = s2 + k * k;
  }
  for (k = 1; k <= n3; k++) {
    s3 = s3 + 1 / k;
  }
  printf("sum=%15.6f\n", s1 + s2 + s3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
movl   $0x32,-0xc(%rbp)
movl   $0xa,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xeac(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1193 <main+0x83>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe7c(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1159 <main+0x49>
movsd  0xe65(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11e7 <main+0xd7>
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe28(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11a0 <main+0x90>
movsd  0xe11(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     123a <main+0x12a>
movsd  -0x30(%rbp),%xmm0
movsd  0xdeb(%rip),%xmm1
divsd  -0x18(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xdd5(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11f4 <main+0xe4>
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
lea    0xdb8(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movsd  0xee7(%rip),%xmm2
xorpd  %xmm0,%xmm0
mov    $0x5,%eax
movsd  0xede(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
lea    -0x3(%rax),%ecx
xorps  %xmm3,%xmm3
cvtsi2sd %ecx,%xmm3
addsd  %xmm2,%xmm0
lea    -0x2(%rax),%ecx
xorps  %xmm4,%xmm4
cvtsi2sd %ecx,%xmm4
addsd  %xmm0,%xmm3
lea    -0x1(%rax),%ecx
xorps  %xmm5,%xmm5
cvtsi2sd %ecx,%xmm5
addsd  %xmm3,%xmm4
addsd  %xmm4,%xmm5
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm5,%xmm0
addsd  %xmm1,%xmm2
add    $0x5,%eax
cmp    $0x69,%eax
jne    1130 <main+0x20>
movsd  0xe83(%rip),%xmm2
xorpd  %xmm3,%xmm3
mov    $0x5,%eax
cs nopw 0x0(%rax,%rax,1)
movapd %xmm2,%xmm4
mulsd  %xmm2,%xmm4
lea    -0x3(%rax),%ecx
xorps  %xmm5,%xmm5
cvtsi2sd %ecx,%xmm5
addsd  %xmm3,%xmm4
mulsd  %xmm5,%xmm5
addsd  %xmm4,%xmm5
lea    -0x2(%rax),%ecx
xorps  %xmm3,%xmm3
cvtsi2sd %ecx,%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm5,%xmm3
lea    -0x1(%rax),%ecx
xorps  %xmm4,%xmm4
cvtsi2sd %ecx,%xmm4
mulsd  %xmm4,%xmm4
addsd  %xmm3,%xmm4
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
mulsd  %xmm3,%xmm3
addsd  %xmm4,%xmm3
addsd  %xmm1,%xmm2
add    $0x5,%eax
cmp    $0x37,%eax
jne    1190 <main+0x80>
addsd  %xmm3,%xmm0
addsd  0xe17(%rip),%xmm0
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"sum=%15.6f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
store i32 100, i32* %2
store i32 50, i32* %3
store i32 10, i32* %4
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 1.000000e+00, double* %5
br label %9
9: ; preds = %18, %0
%10 = load double, double* %5
%11 = load i32, i32* %2
%12 = sitofp i32 %11 to double
%13 = fcmp ole double %10, %12
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load double, double* %6
%16 = load double, double* %5
%17 = fadd double %15, %16
store double %17, double* %6
br label %18
18: ; preds = %14
%19 = load double, double* %5
%20 = fadd double %19, 1.000000e+00
store double %20, double* %5
br label %9
21: ; preds = %9
store double 1.000000e+00, double* %5
br label %22
22: ; preds = %32, %21
%23 = load double, double* %5
%24 = load i32, i32* %3
%25 = sitofp i32 %24 to double
%26 = fcmp ole double %23, %25
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = load double, double* %7
%29 = load double, double* %5
%30 = load double, double* %5
%31 = call double @llvm.fmuladd.f64(double %29, double %30, double %28)
store double %31, double* %7
br label %32
32: ; preds = %27
%33 = load double, double* %5
%34 = fadd double %33, 1.000000e+00
store double %34, double* %5
br label %22
35: ; preds = %22
store double 1.000000e+00, double* %5
br label %36
36: ; preds = %46, %35
%37 = load double, double* %5
%38 = load i32, i32* %4
%39 = sitofp i32 %38 to double
%40 = fcmp ole double %37, %39
br i1 %40, label %41, label %49
41: ; preds = %36
%42 = load double, double* %8
%43 = load double, double* %5
%44 = fdiv double 1.000000e+00, %43
%45 = fadd double %42, %44
store double %45, double* %8
br label %46
46: ; preds = %41
%47 = load double, double* %5
%48 = fadd double %47, 1.000000e+00
store double %48, double* %5
br label %36
49: ; preds = %36
%50 = load double, double* %6
%51 = load double, double* %7
%52 = fadd double %50, %51
%53 = load double, double* %8
%54 = fadd double %52, %53
%55 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), double %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"sum=%15.6f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi double [ 0.000000e+00, %0 ], [ %17, %1 ]
%3 = phi i32 [ 1, %0 ], [ %18, %1 ]
%4 = sitofp i32 %3 to double
%5 = fadd double %2, %4
%6 = add nuw nsw i32 %3, 1
%7 = sitofp i32 %6 to double
%8 = fadd double %5, %7
%9 = add nuw nsw i32 %3, 2
%10 = sitofp i32 %9 to double
%11 = fadd double %8, %10
%12 = add nuw nsw i32 %3, 3
%13 = sitofp i32 %12 to double
%14 = fadd double %11, %13
%15 = add nuw nsw i32 %3, 4
%16 = sitofp i32 %15 to double
%17 = fadd double %14, %16
%18 = add nuw nsw i32 %3, 5
%19 = icmp eq i32 %18, 101
br i1 %19, label %24, label %1
20: ; preds = %24
%21 = fadd double %17, %40
%22 = fadd double %21, 0x40076E86E86E86E8
%23 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), double %22)
ret i32 0
24: ; preds = %1, %24
%25 = phi double [ %40, %24 ], [ 0.000000e+00, %1 ]
%26 = phi i32 [ %41, %24 ], [ 1, %1 ]
%27 = sitofp i32 %26 to double
%28 = tail call double @llvm.fmuladd.f64(double %27, double %27, double %25)
%29 = add nuw nsw i32 %26, 1
%30 = sitofp i32 %29 to double
%31 = tail call double @llvm.fmuladd.f64(double %30, double %30, double %28)
%32 = add nuw nsw i32 %26, 2
%33 = sitofp i32 %32 to double
%34 = tail call double @llvm.fmuladd.f64(double %33, double %33, double %31)
%35 = add nuw nsw i32 %26, 3
%36 = sitofp i32 %35 to double
%37 = tail call double @llvm.fmuladd.f64(double %36, double %36, double %34)
%38 = add nuw nsw i32 %26, 4
%39 = sitofp i32 %38 to double
%40 = tail call double @llvm.fmuladd.f64(double %39, double %39, double %37)
%41 = add nuw nsw i32 %26, 5
%42 = icmp eq i32 %41, 51
br i1 %42, label %20, label %24
}