#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*/ buf;

/* Variables and functions */
int EAGAIN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int);
int read(int, int *, int);
int /*<<< orphan*/ stderr;
int ivshmem_recv(int fd) {
  int rv, buf;
  buf = 0;
  rv = read(fd, &buf, sizeof(buf));
  printf("[RECVIOCTL] rv is %d\n", rv);
  if (rv == -EAGAIN) {
    fprintf(stderr, "EAGAIN\n");
  } else if (rv < 0) {
    fprintf(stderr, "other error\n");
  }
  return buf;
}


x86 assembly (clang, -O0):
<ivshmem_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
xor    %ecx,%ecx
mov    0x2e5f(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
jne    1195 <ivshmem_recv+0x65>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11b9 <ivshmem_recv+0x89>
cmpl   $0x0,-0x8(%rbp)
jge    11b4 <ivshmem_recv+0x84>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11b9 <ivshmem_recv+0x89>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ivshmem_recv>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,%ebx
lea    0xeab(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
add    %ebx,%eax
jne    1172 <ivshmem_recv+0x42>
lea    0xea6(%rip),%rsi
jmp    117d <ivshmem_recv+0x4d>
test   %ebx,%ebx
jns    118b <ivshmem_recv+0x5b>
lea    0xea1(%rip),%rsi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1050 <fprintf@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"[RECVIOCTL] rv is %d\0A\00"
@EAGAIN = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"EAGAIN\0A\00"
@.str.2 = [13 x i8] c"other error\0A\00"
define i32 @ivshmem_recv(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
%5 = load i32, i32* %2
%6 = call i32 @read(i32 %5, i32* %4, i32 4)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %3
%10 = load i32, i32* @EAGAIN
%11 = sub nsw i32 0, %10
%12 = icmp eq i32 %9, %11
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %23
16: ; preds = %1
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %19, %16
br label %23
23: ; preds = %22, %13
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@.str = [22 x i8] c"[RECVIOCTL] rv is %d\0A\00"
@EAGAIN = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"EAGAIN\0A\00"
@.str.2 = [13 x i8] c"other error\0A\00"
define i32 @ivshmem_recv(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = call i32 @read(i32 %0, i32* %2, i32 4)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @EAGAIN
%7 = sub nsw i32 0, %6
%8 = icmp eq i32 %4, %7
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = icmp slt i32 %4, 0
br i1 %10, label %11, label %15
11: ; preds = %9, %1
%12 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %9 ]
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* %12)
br label %15
15: ; preds = %11, %9
%16 = load i32, i32* %2
ret i32 %16
}