#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*/ xdrproc_t;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct sockaddr_in {
  scalar_t__ sin_port;
};
struct pmaplist {
  int dummy;
};
typedef int /*<<< orphan*/ caddr_t;
typedef int /*<<< orphan*/ CLIENT;

/* Variables and functions */
scalar_t__ CLNT_CALL(int /*<<< orphan*/ *, int /*<<< orphan*/,
                     int /*<<< orphan*/, int /*<<< orphan*/ *,
                     int /*<<< orphan*/, int /*<<< orphan*/, struct timeval);
int /*<<< orphan*/ CLNT_DESTROY(int /*<<< orphan*/ *);
int /*<<< orphan*/ PMAPPORT;
int /*<<< orphan*/ PMAPPROC_DUMP;
int /*<<< orphan*/ PMAPPROG;
int /*<<< orphan*/ PMAPVERS;
scalar_t__ RPC_SUCCESS;
int /*<<< orphan*/ clnt_perror(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *clnttcp_create(struct sockaddr_in *, int /*<<< orphan*/,
                                   int /*<<< orphan*/, int *, int, int);
scalar_t__ htons(int /*<<< orphan*/);
scalar_t__ xdr_pmaplist;
scalar_t__ xdr_void;
struct pmaplist *pmap_getmaps(struct sockaddr_in *address) {
  struct pmaplist *head = (struct pmaplist *)NULL;
  int _socket = -1;
  struct timeval minutetimeout;
  CLIENT *client;
  minutetimeout.tv_sec = 60;
  minutetimeout.tv_usec = 0;
  address->sin_port = htons(PMAPPORT);
  client = clnttcp_create(address, PMAPPROG, PMAPVERS, &_socket, 50, 500);
  if (client != (CLIENT *)NULL) {
    if (CLNT_CALL(client, PMAPPROC_DUMP, (xdrproc_t)xdr_void, NULL,
                  (xdrproc_t)xdr_pmaplist, (caddr_t)&head,
                  minutetimeout) != RPC_SUCCESS) {
      clnt_perror(client, "pmap_getmaps rpc problem");
    }
    CLNT_DESTROY(client);
  }
  address->sin_port = 0;
  return head;
}


x86 assembly (clang, -O0):
<pmap_getmaps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x3c,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
mov    $0x32,%r8d
mov    $0x1f4,%r9d
call   1050 <clnttcp_create@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     123f <pmap_getmaps+0xef>
mov    -0x30(%rbp),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    0x2df8(%rip),%rax
mov    (%rax),%rax
mov    %eax,%edx
mov    0x2dc4(%rip),%rax
mov    (%rax),%rax
mov    %eax,%r8d
lea    -0x10(%rbp),%rax
mov    %eax,%r9d
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%rax
mov    (%rax),%r10
mov    %r10,(%rsp)
mov    0x8(%rax),%rax
mov    %rax,0x8(%rsp)
call   1070 <CLNT_CALL@plt>
mov    0x2db3(%rip),%rcx
cmp    (%rcx),%rax
je     1236 <pmap_getmaps+0xe6>
mov    -0x30(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1040 <clnt_perror@plt>
mov    -0x30(%rbp),%rdi
call   1060 <CLNT_DESTROY@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pmap_getmaps>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
movq   $0x0,0x20(%rsp)
movl   $0xffffffff,0x1c(%rsp)
ff
movl   $0x3c,0x28(%rsp)
movq   $0x0,0x30(%rsp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %rax,(%r14)
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
lea    0x1c(%rsp),%rcx
mov    %r14,%rdi
mov    $0x32,%r8d
mov    $0x1f4,%r9d
call   1050 <clnttcp_create@plt>
test   %rax,%rax
je     121e <pmap_getmaps+0xce>
mov    %rax,%rbx
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    0x2dd7(%rip),%rax
mov    (%rax),%r8d
lea    0x20(%rsp),%r9
movups 0x28(%rsp),%xmm0
movups %xmm0,(%rsp)
mov    %rbx,%rdi
xor    %ecx,%ecx
call   1070 <CLNT_CALL@plt>
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%rax
je     120f <pmap_getmaps+0xbf>
lea    0xdf9(%rip),%rsi
mov    %rbx,%rdi
call   1040 <clnt_perror@plt>
mov    %rbx,%rdi
call   1060 <CLNT_DESTROY@plt>
mov    0x20(%rsp),%rax
jmp    1220 <pmap_getmaps+0xd0>
xor    %eax,%eax
movq   $0x0,(%r14)
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.pmaplist = type { i32 }
%struct.sockaddr_in = type { i64 }
%struct.timeval = type { i32, i64 }
@PMAPPORT = global i32 0
@PMAPPROG = global i32 0
@PMAPVERS = global i32 0
@PMAPPROC_DUMP = global i32 0
@xdr_void = global i64 0
@xdr_pmaplist = global i64 0
@RPC_SUCCESS = global i64 0
@.str = [25 x i8] c"pmap_getmaps rpc problem\00"
define %struct.pmaplist* @pmap_getmaps(%struct.sockaddr_in* %0) {
%2 = alloca %struct.sockaddr_in*
%3 = alloca %struct.pmaplist*
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i32*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %2
store %struct.pmaplist* null, %struct.pmaplist** %3
store i32 -1, i32* %4
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 60, i32* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i64 0, i64* %8
%9 = load i32, i32* @PMAPPORT
%10 = call i64 @htons(i32 %9)
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i64 %10, i64* %12
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%14 = load i32, i32* @PMAPPROG
%15 = load i32, i32* @PMAPVERS
%16 = call i32* @clnttcp_create(%struct.sockaddr_in* %13, i32 %14, i32 %15, i32* %4, i32 50, i32 500)
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %36
19: ; preds = %1
%20 = load i32*, i32** %6
%21 = load i32, i32* @PMAPPROC_DUMP
%22 = load i64, i64* @xdr_void
%23 = trunc i64 %22 to i32
%24 = load i64, i64* @xdr_pmaplist
%25 = trunc i64 %24 to i32
%26 = ptrtoint %struct.pmaplist** %3 to i32
%27 = call i64 @CLNT_CALL(i32* %20, i32 %21, i32 %23, i32* null, i32 %25, i32 %26, %struct.timeval* byval(%struct.timeval) align 8 %5)
%28 = load i64, i64* @RPC_SUCCESS
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %19
%31 = load i32*, i32** %6
%32 = call i32 @clnt_perror(i32* %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %30, %19
%34 = load i32*, i32** %6
%35 = call i32 @CLNT_DESTROY(i32* %34)
br label %36
36: ; preds = %33, %1
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %37, i32 0, i32 0
store i64 0, i64* %38
%39 = load %struct.pmaplist*, %struct.pmaplist** %3
ret %struct.pmaplist* %39
}

LLVM IR (-O2):
%struct.pmaplist = type { i32 }
%struct.sockaddr_in = type { i64 }
%struct.timeval = type { i32, i64 }
@PMAPPORT = global i32 0
@PMAPPROG = global i32 0
@PMAPVERS = global i32 0
@PMAPPROC_DUMP = global i32 0
@xdr_void = global i64 0
@xdr_pmaplist = global i64 0
@RPC_SUCCESS = global i64 0
@.str = [25 x i8] c"pmap_getmaps rpc problem\00"
define %struct.pmaplist* @pmap_getmaps(%struct.sockaddr_in* %0) {
%2 = alloca %struct.pmaplist*
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = bitcast %struct.pmaplist** %2 to i8*
store %struct.pmaplist* null, %struct.pmaplist** %2
%6 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%7 = bitcast %struct.timeval* %4 to i8*
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 60, i32* %8
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 0, i64* %9
%10 = load i32, i32* @PMAPPORT
%11 = tail call i64 @htons(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
store i64 %11, i64* %12
%13 = load i32, i32* @PMAPPROG
%14 = load i32, i32* @PMAPVERS
%15 = call i32* @clnttcp_create(%struct.sockaddr_in* %0, i32 %13, i32 %14, i32* %3, i32 50, i32 500)
%16 = icmp eq i32* %15, null
br i1 %16, label %33, label %17
17: ; preds = %1
%18 = load i32, i32* @PMAPPROC_DUMP
%19 = load i64, i64* @xdr_void
%20 = trunc i64 %19 to i32
%21 = load i64, i64* @xdr_pmaplist
%22 = trunc i64 %21 to i32
%23 = ptrtoint %struct.pmaplist** %2 to i64
%24 = trunc i64 %23 to i32
%25 = call i64 @CLNT_CALL(i32* %15, i32 %18, i32 %20, i32* null, i32 %22, i32 %24, %struct.timeval* byval(%struct.timeval) align 8 %4)
%26 = load i64, i64* @RPC_SUCCESS
%27 = icmp eq i64 %25, %26
br i1 %27, label %30, label %28
28: ; preds = %17
%29 = call i32 @clnt_perror(i32* %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %17
%31 = call i32 @CLNT_DESTROY(i32* %15)
%32 = load %struct.pmaplist*, %struct.pmaplist** %2
br label %33
33: ; preds = %30, %1
%34 = phi %struct.pmaplist* [ %32, %30 ], [ null, %1 ]
store i64 0, i64* %12
ret %struct.pmaplist* %34
}