#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*/ tosError_setContext(int /*<<< orphan*/, int /*<<< orphan*/);
int tosFile_read1(int, char *, int /*<<< orphan*/, int);
int tosFile_readChar(int fd) {
  char buf[1];
  int result = tosFile_read1(fd, buf, 0, 1);
  if (result <= 0) {
    if (result == 0)
      tosError_setContext(0, 0);
    ;
    return -1;
  }
  return (int)(unsigned char)buf[0];
}


x86 assembly (clang, -O0):
<tosFile_readChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <tosFile_read1@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     116a <tosFile_readChar+0x4a>
cmpl   $0x0,-0x10(%rbp)
jne    115e <tosFile_readChar+0x3e>
xor    %esi,%esi
mov    %esi,%edi
call   1030 <tosError_setContext@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1171 <tosFile_readChar+0x51>
movzbl -0x9(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tosFile_readChar>:
push   %rbx
sub    $0x10,%rsp
lea    0xf(%rsp),%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <tosFile_read1@plt>
test   %eax,%eax
jle    1141 <tosFile_readChar+0x21>
movzbl 0xf(%rsp),%ebx
jmp    1151 <tosFile_readChar+0x31>
mov    $0xffffffff,%ebx
jne    1151 <tosFile_readChar+0x31>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <tosError_setContext@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @tosFile_readChar(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%8 = call i32 @tosFile_read1(i32 %6, i8* %7, i32 0, i32 1)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @tosError_setContext(i32 0, i32 0)
br label %16
16: ; preds = %14, %11
store i32 -1, i32* %2
br label %21
17: ; preds = %1
%18 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
store i32 %20, i32* %2
br label %21
21: ; preds = %17, %16
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
define i32 @tosFile_readChar(i32 %0) {
%2 = alloca [1 x i8]
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%4 = call i32 @tosFile_read1(i32 %0, i8* %3, i32 0, i32 1)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = icmp eq i32 %4, 0
br i1 %7, label %8, label %13
8: ; preds = %6
%9 = call i32 @tosError_setContext(i32 0, i32 0)
br label %13
10: ; preds = %1
%11 = load i8, i8* %3
%12 = zext i8 %11 to i32
br label %13
13: ; preds = %6, %8, %10
%14 = phi i32 [ %12, %10 ], [ -1, %8 ], [ -1, %6 ]
ret i32 %14
}