#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__ ConvertFreadDouble(int /*<<< orphan*/ *, double *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  double val;
  FILE *fp;
  fp = fopen("test.dat", "r");
  if (fp == NULL) {
    fprintf(stderr, "File not found.\n");
    exit(-1);
  }
  while (ConvertFreadDouble(fp, &val) == 0) {
    fprintf(stdout, "%g\n", val);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <main+0x59>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11ae <main+0x5e>
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <ConvertFreadDouble@plt>
cmp    $0x0,%rax
jne    11e6 <main+0x96>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
movsd  -0x18(%rbp),%xmm0
lea    0xe42(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    11ae <main+0x5e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d9 <main+0x89>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1050 <ConvertFreadDouble@plt>
test   %rax,%rax
jne    11c3 <main+0x73>
mov    0x2e4e(%rip),%r12
lea    0xe8b(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%edi
movsd  (%rsp),%xmm0
mov    %r14,%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <ConvertFreadDouble@plt>
test   %rax,%rax
je     11a0 <main+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"test.dat\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"File not found.\0A\00"
@stdout = global i32 0
@.str.3 = [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 double
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
br label %16
16: ; preds = %20, %15
%17 = load i32*, i32** %7
%18 = call i64 @ConvertFreadDouble(i32* %17, double* %6)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stdout
%22 = load double, double* %6
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %22)
br label %16
24: ; preds = %16
%25 = load i32*, i32** %7
%26 = call i32 @fclose(i32* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.dat\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"File not found.\0A\00"
@stdout = global i32 0
@.str.3 = [4 x i8] c"%g\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i64 @ConvertFreadDouble(i32* %5, double* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %20
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %7, %14
%15 = load i32, i32* @stdout
%16 = load double, double* %3
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %16)
%18 = call i64 @ConvertFreadDouble(i32* %5, double* %3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %14, label %20
20: ; preds = %14, %7
%21 = call i32 @fclose(i32* %5)
ret i32 0
}