#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ perror(char *);
float readFloat(const char *file) {
  float ret = 0;
  FILE *fp;
  if (!(fp = fopen(file, "r"))) {
    perror("fopen");
    return 0;
  }
  if (fscanf(fp, "%f", &ret) != 1) {
    fclose(fp);
    return 0;
  }
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<readFloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    118b <readFloat+0x4b>
lea    0xe89(%rip),%rdi
call   1060 <perror@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11d1 <readFloat+0x91>
mov    -0x20(%rbp),%rdi
lea    0xe72(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11be <readFloat+0x7e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11d1 <readFloat+0x91>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFloat>:
push   %rbp
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1194 <readFloat+0x54>
mov    %rax,%rbx
lea    0xea2(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%ebp
je     1187 <readFloat+0x47>
xorps  %xmm0,%xmm0
jmp    118d <readFloat+0x4d>
movss  0x4(%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
jmp    1182 <readFloat+0x42>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fopen\00"
@.str.2 = [3 x i8] c"%f\00"
define float @readFloat(i8* %0) {
%2 = alloca float
%3 = alloca i8*
%4 = alloca float
%5 = alloca i32*
store i8* %0, i8** %3
store float 0.000000e+00, float* %4
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store float 0.000000e+00, float* %2
br label %22
11: ; preds = %1
%12 = load i32*, i32** %5
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %4)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32*, i32** %5
%17 = call i32 @fclose(i32* %16)
store float 0.000000e+00, float* %2
br label %22
18: ; preds = %11
%19 = load i32*, i32** %5
%20 = call i32 @fclose(i32* %19)
%21 = load float, float* %4
store float %21, float* %2
br label %22
22: ; preds = %18, %15, %9
%23 = load float, float* %2
ret float %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fopen\00"
@.str.2 = [3 x i8] c"%f\00"
define float @readFloat(i8* nocapture %0) {
%2 = alloca float
%3 = bitcast float* %2 to i8*
store float 0.000000e+00, float* %2
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %14
8: ; preds = %1
%9 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %2)
%10 = icmp eq i32 %9, 1
%11 = call i32 @fclose(i32* %4)
%12 = load float, float* %2
%13 = select i1 %10, float %12, float 0.000000e+00
br label %14
14: ; preds = %8, %6
%15 = phi float [ 0.000000e+00, %6 ], [ %13, %8 ]
ret float %15
}