#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ stderr;
void read_float(char path[], float *result) {
  FILE *file = fopen(path, "r");
  if (file == NULL) {
    fprintf(stderr, "Failed to open file: %s", path);
    exit(EXIT_FAILURE);
  }
  if (fscanf(file, "%f", result) < 1) {
    fprintf(stderr, "Failed to scan file: %s", path);
    exit(EXIT_FAILURE);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<read_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a6 <read_float+0x56>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe65(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jge    11ea <read_float+0x9a>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_float>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1192 <read_float+0x42>
mov    %rax,%rbx
lea    0xea4(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1040 <fscanf@plt>
test   %eax,%eax
jle    11a4 <read_float+0x54>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
jmp    11b4 <read_float+0x64>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Failed to open file: %s\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [24 x i8] c"Failed to scan file: %s\00"
define void @read_float(i8* %0, float* %1) {
%3 = alloca i8*
%4 = alloca float*
%5 = alloca i32*
store i8* %0, i8** %3
store float* %1, 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 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32*, i32** %5
%18 = load float*, float** %4
%19 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %18)
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %3
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %16
%28 = load i32*, i32** %5
%29 = call i32 @fclose(i32* %28)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Failed to open file: %s\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [24 x i8] c"Failed to scan file: %s\00"
define void @read_float(i8* %0, float* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %1)
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
%19 = tail call i32 @fclose(i32* %3)
ret void
}