#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 */
double KahanSummation(int, int);
double addForward(int, int);
double addForwardDouble(int, int);
double addRecursive(int, int);
double addRecursiveDouble(int, int);
double addReverse(int, int);
double addReverseDouble(int, int);
int /*<<< orphan*/ printf(char *, ...);
void summation(int from, int to) {
  int i;
  int j;
  double sum[7];
  if (from < 1)
    from = 1;
  if (to < from)
    to = from + 100;
  printf("\n==========Summation==========\n");
  printf("The sum of the series 1/i, with i running from %d to %d is\n", from,
         to);
  printf("Forward summation with floats:\t\t%2.17g\n",
         sum[0] = addForward(from, to));
  printf("Reverse summation with floats:\t\t%2.17g\n",
         sum[1] = addReverse(from, to));
  printf("Recursive summation with floats:\t%2.17g\n",
         sum[2] = addRecursive(from, to));
  printf("Forward summation with doubles:\t\t%2.17g\n",
         sum[3] = addForwardDouble(from, to));
  printf("Reverse summation with doubles:\t\t%2.17g\n",
         sum[4] = addReverseDouble(from, to));
  printf("Recursive summation with doubles:\t%2.17g\n",
         sum[5] = addRecursiveDouble(from, to));
  printf("Kahan summation with floats:\t\t%2.17g\n",
         sum[6] = KahanSummation(from, to));
  printf("Differences between results in a matrix:\n");
  for (i = 0; i < 7; i++) {
    for (j = 0; j < 7; j++) {
      printf("%12.7g\t", sum[i] - sum[j]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<summation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x1,-0x4(%rbp)
jge    119f <summation+0x1f>
movl   $0x1,-0x4(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b4 <summation+0x34>
mov    -0x4(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x8(%rbp)
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <addForward@plt>
movsd  %xmm0,-0x50(%rbp)
lea    0xe6f(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <addReverse@plt>
movsd  %xmm0,-0x48(%rbp)
lea    0xe79(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <addRecursive@plt>
movsd  %xmm0,-0x40(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10a0 <addForwardDouble@plt>
movsd  %xmm0,-0x38(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <addReverseDouble@plt>
movsd  %xmm0,-0x30(%rbp)
lea    0xe99(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <addRecursiveDouble@plt>
movsd  %xmm0,-0x28(%rbp)
lea    0xea4(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <KahanSummation@plt>
movsd  %xmm0,-0x20(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jge    1324 <summation+0x1a4>
movl   $0x0,-0x10(%rbp)
cmpl   $0x7,-0x10(%rbp)
jge    1308 <summation+0x188>
movslq -0xc(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm0
movslq -0x10(%rbp),%rax
subsd  -0x50(%rbp,%rax,8),%xmm0
lea    0xeae(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12ce <summation+0x14e>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12bd <summation+0x13d>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<summation>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
test   %edi,%edi
mov    $0x1,%eax
cmovle %eax,%ebx
lea    0x64(%rbx),%eax
cmp    %esi,%ebx
cmovg  %eax,%ebp
lea    0xf9c(%rip),%rdi
call   1060 <puts@plt>
lea    0xe31(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <addForward@plt>
movsd  %xmm0,0x8(%rsp)
movsd  %xmm0,0x40(%rsp)
lea    0xe46(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <addReverse@plt>
movsd  %xmm0,0x48(%rsp)
lea    0xe51(%rip),%rdi
movsd  %xmm0,0x38(%rsp)
mov    $0x1,%al
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   10a0 <addRecursive@plt>
movsd  %xmm0,0x50(%rsp)
lea    0xe56(%rip),%rdi
movsd  %xmm0,0x30(%rsp)
mov    $0x1,%al
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   10c0 <addForwardDouble@plt>
movsd  %xmm0,0x58(%rsp)
lea    0xe5c(%rip),%rdi
movsd  %xmm0,0x28(%rsp)
mov    $0x1,%al
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1090 <addReverseDouble@plt>
movsd  %xmm0,0x60(%rsp)
lea    0xe62(%rip),%rdi
movsd  %xmm0,0x20(%rsp)
mov    $0x1,%al
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   10b0 <addRecursiveDouble@plt>
movsd  %xmm0,0x68(%rsp)
lea    0xe68(%rip),%rdi
movsd  %xmm0,0x18(%rsp)
mov    $0x1,%al
call   1080 <printf@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   1070 <KahanSummation@plt>
movsd  %xmm0,0x70(%rsp)
lea    0xe6f(%rip),%rdi
movsd  %xmm0,0x10(%rsp)
mov    $0x1,%al
call   1080 <printf@plt>
lea    0xea8(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%ebp
lea    0xe70(%rip),%rbx
movsd  0x8(%rsp),%xmm0
nopl   (%rax)
movsd  %xmm0,(%rsp)
subsd  0x8(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1080 <printf@plt>
movsd  (%rsp),%xmm0
subsd  0x38(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1080 <printf@plt>
movsd  (%rsp),%xmm0
subsd  0x30(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1080 <printf@plt>
movsd  (%rsp),%xmm0
subsd  0x28(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1080 <printf@plt>
movsd  (%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1080 <printf@plt>
movsd  (%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1080 <printf@plt>
movsd  (%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1080 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmp    $0x7,%rbp
je     13a2 <summation+0x202>
movsd  0x40(%rsp,%rbp,8),%xmm0
add    $0x1,%rbp
jmp    12f0 <summation+0x150>
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"\0A==========Summation==========\0A\00"
@.str.1 = [60 x i8] c"The sum of the series 1/i, with i running from %d to %d is\0A\00"
@.str.2 = [40 x i8] c"Forward summation with floats:\09\09%2.17g\0A\00"
@.str.3 = [40 x i8] c"Reverse summation with floats:\09\09%2.17g\0A\00"
@.str.4 = [41 x i8] c"Recursive summation with floats:\09%2.17g\0A\00"
@.str.5 = [41 x i8] c"Forward summation with doubles:\09\09%2.17g\0A\00"
@.str.6 = [41 x i8] c"Reverse summation with doubles:\09\09%2.17g\0A\00"
@.str.7 = [42 x i8] c"Recursive summation with doubles:\09%2.17g\0A\00"
@.str.8 = [38 x i8] c"Kahan summation with floats:\09\09%2.17g\0A\00"
@.str.9 = [42 x i8] c"Differences between results in a matrix:\0A\00"
@.str.10 = [8 x i8] c"%12.7g\09\00"
@.str.11 = [2 x i8] c"\0A\00"
define void @summation(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [7 x double]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %11
11: ; preds = %10, %2
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 100
store i32 %17, i32* %4
br label %18
18: ; preds = %15, %11
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call double @addForward(i32 %23, i32 %24)
%26 = getelementptr inbounds [7 x double], [7 x double]* %7, i64 0, i64 0
store double %25, double* %26
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), double %25)
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = call double @addReverse(i32 %28, i32 %29)
%31 = getelementptr inbounds [7 x double], [7 x double]* %7, i64 0, i64 1
store double %30, double* %31
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), double %30)
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = call double @addRecursive(i32 %33, i32 %34)
%36 = getelementptr inbounds [7 x double], [7 x double]* %7, i64 0, i64 2
store double %35, double* %36
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), double %35)
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = call double @addForwardDouble(i32 %38, i32 %39)
%41 = getelementptr inbounds [7 x double], [7 x double]* %7, i64 0, i64 3
store double %40, double* %41
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), double %40)
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = call double @addReverseDouble(i32 %43, i32 %44)
%46 = getelementptr inbounds [7 x double], [7 x double]* %7, i64 0, i64 4
store double %45, double* %46
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), double %45)
%48 = load i32, i32* %3
%49 = load i32, i32* %4
%50 = call double @addRecursiveDouble(i32 %48, i32 %49)
%51 = getelementptr inbounds [7 x double], [7 x double]* %7, i64 0, i64 5
store double %50, double* %51
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), double %50)
%53 = load i32, i32* %3
%54 = load i32, i32* %4
%55 = call double @KahanSummation(i32 %53, i32 %54)
%56 = getelementptr inbounds [7 x double], [7 x double]* %7, i64 0, i64 6
store double %55, double* %56
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), double %55)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %5
br label %59
59: ; preds = %82, %18
%60 = load i32, i32* %5
%61 = icmp slt i32 %60, 7
br i1 %61, label %62, label %85
62: ; preds = %59
store i32 0, i32* %6
br label %63
63: ; preds = %77, %62
%64 = load i32, i32* %6
%65 = icmp slt i32 %64, 7
br i1 %65, label %66, label %80
66: ; preds = %63
%67 = load i32, i32* %5
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [7 x double], [7 x double]* %7, i64 0, i64 %68
%70 = load double, double* %69
%71 = load i32, i32* %6
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [7 x double], [7 x double]* %7, i64 0, i64 %72
%74 = load double, double* %73
%75 = fsub double %70, %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), double %75)
br label %77
77: ; preds = %66
%78 = load i32, i32* %6
%79 = add nsw i32 %78, 1
store i32 %79, i32* %6
br label %63
80: ; preds = %63
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %82
82: ; preds = %80
%83 = load i32, i32* %5
%84 = add nsw i32 %83, 1
store i32 %84, i32* %5
br label %59
85: ; preds = %59
ret void
}

LLVM IR (-O2):
@.str.1 = [60 x i8] c"The sum of the series 1/i, with i running from %d to %d is\0A\00"
@.str.2 = [40 x i8] c"Forward summation with floats:\09\09%2.17g\0A\00"
@.str.3 = [40 x i8] c"Reverse summation with floats:\09\09%2.17g\0A\00"
@.str.4 = [41 x i8] c"Recursive summation with floats:\09%2.17g\0A\00"
@.str.5 = [41 x i8] c"Forward summation with doubles:\09\09%2.17g\0A\00"
@.str.6 = [41 x i8] c"Reverse summation with doubles:\09\09%2.17g\0A\00"
@.str.7 = [42 x i8] c"Recursive summation with doubles:\09%2.17g\0A\00"
@.str.8 = [38 x i8] c"Kahan summation with floats:\09\09%2.17g\0A\00"
@.str.10 = [8 x i8] c"%12.7g\09\00"
@str = [31 x i8] c"\0A==========Summation==========\00"
@str.12 = [41 x i8] c"Differences between results in a matrix:\00"
define void @summation(i32 %0, i32 %1) {
%3 = alloca [7 x double]
%4 = bitcast [7 x double]* %3 to i8*
%5 = icmp sgt i32 %0, 1
%6 = select i1 %5, i32 %0, i32 1
%7 = icmp sgt i32 %6, %1
%8 = add nuw nsw i32 %6, 100
%9 = select i1 %7, i32 %8, i32 %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %9)
%12 = tail call double @addForward(i32 %6, i32 %9)
%13 = getelementptr inbounds [7 x double], [7 x double]* %3, i64 0, i64 0
store double %12, double* %13
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), double %12)
%15 = tail call double @addReverse(i32 %6, i32 %9)
%16 = getelementptr inbounds [7 x double], [7 x double]* %3, i64 0, i64 1
store double %15, double* %16
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), double %15)
%18 = tail call double @addRecursive(i32 %6, i32 %9)
%19 = getelementptr inbounds [7 x double], [7 x double]* %3, i64 0, i64 2
store double %18, double* %19
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), double %18)
%21 = tail call double @addForwardDouble(i32 %6, i32 %9)
%22 = getelementptr inbounds [7 x double], [7 x double]* %3, i64 0, i64 3
store double %21, double* %22
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), double %21)
%24 = tail call double @addReverseDouble(i32 %6, i32 %9)
%25 = getelementptr inbounds [7 x double], [7 x double]* %3, i64 0, i64 4
store double %24, double* %25
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), double %24)
%27 = tail call double @addRecursiveDouble(i32 %6, i32 %9)
%28 = getelementptr inbounds [7 x double], [7 x double]* %3, i64 0, i64 5
store double %27, double* %28
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), double %27)
%30 = tail call double @KahanSummation(i32 %6, i32 %9)
%31 = getelementptr inbounds [7 x double], [7 x double]* %3, i64 0, i64 6
store double %30, double* %31
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), double %30)
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.12, i64 0, i64 0))
br label %34
34: ; preds = %54, %2
%35 = phi double [ %12, %2 ], [ %56, %54 ]
%36 = phi i64 [ 0, %2 ], [ %52, %54 ]
%37 = fsub double %35, %12
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), double %37)
%39 = fsub double %35, %15
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), double %39)
%41 = fsub double %35, %18
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), double %41)
%43 = fsub double %35, %21
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), double %43)
%45 = fsub double %35, %24
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), double %45)
%47 = fsub double %35, %27
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), double %47)
%49 = fsub double %35, %30
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), double %49)
%51 = tail call i32 @putchar(i32 10)
%52 = add nuw nsw i64 %36, 1
%53 = icmp eq i64 %52, 7
br i1 %53, label %57, label %54
54: ; preds = %34
%55 = getelementptr inbounds [7 x double], [7 x double]* %3, i64 0, i64 %52
%56 = load double, double* %55
br label %34
57: ; preds = %34
ret void
}