#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 argc, char *argv[]) {
  int i = 0;
  double sum1 = 0.0;
  double sum2 = 0.0;
  for (i = 1; i < 1024; i++) {
    sum1 += 1.0 / i;
  }
  printf("%g\n", sum1);
  for (i = 1024; i > 0; i--) {
    sum2 += 1.0 / i;
  }
  printf("%g\n", sum2);
}


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   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jge    117a <main+0x6a>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xea2(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <main+0x34>
movsd  -0x20(%rbp),%xmm0
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
movl   $0x400,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11c5 <main+0xb5>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe57(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1192 <main+0x82>
movsd  -0x28(%rbp),%xmm0
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movsd  0xee7(%rip),%xmm1
xorpd  %xmm0,%xmm0
mov    $0x3,%eax
movsd  0xede(%rip),%xmm2
movapd %xmm1,%xmm3
xchg   %ax,%ax
movapd %xmm1,%xmm4
divsd  %xmm3,%xmm4
addsd  %xmm0,%xmm4
lea    -0x1(%rax),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movapd %xmm1,%xmm5
divsd  %xmm0,%xmm5
addsd  %xmm4,%xmm5
xorps  %xmm4,%xmm4
cvtsi2sd %eax,%xmm4
movapd %xmm1,%xmm0
divsd  %xmm4,%xmm0
addsd  %xmm5,%xmm0
addsd  %xmm2,%xmm3
add    $0x3,%eax
cmp    $0x402,%eax
jne    1130 <main+0x20>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    $0x400,%eax
xorpd  %xmm0,%xmm0
movsd  0xe70(%rip),%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movapd %xmm1,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm0,%xmm3
lea    -0x1(%rax),%ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
movapd %xmm1,%xmm0
divsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
add    $0xfffffffe,%eax
cmp    $0x1,%ecx
jne    1190 <main+0x80>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%g\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %3, %2
%4 = phi double [ 0.000000e+00, %2 ], [ %16, %3 ]
%5 = phi i32 [ 1, %2 ], [ %17, %3 ]
%6 = sitofp i32 %5 to double
%7 = fdiv double 1.000000e+00, %6
%8 = fadd double %4, %7
%9 = add nuw nsw i32 %5, 1
%10 = sitofp i32 %9 to double
%11 = fdiv double 1.000000e+00, %10
%12 = fadd double %8, %11
%13 = add nuw nsw i32 %5, 2
%14 = sitofp i32 %13 to double
%15 = fdiv double 1.000000e+00, %14
%16 = fadd double %12, %15
%17 = add nuw nsw i32 %5, 3
%18 = icmp eq i32 %17, 1024
br i1 %18, label %19, label %3
19: ; preds = %3
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %16)
br label %21
21: ; preds = %21, %19
%22 = phi double [ 0.000000e+00, %19 ], [ %30, %21 ]
%23 = phi i32 [ 1024, %19 ], [ %31, %21 ]
%24 = sitofp i32 %23 to double
%25 = fdiv double 1.000000e+00, %24
%26 = fadd double %22, %25
%27 = add nsw i32 %23, -1
%28 = sitofp i32 %27 to double
%29 = fdiv double 1.000000e+00, %28
%30 = fadd double %26, %29
%31 = add nsw i32 %23, -2
%32 = icmp eq i32 %27, 1
br i1 %32, label %33, label %21
33: ; preds = %21
%34 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %30)
ret i32 0
}