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


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

x86 assembly (clang, -O2):
<recvint>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%r14
mov    0x2e99(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0x4,%eax
je     1184 <recvint+0x54>
mov    (%r15),%edi
cmp    $0x80,%edi
je     1150 <recvint+0x20>
call   1050 <strerror@plt>
lea    0xe85(%rip),%rdi
mov    %eax,%esi
call   1030 <panic@plt>
jmp    1188 <recvint+0x58>
mov    0xc(%rsp),%eax
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 i32 @recvint(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
br label %5
5: ; preds = %14, %1
%6 = load i32, i32* %3
%7 = call i32 @read(i32 %6, i32* %4, i32 4)
%8 = sext i32 %7 to i64
%9 = icmp eq i64 %8, 4
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = load i32, i32* %4
store i32 %11, i32* %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 i32, i32* %2
ret i32 %20
}

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