#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  double s = 0, d;
  FILE *fp;
  char *infile = "../../src/rn100";
  if (argc > 1)
    infile = argv[1];
  fp = fopen(infile, "r");
  if (fp == NULL) {
    fprintf(stderr, "can't open %s\n", infile);
    exit(1);
  }
  while (fscanf(fp, "%lf", &d) != EOF)
    s += d;
  printf("%f\n", s);
  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)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xe8b(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    118f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d1 <main+0x81>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11d6 <main+0x86>
mov    -0x28(%rbp),%rdi
lea    0xe40(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%rax
je     120e <main+0xbe>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11d6 <main+0x86>
movsd  -0x18(%rbp),%xmm0
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     1166 <main+0x16>
mov    0x8(%rsi),%r14
jmp    116d <main+0x1d>
lea    0xe93(%rip),%r14
lea    0xe9c(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1200 <main+0xb0>
mov    %rax,%rbx
lea    0xe96(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0x2e49(%rip),%r12
xorpd  %xmm0,%xmm0
cmp    (%r12),%rax
je     11e6 <main+0x96>
xorpd  %xmm0,%xmm0
lea    0xe6d(%rip),%r14
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <fscanf@plt>
movsd  0x10(%rsp),%xmm0
cmp    (%r12),%rax
jne    11c0 <main+0x70>
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"../../src/rn100\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"can't open %s\0A\00"
@.str.3 = [4 x i8] c"%lf\00"
@EOF = global i64 0
@.str.4 = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca i32*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %6
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %9
br label %16
16: ; preds = %12, %2
%17 = load i8*, i8** %9
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %8
%19 = load i32*, i32** %8
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %9
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %16
br label %27
27: ; preds = %32, %26
%28 = load i32*, i32** %8
%29 = call i64 @fscanf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %7)
%30 = load i64, i64* @EOF
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load double, double* %7
%34 = load double, double* %6
%35 = fadd double %34, %33
store double %35, double* %6
br label %27
36: ; preds = %27
%37 = load double, double* %6
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"../../src/rn100\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"can't open %s\0A\00"
@.str.3 = [4 x i8] c"%lf\00"
@EOF = global i64 0
@.str.4 = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
br label %9
9: ; preds = %6, %2
%10 = phi i8* [ %8, %6 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %3)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %28, label %21
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %13, %21
%22 = phi double [ %24, %21 ], [ 0.000000e+00, %13 ]
%23 = load double, double* %3
%24 = fadd double %22, %23
%25 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %3)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %21
28: ; preds = %21, %13
%29 = phi double [ 0.000000e+00, %13 ], [ %24, %21 ]
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %29)
ret i32 0
}