#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int gethndl(int hndl) {
  int len;
  char buf[8];
  len = read(hndl, buf, 1);
  if (!len)
    return (EOF);
  if (len != 1) {
    fprintf(stderr,
            "gethndl: read error "
            "handle=%d\n",
            hndl);
    exit(1);
  }
  return (buf[0]);
}


x86 assembly (clang, -O0):
<gethndl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116a <gethndl+0x3a>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    119d <gethndl+0x6d>
cmpl   $0x1,-0xc(%rbp)
je     1196 <gethndl+0x66>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movsbl -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethndl>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     115a <gethndl+0x2a>
test   %eax,%eax
jne    1165 <gethndl+0x35>
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
jmp    115f <gethndl+0x2f>
movsbl 0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"gethndl: read error handle=%d\0A\00"
define i32 @gethndl(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [8 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 1)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = load i32, i32* @EOF
store i32 %12, i32* %2
br label %25
13: ; preds = %1
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = load i32, i32* %3
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
store i32 %24, i32* %2
br label %25
25: ; preds = %21, %11
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"gethndl: read error handle=%d\0A\00"
define i32 @gethndl(i32 %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 1)
switch i32 %4, label %7 [
i32 0, label %5
i32 1, label %11
]
5: ; preds = %1
%6 = load i32, i32* @EOF
br label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
br label %14
14: ; preds = %11, %5
%15 = phi i32 [ %13, %11 ], [ %6, %5 ]
ret i32 %15
}