#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 */
struct sockaddr {
  int dummy;
};
struct pollfd {
  int fd;
  int events;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ rpl_buf;

/* Variables and functions */
int /*<<< orphan*/ MSG_DONTWAIT;
int POLLERR;
int POLLIN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    int /*<<< orphan*/ *);
int rpcbind_socket();
int /*<<< orphan*/ stderr;
int rpcbind_recv(struct sockaddr *addr, socklen_t *alen, int timeout) {
  char rpl_buf[1024];
  int fd;
  printf("receicing reply...");
  if ((fd = rpcbind_socket()) < 0)
    return 0;
  if (timeout >= 0) {
    struct pollfd pfd;
    pfd.fd = fd;
    pfd.events = POLLIN | POLLERR;
    switch (poll(&pfd, 1, timeout * 1000)) {
    case 0:
      fprintf(stderr, "Timed out waiting for reply\n");
      return 0;
    case -1:
      perror("poll failed");
      return 0;
    }
  }
  if (recvfrom(fd, rpl_buf, sizeof(rpl_buf), MSG_DONTWAIT, addr, alen) < 0) {
    perror("recvfrom failed");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<rpcbind_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <rpcbind_socket@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jge    11a4 <rpcbind_recv+0x44>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <rpcbind_recv+0x146>
cmpl   $0x0,-0x1c(%rbp)
jl     1255 <rpcbind_recv+0xf5>
mov    -0x424(%rbp),%eax
mov    %eax,-0x430(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    0x2e1e(%rip),%rcx
mov    (%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x42c(%rbp)
mov    -0x1c(%rbp),%eax
imul   $0x3e8,%eax,%edx
lea    -0x430(%rbp),%rdi
mov    $0x1,%esi
call   1070 <poll@plt>
mov    %eax,%ecx
mov    %ecx,-0x434(%rbp)
sub    $0xffffffff,%eax
je     1238 <rpcbind_recv+0xd8>
jmp    1204 <rpcbind_recv+0xa4>
mov    -0x434(%rbp),%eax
test   %eax,%eax
jne    1250 <rpcbind_recv+0xf0>
jmp    1217 <rpcbind_recv+0xb7>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <rpcbind_recv+0x146>
lea    0xdf1(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <rpcbind_recv+0x146>
jmp    1255 <rpcbind_recv+0xf5>
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    0x2d5f(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    $0x400,%edx
call   1060 <recvfrom@plt>
cmp    $0x0,%rax
jge    129f <rpcbind_recv+0x13f>
lea    0xdae(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <rpcbind_recv+0x146>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpcbind_recv>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <rpcbind_socket@plt>
test   %eax,%eax
js     121a <rpcbind_recv+0xba>
mov    %eax,%ebp
test   %r12d,%r12d
js     11d2 <rpcbind_recv+0x72>
mov    %ebp,(%rsp)
mov    0x2e3a(%rip),%rax
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x4(%rsp)
imul   $0x3e8,%r12d,%edx
mov    %rsp,%rdi
mov    $0x1,%esi
call   1070 <poll@plt>
test   %eax,%eax
je     1203 <rpcbind_recv+0xa3>
cmp    $0xffffffff,%eax
je     122c <rpcbind_recv+0xcc>
mov    0x2def(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x400,%edx
mov    %r15,%r8
mov    %r14,%r9
call   1060 <recvfrom@plt>
mov    $0x1,%ebx
test   %rax,%rax
jns    121a <rpcbind_recv+0xba>
lea    0xe3b(%rip),%rdi
jmp    1233 <rpcbind_recv+0xd3>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfd(%rip),%rdi
call   1080 <perror@plt>
jmp    1218 <rpcbind_recv+0xb8>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.pollfd = type { i32, i32 }
@.str = [19 x i8] c"receicing reply...\00"
@POLLIN = global i32 0
@POLLERR = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"Timed out waiting for reply\0A\00"
@.str.2 = [12 x i8] c"poll failed\00"
@MSG_DONTWAIT = global i32 0
@.str.3 = [16 x i8] c"recvfrom failed\00"
define i32 @rpcbind_recv(%struct.sockaddr* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca %struct.pollfd
store %struct.sockaddr* %0, %struct.sockaddr** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%11 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (...) @rpcbind_socket()
store i32 %12, i32* %9
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %45
15: ; preds = %3
%16 = load i32, i32* %7
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = load i32, i32* %9
%20 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* @POLLIN
%22 = load i32, i32* @POLLERR
%23 = or i32 %21, %22
%24 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i32 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* %7
%26 = mul nsw i32 %25, 1000
%27 = call i32 @poll(%struct.pollfd* %10, i32 1, i32 %26)
switch i32 %27, label %33 [
i32 0, label %28
i32 -1, label %31
]
28: ; preds = %18
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %45
31: ; preds = %18
%32 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %45
33: ; preds = %18
br label %34
34: ; preds = %33, %15
%35 = load i32, i32* %9
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%37 = load i32, i32* @MSG_DONTWAIT
%38 = load %struct.sockaddr*, %struct.sockaddr** %5
%39 = load i32*, i32** %6
%40 = call i64 @recvfrom(i32 %35, i8* %36, i32 1024, i32 %37, %struct.sockaddr* %38, i32* %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %45
44: ; preds = %34
store i32 1, i32* %4
br label %45
45: ; preds = %44, %42, %31, %28, %14
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.pollfd = type { i32, i32 }
@.str = [19 x i8] c"receicing reply...\00"
@POLLIN = global i32 0
@POLLERR = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"Timed out waiting for reply\0A\00"
@.str.2 = [12 x i8] c"poll failed\00"
@MSG_DONTWAIT = global i32 0
@.str.3 = [16 x i8] c"recvfrom failed\00"
define i32 @rpcbind_recv(%struct.sockaddr* %0, i32* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = alloca %struct.pollfd
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @rpcbind_socket()
%9 = icmp slt i32 %8, 0
br i1 %9, label %33, label %10
10: ; preds = %3
%11 = icmp sgt i32 %2, -1
br i1 %11, label %12, label %27
12: ; preds = %10
%13 = bitcast %struct.pollfd* %5 to i8*
%14 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 0, i32 0
store i32 %8, i32* %14
%15 = load i32, i32* @POLLIN
%16 = load i32, i32* @POLLERR
%17 = or i32 %16, %15
%18 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 0, i32 1
store i32 %17, i32* %18
%19 = mul nsw i32 %2, 1000
%20 = call i32 @poll(%struct.pollfd* %5, i32 1, i32 %19)
switch i32 %20, label %26 [
i32 0, label %21
i32 -1, label %24
]
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %33
24: ; preds = %12
%25 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %33
26: ; preds = %12
br label %27
27: ; preds = %26, %10
%28 = load i32, i32* @MSG_DONTWAIT
%29 = call i64 @recvfrom(i32 %8, i8* %6, i32 1024, i32 %28, %struct.sockaddr* %0, i32* %1)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %27, %21, %24, %3, %31
%34 = phi i32 [ 0, %31 ], [ 0, %3 ], [ 0, %24 ], [ 0, %21 ], [ 1, %27 ]
ret i32 %34
}