#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*/ x;
struct stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, double *, int);
int /*<<< orphan*/ stat(char *, struct stat *);
int main(int argc, char **argv) {
  if (argc != 2)
    exit(0);
  struct stat st;
  stat(argv[1], &st);
  int length = st.st_size;
  int fd = open(argv[1], O_RDONLY);
  if (fd <= 0) {
    printf("failed to open\n");
    exit(0);
  }
  double x;
  while (length > 0) {
    x = 0.0;
    read(fd, &x, sizeof(x));
    printf("FLOAT: %.2000lf\n\n", x);
    length -= sizeof(x);
  }
  close(fd);
  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)
cmpl   $0x2,-0x8(%rbp)
je     1187 <main+0x27>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     11d6 <main+0x76>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    11db <main+0x7b>
cmpl   $0x0,-0x1c(%rbp)
jle    1221 <main+0xc1>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1050 <read@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xe06(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movslq -0x1c(%rbp),%rax
sub    $0x8,%rax
mov    %eax,-0x1c(%rbp)
jmp    11db <main+0x7b>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1214 <main+0xa4>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
mov    0x8(%rsp),%ebp
mov    0x8(%rbx),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
jle    121b <main+0xab>
mov    %eax,%ebx
test   %ebp,%ebp
jle    1200 <main+0x90>
add    $0x8,%ebp
lea    0x10(%rsp),%r14
lea    0xe3d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movq   $0x0,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <read@plt>
movsd  0x10(%rsp),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0xfffffff8,%ebp
cmp    $0x8,%ebp
ja     11d0 <main+0x60>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xdf0(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str = [16 x i8] c"failed to open\0A\00"
@.str.1 = [18 x i8] c"FLOAT: %.2000lf\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @stat(i8* %17, %struct.stat* %6)
%19 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%20 = load i32, i32* %19
store i32 %20, i32* %7
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %23, i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp sle i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %14
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %14
br label %32
32: ; preds = %35, %31
%33 = load i32, i32* %7
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %32
store double 0.000000e+00, double* %9
%36 = load i32, i32* %8
%37 = call i32 @read(i32 %36, double* %9, i32 8)
%38 = load double, double* %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %38)
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = sub i64 %41, 8
%43 = trunc i64 %42 to i32
store i32 %43, i32* %7
br label %32
44: ; preds = %32
%45 = load i32, i32* %8
%46 = call i32 @close(i32 %45)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"FLOAT: %.2000lf\0A\0A\00"
@str = [15 x i8] c"failed to open\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca double
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = bitcast %struct.stat* %3 to i8*
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @stat(i8* %11, %struct.stat* %3)
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = load i8*, i8** %10
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* %15, i32 %16)
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %8
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %8
%23 = bitcast double* %4 to i8*
%24 = icmp sgt i32 %14, 0
br i1 %24, label %25, label %32
25: ; preds = %22, %25
%26 = phi i32 [ %30, %25 ], [ %14, %22 ]
store double 0.000000e+00, double* %4
%27 = call i32 @read(i32 %17, double* %4, i32 8)
%28 = load double, double* %4
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %28)
%30 = add nsw i32 %26, -8
%31 = icmp ugt i32 %26, 8
br i1 %31, label %25, label %32
32: ; preds = %25, %22
%33 = tail call i32 @close(i32 %17)
ret i32 0
}