#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 LOG_DAEMON;
int LOG_ERR;
unsigned char atoi(char *);
int /*<<< orphan*/ errno;
int pread(int, void *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int, char *, int /*<<< orphan*/);
unsigned char stateRead(int state_fd) {
  int fd = state_fd;
  char d[2] = {0, 0};
  if (fd) {
    if (pread(fd, (void *)d, 1, 0) != 1) {
      syslog(LOG_DAEMON | LOG_ERR, "Unable to pread state value: %s",
             strerror(errno));
    }
    return (atoi(d));
  } else
    return (1);
}


x86 assembly (clang, -O0):
<stateRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0xe(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <memset@plt>
cmpl   $0x0,-0xc(%rbp)
je     11dc <stateRead+0x8c>
mov    -0xc(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <pread@plt>
cmp    $0x1,%eax
je     11cb <stateRead+0x7b>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    0x2e21(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%edx
lea    0xe3a(%rip),%rsi
call   1040 <syslog@plt>
lea    -0xe(%rbp),%rdi
call   1050 <atoi@plt>
mov    %al,-0x1(%rbp)
jmp    11e0 <stateRead+0x90>
movb   $0x1,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stateRead>:
push   %rbx
sub    $0x10,%rsp
movw   $0x0,0xe(%rsp)
test   %edi,%edi
je     11a2 <stateRead+0x62>
lea    0xe(%rsp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1050 <pread@plt>
cmp    $0x1,%eax
je     1196 <stateRead+0x56>
mov    0x2e7b(%rip),%rax
mov    0x2e54(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe73(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <syslog@plt>
lea    0xe(%rsp),%rdi
call   1040 <atoi@plt>
jmp    11a4 <stateRead+0x64>
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@LOG_DAEMON = global i32 0
@LOG_ERR = global i32 0
@.str = [32 x i8] c"Unable to pread state value: %s\00"
@errno = global i32 0
define zeroext i8 @stateRead(i32 %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* %3
store i32 %6, i32* %4
%7 = bitcast [2 x i8]* %5 to i8*
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %1
%11 = load i32, i32* %4
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%13 = call i32 @pread(i32 %11, i8* %12, i32 1, i32 0)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* @LOG_DAEMON
%17 = load i32, i32* @LOG_ERR
%18 = or i32 %16, %17
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 @syslog(i32 %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %15, %10
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%24 = call zeroext i8 @atoi(i8* %23)
store i8 %24, i8* %2
br label %26
25: ; preds = %1
store i8 1, i8* %2
br label %26
26: ; preds = %25, %22
%27 = load i8, i8* %2
ret i8 %27
}

LLVM IR (-O2):
@LOG_DAEMON = global i32 0
@LOG_ERR = global i32 0
@.str = [32 x i8] c"Unable to pread state value: %s\00"
@errno = global i32 0
define zeroext i8 @stateRead(i32 %0) {
%2 = alloca i16
%3 = bitcast i16* %2 to i8*
store i16 0, i16* %2
%4 = icmp eq i32 %0, 0
br i1 %4, label %17, label %5
5: ; preds = %1
%6 = call i32 @pread(i32 %0, i8* %3, i32 1, i32 0)
%7 = icmp eq i32 %6, 1
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = load i32, i32* @LOG_DAEMON
%10 = load i32, i32* @LOG_ERR
%11 = or i32 %10, %9
%12 = load i32, i32* @errno
%13 = tail call i32 @strerror(i32 %12)
%14 = tail call i32 @syslog(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %8, %5
%16 = call zeroext i8 @atoi(i8* %3)
br label %17
17: ; preds = %1, %15
%18 = phi i8 [ %16, %15 ], [ 1, %1 ]
ret i8 %18
}