#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 */
scalar_t__ ConvertReadDouble(int, double *);
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  double val;
  int fd;
  fd = open("test.dat", O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "File not found.\n");
    exit(-1);
  }
  while (ConvertReadDouble(fd, &val) == 0) {
    fprintf(stdout, "%g\n", val);
  }
  close(fd);
  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)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11a9 <main+0x59>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11ae <main+0x5e>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <ConvertReadDouble@plt>
cmp    $0x0,%rax
jne    11e5 <main+0x95>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
movsd  -0x18(%rbp),%xmm0
lea    0xe41(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    11ae <main+0x5e>
mov    -0x1c(%rbp),%edi
call   1030 <close@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
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11d7 <main+0x87>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <ConvertReadDouble@plt>
test   %rax,%rax
jne    11c2 <main+0x72>
mov    0x2e46(%rip),%r12
lea    0xe89(%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    %ebx,%edi
mov    %r15,%rsi
call   1050 <ConvertReadDouble@plt>
test   %rax,%rax
je     11a0 <main+0x50>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dfa(%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"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [17 x i8] c"File not found.\0A\00"
@stdout = global i32 0
@.str.2 = [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 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
br label %17
17: ; preds = %21, %16
%18 = load i32, i32* %7
%19 = call i64 @ConvertReadDouble(i32 %18, double* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* @stdout
%23 = load double, double* %6
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %23)
br label %17
25: ; preds = %17
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
ret i32 0
}

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