#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 EOF;
scalar_t__ IO_ConvertUnsigned(int);
int /*<<< orphan*/ assert(int);
int fgetc(int /*<<< orphan*/ *);
int IO_Read_UBYTE(unsigned char *buffer, FILE *fp) {
  int c;
  assert(buffer && fp);
  if ((c = fgetc(fp)) != EOF) {
    *buffer = (unsigned char)(IO_ConvertUnsigned(c));
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<IO_Read_UBYTE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x1d(%rbp)
je     115b <IO_Read_UBYTE+0x2b>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
je     119f <IO_Read_UBYTE+0x6f>
mov    -0x1c(%rbp),%edi
call   1050 <IO_ConvertUnsigned@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11a6 <IO_Read_UBYTE+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IO_Read_UBYTE>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    0x2e89(%rip),%rdx
xor    %ecx,%ecx
cmp    (%rdx),%eax
je     1174 <IO_Read_UBYTE+0x44>
mov    %eax,%edi
call   1050 <IO_ConvertUnsigned@plt>
mov    %al,(%r14)
mov    $0x1,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @IO_Read_UBYTE(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br label %12
12: ; preds = %9, %2
%13 = phi i1 [ false, %2 ], [ %11, %9 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32*, i32** %5
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %6
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %12
%21 = load i32, i32* %6
%22 = call i64 @IO_ConvertUnsigned(i32 %21)
%23 = trunc i64 %22 to i8
%24 = load i8*, i8** %4
store i8 %23, i8* %24
store i32 1, i32* %3
br label %26
25: ; preds = %12
store i32 0, i32* %3
br label %26
26: ; preds = %25, %20
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @IO_Read_UBYTE(i8* writeonly %0, i32* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i32* %1, null
%5 = and i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @fgetc(i32* %1)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = tail call i64 @IO_ConvertUnsigned(i32 %8)
%13 = trunc i64 %12 to i8
store i8 %13, i8* %0
br label %14
14: ; preds = %2, %11
%15 = phi i32 [ 1, %11 ], [ 0, %2 ]
ret i32 %15
}