#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 */
struct fileaccess {
  int dummy;
};

/* Variables and functions */
int ETXTBSY;
int file_read_int(struct fileaccess *, int *, int /*<<< orphan*/);
int file_read_bool(struct fileaccess *fa, int *value) {
  int val, err;
  err = file_read_int(fa, &val, 0);
  if (err)
    return err;
  if (val < 0)
    return -ETXTBSY;
  *value = !!val;
  return 0;
}


x86 assembly (clang, -O0):
<file_read_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1030 <file_read_int@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1147 <file_read_bool+0x37>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <file_read_bool+0x71>
cmpl   $0x0,-0x1c(%rbp)
jge    1164 <file_read_bool+0x54>
xor    %eax,%eax
mov    0x2e86(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <file_read_bool+0x71>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read_bool>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <file_read_int@plt>
test   %eax,%eax
jne    1146 <file_read_bool+0x36>
cmpl   $0x0,0xc(%rsp)
js     113b <file_read_bool+0x2b>
setne  %al
movzbl %al,%eax
mov    %eax,(%rbx)
xor    %eax,%eax
jmp    1146 <file_read_bool+0x36>
mov    0x2e9e(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.fileaccess = type { i32 }
@ETXTBSY = global i32 0
define i32 @file_read_bool(%struct.fileaccess* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.fileaccess*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store %struct.fileaccess* %0, %struct.fileaccess** %4
store i32* %1, i32** %5
%8 = load %struct.fileaccess*, %struct.fileaccess** %4
%9 = call i32 @file_read_int(%struct.fileaccess* %8, i32* %6, i32 0)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* %7
store i32 %13, i32* %3
br label %27
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @ETXTBSY
%19 = sub nsw i32 0, %18
store i32 %19, i32* %3
br label %27
20: ; preds = %14
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
%24 = xor i1 %23, true
%25 = zext i1 %24 to i32
%26 = load i32*, i32** %5
store i32 %25, i32* %26
store i32 0, i32* %3
br label %27
27: ; preds = %20, %17, %12
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.fileaccess = type { i32 }
@ETXTBSY = global i32 0
define i32 @file_read_bool(%struct.fileaccess* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @file_read_int(%struct.fileaccess* %0, i32* %3, i32 0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @ETXTBSY
%12 = sub nsw i32 0, %11
br label %16
13: ; preds = %7
%14 = icmp ne i32 %8, 0
%15 = zext i1 %14 to i32
store i32 %15, i32* %1
br label %16
16: ; preds = %2, %13, %10
%17 = phi i32 [ %12, %10 ], [ 0, %13 ], [ %5, %2 ]
ret i32 %17
}