#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(float *, int, int, int /*<<< orphan*/ *);
int fwrite(float const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fp;
  const float PI = 3.1415;
  float num;
  if ((fp = fopen("foo.bin", "wb")) == NULL) {
    fprintf(stderr, "Could not open file %s.\n", "foo.bin");
    exit(-1);
  }
  if (fwrite(&PI, sizeof(float), 1, fp) != 1)
    printf("Erro na escrita do arquivo");
  fclose(fp);
  if ((fp = fopen("foo.bin", "rb")) == NULL) {
    fprintf(stderr, "Could not open file %s.", "foo.bin");
    exit(-1);
  }
  if (fread(&num, sizeof(float), 1, fp) != 1) {
    fprintf(stderr, "Could not read file %s.\n", "foo.bin");
    exit(-2);
  }
  printf("\nPI value is: %f", num);
  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)
movss  0xe72(%rip),%xmm0
movss  %xmm0,-0x1c(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11da <main+0x6a>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
lea    0xe39(%rip),%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
cmp    $0x1,%eax
je     1208 <main+0x98>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdec(%rip),%rdi
lea    0xe24(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1258 <main+0xe8>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
lea    0xdbb(%rip),%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     129e <main+0x12e>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
lea    0xd75(%rip),%rdx
call   1060 <fprintf@plt>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc9(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x40490e56,0xc(%rsp)
40
lea    0xe7c(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     122d <main+0xbd>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
cmp    $0x1,%eax
je     11c6 <main+0x56>
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe2b(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     123f <main+0xcf>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1265 <main+0xf5>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe5d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
jmp    124f <main+0xdf>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
lea    0xdaa(%rip),%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
lea    0xd84(%rip),%rdx
call   1060 <fprintf@plt>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"foo.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Could not open file %s.\0A\00"
@.str.3 = [27 x i8] c"Erro na escrita do arquivo\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [24 x i8] c"Could not open file %s.\00"
@.str.6 = [25 x i8] c"Could not read file %s.\0A\00"
@.str.7 = [17 x i8] c"\0API value is: %f\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca float
%8 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store float 0x400921CAC0000000, float* %7
%9 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = call i32 @fwrite(float* %7, i32 4, i32 1, i32* %16)
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
%24 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %21
%31 = load i32*, i32** %6
%32 = call i32 @fread(float* %8, i32 4, i32 1, i32* %31)
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 -2)
unreachable
38: ; preds = %30
%39 = load float, float* %8
%40 = fpext float %39 to double
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), double %40)
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"foo.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Could not open file %s.\0A\00"
@.str.3 = [27 x i8] c"Erro na escrita do arquivo\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [24 x i8] c"Could not open file %s.\00"
@.str.6 = [25 x i8] c"Could not read file %s.\0A\00"
@.str.7 = [17 x i8] c"\0API value is: %f\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca float
%4 = alloca float
%5 = bitcast float* %3 to i8*
store float 0x400921CAC0000000, float* %3
%6 = bitcast float* %4 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = call i32 @fwrite(float* %3, i32 4, i32 1, i32* %7)
%15 = icmp eq i32 %14, 1
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = tail call i32 @fclose(i32* %7)
%20 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 -1)
unreachable
26: ; preds = %18
%27 = call i32 @fread(float* %4, i32 4, i32 1, i32* %20)
%28 = icmp eq i32 %27, 1
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%32 = tail call i32 @exit(i32 -2)
unreachable
33: ; preds = %26
%34 = load float, float* %4
%35 = fpext float %34 to double
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), double %35)
%37 = tail call i32 @fclose(i32* %20)
ret i32 0
}