#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*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
double atof(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char const *argv[]) {
  int fd;
  char buffer[1024];
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "OPEN DEVICE FAILED\n");
    exit(0);
  }
  double value = 0.0;
  while (read(fd, buffer, sizeof(buffer)) != 0) {
    value = atof(buffer);
    fprintf(stdout, "%lf\n", value);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11ba <main+0x5a>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x428(%rbp)
ff
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
je     121b <main+0xbb>
lea    -0x420(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x428(%rbp)
ff
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
movsd  -0x428(%rbp),%xmm0
ff
lea    0xe05(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
jmp    11c5 <main+0x65>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11f0 <main+0x90>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
je     11d9 <main+0x79>
mov    %rsp,%rbx
mov    0x2e2c(%rip),%r15
lea    0xe69(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <atof@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"OPEN DEVICE FAILED\0A\00"
@stdout = global i32 0
@.str.1 = [5 x i8] c"%lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %2
store double 0.000000e+00, double* %8
br label %21
21: ; preds = %26, %20
%22 = load i32, i32* %6
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%24 = call i64 @read(i32 %22, i8* %23, i32 1024)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call double @atof(i8* %27)
store double %28, double* %8
%29 = load i32, i32* @stdout
%30 = load double, double* %8
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %30)
br label %21
32: ; preds = %21
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"OPEN DEVICE FAILED\0A\00"
@stdout = global i32 0
@.str.1 = [5 x i8] c"%lf\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = call i64 @read(i32 %8, i8* %4, i32 1024)
%12 = icmp eq i64 %11, 0
br i1 %12, label %23, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %10, %17
%18 = call double @atof(i8* %4)
%19 = load i32, i32* @stdout
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %18)
%21 = call i64 @read(i32 %8, i8* %4, i32 1024)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %17
23: ; preds = %17, %10
%24 = tail call i32 @close(i32 %8)
ret i32 0
}