#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                         char const *);
int /*<<< orphan*/ read_file(char const *, char *, int);
int strtol(char *, char **, int /*<<< orphan*/);
int read_int_from_file(const char *path, char ending_char) {
  char buf[32], *end;
  int value;
  read_file(path, buf, sizeof(buf));
  value = strtol(buf, &end, 0);
  if (*end && *end != ending_char)
    error(EXIT_FAILURE, 0, "%s: Invalid file content", path);
  return value;
}


x86 assembly (clang, -O0):
<read_int_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1040 <read_file@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a4 <read_int_from_file+0x74>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     11a4 <read_int_from_file+0x74>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rcx
xor    %esi,%esi
lea    0xe61(%rip),%rdx
call   1050 <error@plt>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int_from_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
mov    $0x20,%edx
call   1040 <read_file@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rax
mov    (%rax),%al
test   %al,%al
je     118b <read_int_from_file+0x5b>
cmp    %r14b,%al
je     118b <read_int_from_file+0x5b>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rdx
xor    %esi,%esi
mov    %rbx,%rcx
call   1050 <error@plt>
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [25 x i8] c"%s: Invalid file content\00"
define i32 @read_int_from_file(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [32 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
%8 = load i8*, i8** %3
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%10 = call i32 @read_file(i8* %8, i8* %9, i32 32)
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%12 = call i32 @strtol(i8* %11, i8** %6, i32 0)
store i32 %12, i32* %7
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %2
%18 = load i8*, i8** %6
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i32, i32* @EXIT_FAILURE
%26 = load i8*, i8** %3
%27 = call i32 @error(i32 %25, i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %24, %17, %2
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [25 x i8] c"%s: Invalid file content\00"
define i32 @read_int_from_file(i8* %0, i8 signext %1) {
%3 = alloca [32 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = call i32 @read_file(i8* %0, i8* %5, i32 32)
%8 = call i32 @strtol(i8* %5, i8** %4, i32 0)
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
%12 = icmp eq i8 %10, %1
%13 = or i1 %11, %12
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @error(i32 %15, i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
17: ; preds = %14, %2
ret i32 %8
}