#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read_from_file(char *file_input) {
  FILE *fp;
  fp = fopen(file_input, "r");
  if (fp == NULL) {
    perror("Error: ");
    exit(EXIT_FAILURE);
  }
  char buffer[11];
  if (!fgets(buffer, sizeof(buffer), fp)) {
    printf("nothing to read\n");
    exit(EXIT_FAILURE);
  }
  buffer[10] = '\x00';
  return atoi(buffer);
}


x86 assembly (clang, -O0):
<read_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a5 <read_from_file+0x45>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xb,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    11da <read_from_file+0x7a>
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x1b(%rbp),%rdi
call   1070 <atoi@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_from_file>:
sub    $0x18,%rsp
lea    0xe95(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     119f <read_from_file+0x3f>
lea    0xd(%rsp),%rdi
mov    $0xb,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %eax,%eax
je     11ad <read_from_file+0x4d>
movb   $0x0,0x17(%rsp)
lea    0xd(%rsp),%rdi
call   1070 <atoi@plt>
add    $0x18,%rsp
ret
lea    0xe5c(%rip),%rdi
call   1060 <perror@plt>
jmp    11b9 <read_from_file+0x59>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"Error: \00"
@EXIT_FAILURE = global i32 0
@.str.2 = [17 x i8] c"nothing to read\0A\00"
define i32 @read_from_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [11 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%15 = load i32*, i32** %3
%16 = call i32 @fgets(i8* %14, i32 11, i32* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 10
store i8 0, i8* %23
%24 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%25 = call i32 @atoi(i8* %24)
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"Error: \00"
@EXIT_FAILURE = global i32 0
@str = [16 x i8] c"nothing to read\00"
define i32 @read_from_file(i8* nocapture %0) {
%2 = alloca [11 x i8]
%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 %9
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%11 = call i32 @fgets(i8* %10, i32 11, i32* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %9
%18 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 10
store i8 0, i8* %18
%19 = call i32 @atoi(i8* %10)
ret i32 %19
}