#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__ ConvertReadFloat(int, float *);
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[]) {
  float val;
  int fd;
  fd = open("test.dat", O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "File not found.\n");
    exit(-1);
  }
  while (ConvertReadFloat(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,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11a9 <main+0x59>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11ae <main+0x5e>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1030 <ConvertReadFloat@plt>
cmp    $0x0,%rax
jne    11e9 <main+0x99>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe3d(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
jmp    11ae <main+0x5e>
mov    -0x18(%rbp),%edi
call   1040 <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     11dc <main+0x8c>
mov    %eax,%ebx
lea    0x4(%rsp),%rsi
mov    %eax,%edi
call   1030 <ConvertReadFloat@plt>
test   %rax,%rax
jne    11c7 <main+0x77>
mov    0x2e44(%rip),%r12
lea    0xe87(%rip),%r14
lea    0x4(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <ConvertReadFloat@plt>
test   %rax,%rax
je     11a0 <main+0x50>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
xor    %eax,%eax
call   1050 <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 float
%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 @ConvertReadFloat(i32 %18, float* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* @stdout
%23 = load float, float* %6
%24 = fpext float %23 to double
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %24)
br label %17
26: ; preds = %17
%27 = load i32, i32* %7
%28 = call i32 @close(i32 %27)
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 float
%4 = bitcast float* %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 @ConvertReadFloat(i32 %6, float* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %22
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 float, float* %3
%18 = fpext float %17 to double
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %18)
%20 = call i64 @ConvertReadFloat(i32 %6, float* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %15, label %22
22: ; preds = %15, %8
%23 = call i32 @close(i32 %6)
ret i32 0
}