#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 Z_ERRNO;
scalar_t__ ferror(int /*<<< orphan*/ *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int unzlocal_getByte(FILE *fin, int *pi) {
  unsigned char c;
  int err = fread(&c, 1, 1, fin);
  if (err == 1) {
    *pi = (int)c;
    return (0);
  } else {
    if (ferror(fin))
      return (Z_ERRNO);
    else
      return (0);
  }
}


x86 assembly (clang, -O0):
<unzlocal_getByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1167 <unzlocal_getByte+0x47>
movzbl -0x19(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1192 <unzlocal_getByte+0x72>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     118b <unzlocal_getByte+0x6b>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <unzlocal_getByte+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unzlocal_getByte>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1152 <unzlocal_getByte+0x32>
movzbl 0x7(%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
jmp    116d <unzlocal_getByte+0x4d>
mov    %rbx,%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     116d <unzlocal_getByte+0x4d>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@Z_ERRNO = global i32 0
define i32 @unzlocal_getByte(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %4
%9 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8, i8* %6
%14 = zext i8 %13 to i32
%15 = load i32*, i32** %5
store i32 %14, i32* %15
store i32 0, i32* %3
br label %23
16: ; preds = %2
%17 = load i32*, i32** %4
%18 = call i64 @ferror(i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* @Z_ERRNO
store i32 %21, i32* %3
br label %23
22: ; preds = %16
store i32 0, i32* %3
br label %23
23: ; preds = %22, %20, %12
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@Z_ERRNO = global i32 0
define i32 @unzlocal_getByte(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca i8
%4 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %0)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8, i8* %3
%8 = zext i8 %7 to i32
store i32 %8, i32* %1
br label %14
9: ; preds = %2
%10 = tail call i64 @ferror(i32* %0)
%11 = icmp eq i64 %10, 0
%12 = load i32, i32* @Z_ERRNO
%13 = select i1 %11, i32 0, i32 %12
br label %14
14: ; preds = %9, %6
%15 = phi i32 [ 0, %6 ], [ %13, %9 ]
ret i32 %15
}