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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int _read_value(int fd) {
  char c;
  if (lseek(fd, 0, SEEK_SET) < 0) {
    perror("lseek");
    exit(0);
  }
  if (read(fd, &c, 1) != 1) {
    perror("read");
    exit(0);
  }
  return c == '0' ? 0 : 1;
}


x86 assembly (clang, -O0):
<_read_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
cmp    $0x0,%rax
jge    117b <_read_value+0x3b>
lea    0xe91(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
je     11a8 <_read_value+0x68>
lea    0xe6a(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>
movsbl -0x5(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x30,%edx
cmove  %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_read_value>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
test   %rax,%rax
js     1182 <_read_value+0x42>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    118b <_read_value+0x4b>
xor    %eax,%eax
cmpb   $0x30,0xf(%rsp)
setne  %al
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe77(%rip),%rdi
jmp    1192 <_read_value+0x52>
lea    0xe74(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [5 x i8] c"read\00"
define i32 @_read_value(i32 %0) {
%2 = alloca i32
%3 = alloca i8
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @SEEK_SET
%6 = call i64 @lseek(i32 %4, i32 0, i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %1
%12 = load i32, i32* %2
%13 = call i32 @read(i32 %12, i8* %3, i32 1)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %11
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 48
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 0, i32 1
ret i32 %23
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [5 x i8] c"read\00"
define i32 @_read_value(i32 %0) {
%2 = alloca i8
%3 = load i32, i32* @SEEK_SET
%4 = tail call i64 @lseek(i32 %0, i32 0, i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %1
%10 = call i32 @read(i32 %0, i8* %2, i32 1)
%11 = icmp eq i32 %10, 1
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %9
%16 = load i8, i8* %2
%17 = icmp ne i8 %16, 48
%18 = zext i1 %17 to i32
ret i32 %18
}