#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int fscanf(int /*<<< orphan*/ *, char const *, void *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
bool read_board(const char *src, const char *spec, void *dst) {
  FILE *fp = fopen(src, "r");
  if (!fp) {
    fprintf(stderr, "Failed to open %s due to '%s' error\n", src,
            strerror(errno));
    return false;
  }
  if (fscanf(fp, spec, dst) != 1) {
    fclose(fp);
    fprintf(stderr, "Failed to read %s due to '%s' error\n", src,
            strerror(errno));
    return false;
  }
  fclose(fp);
  return true;
}


x86 assembly (clang, -O0):
<read_board>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c7 <read_board+0x77>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123e <read_board+0xee>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     122e <read_board+0xde>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xe0a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123e <read_board+0xee>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_board>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a0 <read_board+0x50>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
cmp    $0x1,%ebp
je     11d0 <read_board+0x80>
lea    0xe89(%rip),%r14
jmp    11a7 <read_board+0x57>
lea    0xe5b(%rip),%r14
mov    0x2e32(%rip),%rax
mov    (%rax),%ebx
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"Failed to open %s due to '%s' error\0A\00"
@errno = global i32 0
@.str.2 = [37 x i8] c"Failed to read %s due to '%s' error\0A\00"
define i32 @read_board(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %19, label %13
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %5
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %17)
store i32 0, i32* %4
br label %36
19: ; preds = %3
%20 = load i32*, i32** %8
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = call i32 @fscanf(i32* %20, i8* %21, i8* %22)
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %33
25: ; preds = %19
%26 = load i32*, i32** %8
%27 = call i32 @fclose(i32* %26)
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %5
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %31)
store i32 0, i32* %4
br label %36
33: ; preds = %19
%34 = load i32*, i32** %8
%35 = call i32 @fclose(i32* %34)
store i32 1, i32* %4
br label %36
36: ; preds = %33, %25, %13
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"Failed to open %s due to '%s' error\0A\00"
@errno = global i32 0
@.str.2 = [37 x i8] c"Failed to read %s due to '%s' error\0A\00"
define i32 @read_board(i8* %0, i8* nocapture %1, i8* %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 %10, label %6
6: ; preds = %3
%7 = tail call i32 @fscanf(i32* %4, i8* %1, i8* %2)
%8 = icmp eq i32 %7, 1
%9 = tail call i32 @fclose(i32* %4)
br i1 %8, label %16, label %10
10: ; preds = %6, %3
%11 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), %6 ]
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @fprintf(i32 %12, i8* %11, i8* %0, i8* %14)
br label %16
16: ; preds = %10, %6
%17 = phi i32 [ 1, %6 ], [ 0, %10 ]
ret i32 %17
}