#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 */
#define EINTR 128
int errno;
int /*<<< orphan*/ panic(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ strerror(int);
char evt_recv(int fd) {
  char code;
Read:
  if (read(fd, &code, sizeof code) == sizeof code)
    return code;
  switch (errno) {
  case EINTR:
    goto Read;
  default:
    panic("read() failed: %s", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<evt_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cltq
cmp    $0x1,%rax
jne    1163 <evt_recv+0x33>
mov    -0x9(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    119d <evt_recv+0x6d>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    1181 <evt_recv+0x51>
jmp    117c <evt_recv+0x4c>
jmp    113b <evt_recv+0xb>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe68(%rip),%rdi
call   1030 <panic@plt>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evt_recv>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xf(%rsp),%r14
mov    0x2e99(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
je     1184 <evt_recv+0x54>
mov    (%r15),%edi
cmp    $0x80,%edi
je     1150 <evt_recv+0x20>
call   1050 <strerror@plt>
lea    0xe85(%rip),%rdi
mov    %eax,%esi
call   1030 <panic@plt>
jmp    1188 <evt_recv+0x58>
mov    0xf(%rsp),%al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [18 x i8] c"read() failed: %s\00"
define signext i8 @evt_recv(i32 %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %3
br label %5
5: ; preds = %14, %1
%6 = load i32, i32* %3
%7 = call i32 @read(i32 %6, i8* %4, i32 1)
%8 = sext i32 %7 to i64
%9 = icmp eq i64 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = load i8, i8* %4
store i8 %11, i8* %2
br label %19
12: ; preds = %5
%13 = load i32, i32* @errno
switch i32 %13, label %15 [
i32 128, label %14
]
14: ; preds = %12
br label %5
15: ; preds = %12
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @panic(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %10, %15
%20 = load i8, i8* %2
ret i8 %20
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [18 x i8] c"read() failed: %s\00"
define signext i8 @evt_recv(i32 %0) {
%2 = alloca i8
br label %3
3: ; preds = %8, %1
%4 = call i32 @read(i32 %0, i8* %2, i32 1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = load i8, i8* %2
br label %14
8: ; preds = %3
%9 = load i32, i32* @errno
%10 = icmp eq i32 %9, 128
br i1 %10, label %3, label %11
11: ; preds = %8
%12 = tail call i32 @strerror(i32 %9)
%13 = tail call i32 @panic(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %11, %6
%15 = phi i8 [ %7, %6 ], [ undef, %11 ]
ret i8 %15
}