#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*/ u_long;
typedef int /*<<< orphan*/ u_int;
struct sockaddr_in {
  int dummy;
};

/* Variables and functions */
scalar_t__ __libc_rpc_gethostbyname(char const *, struct sockaddr_in *);
int pmap_getport(struct sockaddr_in *, int /*<<< orphan*/, int /*<<< orphan*/,
                 int /*<<< orphan*/);
int getrpcport(const char *host, u_long prognum, u_long versnum, u_int proto) {
  struct sockaddr_in addr;
  if (__libc_rpc_gethostbyname(host, &addr) != 0)
    return 0;
  return pmap_getport(&addr, prognum, versnum, proto);
}


x86 assembly (clang, -O0):
<getrpcport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <__libc_rpc_gethostbyname@plt>
cmp    $0x0,%rax
je     1158 <getrpcport+0x38>
movl   $0x0,-0x4(%rbp)
jmp    116d <getrpcport+0x4d>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    -0x20(%rbp),%rdi
call   1040 <pmap_getport@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrpcport>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%ebx
lea    0x8(%rsp),%rsi
call   1030 <__libc_rpc_gethostbyname@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1154 <getrpcport+0x34>
lea    0x8(%rsp),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <pmap_getport@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
define i32 @getrpcport(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i8*, i8** %6
%12 = call i64 @__libc_rpc_gethostbyname(i8* %11, %struct.sockaddr_in* %10)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 0, i32* %5
br label %20
15: ; preds = %4
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = call i32 @pmap_getport(%struct.sockaddr_in* %10, i32 %16, i32 %17, i32 %18)
store i32 %19, i32* %5
br label %20
20: ; preds = %15, %14
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
define i32 @getrpcport(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.sockaddr_in
%6 = bitcast %struct.sockaddr_in* %5 to i8*
%7 = call i64 @__libc_rpc_gethostbyname(i8* %0, %struct.sockaddr_in* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = call i32 @pmap_getport(%struct.sockaddr_in* %5, i32 %1, i32 %2, i32 %3)
br label %11
11: ; preds = %4, %9
%12 = phi i32 [ %10, %9 ], [ 0, %4 ]
ret i32 %12
}