#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_in {
  scalar_t__ sin_port;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_addr;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ memmove(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int pmap_getport(struct sockaddr_in *, unsigned long, unsigned long,
                 unsigned int);
extern int getrpcport(const char *host, unsigned long prognum,
                      unsigned long versnum, unsigned int proto) {
  struct sockaddr_in addr;
  struct hostent *hp;
  if ((hp = gethostbyname(host)) == NULL)
    return (0);
  memmove((char *)&addr.sin_addr, hp->h_addr, hp->h_length);
  addr.sin_family = AF_INET;
  addr.sin_port = 0;
  return (pmap_getport(&addr, prognum, versnum, proto));
}


x86 assembly (clang, -O0):
<getrpcport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    116a <getrpcport+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    11af <getrpcport+0x7f>
lea    -0x38(%rbp),%rdi
add    $0xc,%rdi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1050 <memmove@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    -0x38(%rbp),%rdi
call   1030 <pmap_getport@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrpcport>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%rbp
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1182 <getrpcport+0x52>
lea    0xc(%rsp),%rdi
mov    (%rax),%edx
mov    0x4(%rax),%esi
call   1050 <memmove@plt>
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %rsp,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1030 <pmap_getport@plt>
jmp    1184 <getrpcport+0x54>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i64, i32, i32 }
%struct.hostent = type { i32, i32 }
@AF_INET = global i32 0
define i32 @getrpcport(i8* %0, i64 %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
%13 = call %struct.hostent* @gethostbyname(i8* %12)
store %struct.hostent* %13, %struct.hostent** %11
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 0, i32* %5
br label %33
16: ; preds = %4
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
%18 = bitcast i32* %17 to i8*
%19 = load %struct.hostent*, %struct.hostent** %11
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load %struct.hostent*, %struct.hostent** %11
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @memmove(i8* %18, i32 %21, i32 %24)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i64 0, i64* %28
%29 = load i64, i64* %7
%30 = load i64, i64* %8
%31 = load i32, i32* %9
%32 = call i32 @pmap_getport(%struct.sockaddr_in* %10, i64 %29, i64 %30, i32 %31)
store i32 %32, i32* %5
br label %33
33: ; preds = %16, %15
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i64, i32, i32 }
%struct.hostent = type { i32, i32 }
@AF_INET = global i32 0
define i32 @getrpcport(i8* %0, i64 %1, i64 %2, i32 %3) {
%5 = alloca %struct.sockaddr_in
%6 = bitcast %struct.sockaddr_in* %5 to i8*
%7 = tail call %struct.hostent* @gethostbyname(i8* %0)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %21, label %9
9: ; preds = %4
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
%11 = bitcast i32* %10 to i8*
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @memmove(i8* %11, i32 %13, i32 %15)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i64 0, i64* %19
%20 = call i32 @pmap_getport(%struct.sockaddr_in* %5, i64 %1, i64 %2, i32 %3)
br label %21
21: ; preds = %4, %9
%22 = phi i32 [ %20, %9 ], [ 0, %4 ]
ret i32 %22
}