#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 atoi(char *);
int /*<<< orphan*/ fill_array(float *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ show_sums(float *, int);
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  printf("Kahan summation algorithm.\n");
  if (argc != 2) {
    fprintf(stderr, "Usage: %s array-size.\n", argv[0]);
    return 1;
  }
  int N = atoi(argv[1]);
  if (N < 1) {
    fprintf(stderr, "Array size must be positive.\n");
    return 1;
  }
  printf("Compile-time options: ");
  printf("none");
  printf(".\n");
  unsigned int seed = 0;
  srand(seed);
  printf("Random number seed = %i.\n", seed);
  float f[N];
  printf("Input: array size = %i.\n", N);
  fill_array(f, N);
  show_sums(f, N);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     11b8 <main+0x58>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a3 <main+0x143>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    11f5 <main+0x95>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a3 <main+0x143>
lea    0xe55(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x31(%rbp)
call   1030 <printf@plt>
mov    -0x31(%rbp),%al
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
mov    -0x31(%rbp),%al
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <srand@plt>
mov    -0x31(%rbp),%al
mov    -0x18(%rbp),%esi
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <fill_array@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <show_sums@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x2,%ebx
jne    1232 <main+0xc2>
mov    0x8(%r14),%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jle    124e <main+0xde>
mov    %eax,%r15d
lea    0xe85(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <srand@plt>
lea    0xe6f(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%r12
mov    %r15d,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe5e(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1080 <fill_array@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <show_sums@plt>
mov    %r12,%rsp
jmp    126b <main+0xfb>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdbb(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1265 <main+0xf5>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Kahan summation algorithm.\0A\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Usage: %s array-size.\0A\00"
@.str.2 = [30 x i8] c"Array size must be positive.\0A\00"
@.str.3 = [23 x i8] c"Compile-time options: \00"
@.str.4 = [5 x i8] c"none\00"
@.str.5 = [3 x i8] c".\0A\00"
@.str.6 = [26 x i8] c"Random number seed = %i.\0A\00"
@.str.7 = [25 x i8] c"Input: array size = %i.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %48
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %48
29: ; preds = %19
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %7
%33 = load i32, i32* %7
%34 = call i32 @srand(i32 %33)
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %6
%38 = zext i32 %37 to i64
%39 = call i8* @llvm.stacksave()
store i8* %39, i8** %8
%40 = alloca float, i64 %38
store i64 %38, i64* %9
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %6
%44 = call i32 @fill_array(float* %40, i32 %43)
%45 = load i32, i32* %6
%46 = call i32 @show_sums(float* %40, i32 %45)
store i32 0, i32* %3
%47 = load i8*, i8** %8
br label %48
48: ; preds = %29, %26, %13
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [23 x i8] c"Usage: %s array-size.\0A\00"
@.str.2 = [30 x i8] c"Array size must be positive.\0A\00"
@.str.3 = [23 x i8] c"Compile-time options: \00"
@.str.4 = [5 x i8] c"none\00"
@.str.6 = [26 x i8] c"Random number seed = %i.\0A\00"
@.str.7 = [25 x i8] c"Input: array size = %i.\0A\00"
@str = [27 x i8] c"Kahan summation algorithm.\00"
@str.8 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %29
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %29
17: ; preds = %9
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.8, i64 0, i64 0))
%21 = tail call i32 @srand(i32 0)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 0)
%23 = zext i32 %12 to i64
%24 = tail call i8* @llvm.stacksave()
%25 = alloca float, i64 %23
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %12)
%27 = call i32 @fill_array(float* %25, i32 %12)
%28 = call i32 @show_sums(float* %25, i32 %12)
br label %29
29: ; preds = %14, %17, %5
%30 = phi i32 [ 1, %5 ], [ 1, %14 ], [ 0, %17 ]
ret i32 %30
}