#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct ypbind_setdom {
  int ypsetdom_port;
  int /*<<< orphan*/ ypsetdom_vers;
  int /*<<< orphan*/ ypsetdom_domain;
  int /*<<< orphan*/ ypsetdom_addr;
};
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct sockaddr_in {
  int dummy;
};
struct TYPE_5__ {
  int /*<<< orphan*/ cl_auth;
};
typedef TYPE_1__ CLIENT;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_UDP;
int RPC_ANYSOCK;
int /*<<< orphan*/ YPBINDPROC_SETDOM;
int /*<<< orphan*/ YPBINDPROG;
int /*<<< orphan*/ YPBINDVERS;
int YPERR_YPBIND;
int /*<<< orphan*/ YPPROC_NULL;
int /*<<< orphan*/ YPPROG;
int /*<<< orphan*/ YPVERS;
int /*<<< orphan*/ authunix_create_default();
int clnt_call(TYPE_1__ *, int /*<<< orphan*/, int /*<<< orphan*/,
              struct ypbind_setdom *, int /*<<< orphan*/, int /*<<< orphan*/ *,
              struct timeval);
int /*<<< orphan*/ clnt_destroy(TYPE_1__ *);
int /*<<< orphan*/ clnt_sperrno(int);
TYPE_1__ *clntudp_create(struct sockaddr_in *, int /*<<< orphan*/,
                         int /*<<< orphan*/, struct timeval, int *);
int /*<<< orphan*/ errx(int, char *, char *);
int /*<<< orphan*/ gethostaddr(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ getrpcport(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct ypbind_setdom *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strlcpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ warnx(char *, char *, ...);
int /*<<< orphan*/ xdr_void;
int /*<<< orphan*/ xdr_ypbind_setdom;
int /*<<< orphan*/ yperr_string(int);
int bind_tohost(struct sockaddr_in *sin, char *dom, char *server) {
  struct ypbind_setdom ypsd;
  struct timeval tv;
  CLIENT *client;
  int sock, port;
  int r;
  port = htons(getrpcport(server, YPPROG, YPPROC_NULL, IPPROTO_UDP));
  if (port == 0)
    errx(1, "%s not running ypserv.", server);
  (void)memset(&ypsd, 0, sizeof ypsd);
  gethostaddr(server, &ypsd.ypsetdom_addr);
  (void)strlcpy(ypsd.ypsetdom_domain, dom, sizeof ypsd.ypsetdom_domain);
  ypsd.ypsetdom_port = port;
  ypsd.ypsetdom_vers = YPVERS;
  tv.tv_sec = 15;
  tv.tv_usec = 0;
  sock = RPC_ANYSOCK;
  client = clntudp_create(sin, YPBINDPROG, YPBINDVERS, tv, &sock);
  if (client == NULL) {
    warnx("Can't yp_bind: Reason: %s", yperr_string(YPERR_YPBIND));
    return YPERR_YPBIND;
  }
  client->cl_auth = authunix_create_default();
  r = clnt_call(client, YPBINDPROC_SETDOM, xdr_ypbind_setdom, &ypsd, xdr_void,
                NULL, tv);
  if (r) {
    warnx("Cannot ypset for domain %s on host %s: %s.", dom, server,
          clnt_sperrno(r));
    clnt_destroy(client);
    return YPERR_YPBIND;
  }
  clnt_destroy(client);
  return 0;
}


x86 assembly (clang, -O0):
<bind_tohost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    0x2dad(%rip),%rax
mov    (%rax),%edx
mov    0x2d84(%rip),%rax
mov    (%rax),%ecx
call   1030 <getrpcport@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jne    1234 <bind_tohost+0x64>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xdd1(%rip),%rsi
call   1050 <errx@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
add    $0xc,%rsi
call   1040 <gethostaddr@plt>
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <strlcpy@plt>
mov    -0x50(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movl   $0xf,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2d12(%rip),%rax
mov    (%rax),%esi
mov    0x2d11(%rip),%rax
mov    (%rax),%edx
mov    -0x40(%rbp),%ecx
mov    -0x38(%rbp),%r8
lea    -0x4c(%rbp),%r9
call   10f0 <clntudp_create@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12f8 <bind_tohost+0x128>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   10a0 <yperr_string@plt>
movslq %eax,%rsi
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
mov    0x2caa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13b0 <bind_tohost+0x1e0>
mov    $0x0,%al
call   1090 <authunix_create_default@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%rdi
mov    0x2c8e(%rip),%rax
mov    (%rax),%esi
mov    0x2ccd(%rip),%rax
mov    (%rax),%edx
mov    0x2cac(%rip),%rax
mov    (%rax),%r8d
lea    -0x30(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r9d
lea    -0x40(%rbp),%rax
mov    (%rax),%r10
mov    %r10,(%rsp)
mov    0x8(%rax),%rax
mov    %rax,0x8(%rsp)
call   10c0 <clnt_call@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     13a0 <bind_tohost+0x1d0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x54(%rbp),%edi
call   10d0 <clnt_sperrno@plt>
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    %eax,%ecx
lea    0xcb2(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
mov    -0x48(%rbp),%rdi
call   10e0 <clnt_destroy@plt>
mov    0x2c02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13b0 <bind_tohost+0x1e0>
mov    -0x48(%rbp),%rdi
call   10e0 <clnt_destroy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bind_tohost>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
mov    0x2d8b(%rip),%rax
mov    (%rax),%ecx
mov    %r12,%rdi
call   1030 <getrpcport@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1228 <bind_tohost+0x58>
lea    0xde5(%rip),%rsi
mov    $0x1,%edi
mov    %r12,%rdx
call   1050 <errx@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    0x24(%rsp),%rsi
mov    %r12,%rdi
call   1040 <gethostaddr@plt>
mov    0x20(%rsp),%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   10b0 <strlcpy@plt>
mov    %ebx,0x18(%rsp)
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
movl   $0xf,0x28(%rsp)
movq   $0x0,0x30(%rsp)
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2d23(%rip),%rax
mov    (%rax),%esi
mov    0x2d22(%rip),%rax
mov    (%rax),%edx
lea    0x14(%rsp),%r9
mov    %r15,%rdi
mov    $0xf,%ecx
xor    %r8d,%r8d
call   10f0 <clntudp_create@plt>
test   %rax,%rax
je     132b <bind_tohost+0x15b>
mov    %rax,%rbx
xor    %r15d,%r15d
xor    %eax,%eax
call   1090 <authunix_create_default@plt>
mov    %eax,(%rbx)
mov    0x2cd8(%rip),%rax
mov    (%rax),%esi
mov    0x2d17(%rip),%rax
mov    (%rax),%edx
mov    0x2cf6(%rip),%rax
mov    (%rax),%r8d
movups 0x28(%rsp),%xmm0
movups %xmm0,(%rsp)
lea    0x18(%rsp),%rcx
mov    %rbx,%rdi
xor    %r9d,%r9d
call   10c0 <clnt_call@plt>
test   %eax,%eax
je     134f <bind_tohost+0x17f>
mov    %eax,%edi
call   10d0 <clnt_sperrno@plt>
lea    0xd29(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <warnx@plt>
mov    %rbx,%rdi
call   10e0 <clnt_destroy@plt>
mov    0x2c72(%rip),%rax
mov    (%rax),%r15d
jmp    1357 <bind_tohost+0x187>
mov    0x2c66(%rip),%rbx
mov    (%rbx),%edi
call   10a0 <yperr_string@plt>
movslq %eax,%rsi
lea    0xcd4(%rip),%rdi
xor    %eax,%eax
call   1070 <warnx@plt>
mov    (%rbx),%r15d
jmp    1357 <bind_tohost+0x187>
mov    %rbx,%rdi
call   10e0 <clnt_destroy@plt>
mov    %r15d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.ypbind_setdom = type { i32, i32, i32, i32 }
%struct.timeval = type { i32, i64 }
%struct.TYPE_5__ = type { i32 }
@YPPROG = global i32 0
@YPPROC_NULL = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [23 x i8] c"%s not running ypserv.\00"
@YPVERS = global i32 0
@RPC_ANYSOCK = global i32 0
@YPBINDPROG = global i32 0
@YPBINDVERS = global i32 0
@.str.1 = [26 x i8] c"Can't yp_bind: Reason: %s\00"
@YPERR_YPBIND = global i32 0
@YPBINDPROC_SETDOM = global i32 0
@xdr_ypbind_setdom = global i32 0
@xdr_void = global i32 0
@.str.2 = [43 x i8] c"Cannot ypset for domain %s on host %s: %s.\00"
define i32 @bind_tohost(%struct.sockaddr_in* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.ypbind_setdom
%9 = alloca %struct.timeval
%10 = alloca %struct.TYPE_5__*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%14 = load i8*, i8** %7
%15 = load i32, i32* @YPPROG
%16 = load i32, i32* @YPPROC_NULL
%17 = load i32, i32* @IPPROTO_UDP
%18 = call i32 @getrpcport(i8* %14, i32 %15, i32 %16, i32 %17)
%19 = call i32 @htons(i32 %18)
store i32 %19, i32* %12
%20 = load i32, i32* %12
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = load i8*, i8** %7
%24 = call i32 @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %3
%26 = call i32 @memset(%struct.ypbind_setdom* %8, i32 0, i32 16)
%27 = load i8*, i8** %7
%28 = getelementptr inbounds %struct.ypbind_setdom, %struct.ypbind_setdom* %8, i32 0, i32 3
%29 = call i32 @gethostaddr(i8* %27, i32* %28)
%30 = getelementptr inbounds %struct.ypbind_setdom, %struct.ypbind_setdom* %8, i32 0, i32 2
%31 = load i32, i32* %30
%32 = load i8*, i8** %6
%33 = call i32 @strlcpy(i32 %31, i8* %32, i32 4)
%34 = load i32, i32* %12
%35 = getelementptr inbounds %struct.ypbind_setdom, %struct.ypbind_setdom* %8, i32 0, i32 0
store i32 %34, i32* %35
%36 = load i32, i32* @YPVERS
%37 = getelementptr inbounds %struct.ypbind_setdom, %struct.ypbind_setdom* %8, i32 0, i32 1
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
store i32 15, i32* %38
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store i64 0, i64* %39
%40 = load i32, i32* @RPC_ANYSOCK
store i32 %40, i32* %11
%41 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%42 = load i32, i32* @YPBINDPROG
%43 = load i32, i32* @YPBINDVERS
%44 = bitcast %struct.timeval* %9 to { i32, i64 }*
%45 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %44, i32 0, i32 1
%48 = load i64, i64* %47
%49 = call %struct.TYPE_5__* @clntudp_create(%struct.sockaddr_in* %41, i32 %42, i32 %43, i32 %46, i64 %48, i32* %11)
store %struct.TYPE_5__* %49, %struct.TYPE_5__** %10
%50 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%51 = icmp eq %struct.TYPE_5__* %50, null
br i1 %51, label %52, label %59
52: ; preds = %25
%53 = load i32, i32* @YPERR_YPBIND
%54 = call i32 @yperr_string(i32 %53)
%55 = sext i32 %54 to i64
%56 = inttoptr i64 %55 to i8*
%57 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %56)
%58 = load i32, i32* @YPERR_YPBIND
store i32 %58, i32* %4
br label %82
59: ; preds = %25
%60 = call i32 (...) @authunix_create_default()
%61 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%62 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %61, i32 0, i32 0
store i32 %60, i32* %62
%63 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%64 = load i32, i32* @YPBINDPROC_SETDOM
%65 = load i32, i32* @xdr_ypbind_setdom
%66 = load i32, i32* @xdr_void
%67 = call i32 @clnt_call(%struct.TYPE_5__* %63, i32 %64, i32 %65, %struct.ypbind_setdom* %8, i32 %66, i32* null, %struct.timeval* byval(%struct.timeval) align 8 %9)
store i32 %67, i32* %13
%68 = load i32, i32* %13
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %79
70: ; preds = %59
%71 = load i8*, i8** %6
%72 = load i8*, i8** %7
%73 = load i32, i32* %13
%74 = call i32 @clnt_sperrno(i32 %73)
%75 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %71, i8* %72, i32 %74)
%76 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%77 = call i32 @clnt_destroy(%struct.TYPE_5__* %76)
%78 = load i32, i32* @YPERR_YPBIND
store i32 %78, i32* %4
br label %82
79: ; preds = %59
%80 = load %struct.TYPE_5__*, %struct.TYPE_5__** %10
%81 = call i32 @clnt_destroy(%struct.TYPE_5__* %80)
store i32 0, i32* %4
br label %82
82: ; preds = %79, %70, %52
%83 = load i32, i32* %4
ret i32 %83
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.ypbind_setdom = type { i32, i32, i32, i32 }
%struct.timeval = type { i32, i64 }
%struct.TYPE_5__ = type { i32 }
@YPPROG = global i32 0
@YPPROC_NULL = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [23 x i8] c"%s not running ypserv.\00"
@YPVERS = global i32 0
@RPC_ANYSOCK = global i32 0
@YPBINDPROG = global i32 0
@YPBINDVERS = global i32 0
@.str.1 = [26 x i8] c"Can't yp_bind: Reason: %s\00"
@YPERR_YPBIND = global i32 0
@YPBINDPROC_SETDOM = global i32 0
@xdr_ypbind_setdom = global i32 0
@xdr_void = global i32 0
@.str.2 = [43 x i8] c"Cannot ypset for domain %s on host %s: %s.\00"
define i32 @bind_tohost(%struct.sockaddr_in* %0, i8* %1, i8* %2) {
%4 = alloca %struct.ypbind_setdom
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = bitcast %struct.ypbind_setdom* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = load i32, i32* @YPPROG
%11 = load i32, i32* @YPPROC_NULL
%12 = load i32, i32* @IPPROTO_UDP
%13 = tail call i32 @getrpcport(i8* %2, i32 %10, i32 %11, i32 %12)
%14 = tail call i32 @htons(i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %18
18: ; preds = %16, %3
%19 = call i32 @memset(%struct.ypbind_setdom* %4, i32 0, i32 16)
%20 = getelementptr inbounds %struct.ypbind_setdom, %struct.ypbind_setdom* %4, i64 0, i32 3
%21 = call i32 @gethostaddr(i8* %2, i32* %20)
%22 = getelementptr inbounds %struct.ypbind_setdom, %struct.ypbind_setdom* %4, i64 0, i32 2
%23 = load i32, i32* %22
%24 = call i32 @strlcpy(i32 %23, i8* %1, i32 4)
%25 = getelementptr inbounds %struct.ypbind_setdom, %struct.ypbind_setdom* %4, i64 0, i32 0
store i32 %14, i32* %25
%26 = load i32, i32* @YPVERS
%27 = getelementptr inbounds %struct.ypbind_setdom, %struct.ypbind_setdom* %4, i64 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 15, i32* %28
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 0, i64* %29
%30 = load i32, i32* @RPC_ANYSOCK
store i32 %30, i32* %6
%31 = load i32, i32* @YPBINDPROG
%32 = load i32, i32* @YPBINDVERS
%33 = call %struct.TYPE_5__* @clntudp_create(%struct.sockaddr_in* %0, i32 %31, i32 %32, i32 15, i64 0, i32* %6)
%34 = icmp eq %struct.TYPE_5__* %33, null
br i1 %34, label %35, label %42
35: ; preds = %18
%36 = load i32, i32* @YPERR_YPBIND
%37 = call i32 @yperr_string(i32 %36)
%38 = sext i32 %37 to i64
%39 = inttoptr i64 %38 to i8*
%40 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @YPERR_YPBIND
br label %57
42: ; preds = %18
%43 = call i32 (...) @authunix_create_default()
%44 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %33, i64 0, i32 0
store i32 %43, i32* %44
%45 = load i32, i32* @YPBINDPROC_SETDOM
%46 = load i32, i32* @xdr_ypbind_setdom
%47 = load i32, i32* @xdr_void
%48 = call i32 @clnt_call(%struct.TYPE_5__* %33, i32 %45, i32 %46, %struct.ypbind_setdom* %4, i32 %47, i32* null, %struct.timeval* byval(%struct.timeval) align 8 %5)
%49 = icmp eq i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %42
%51 = call i32 @clnt_sperrno(i32 %48)
%52 = call i32 (i8*, i8*, ...) @warnx(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2, i32 %51)
%53 = call i32 @clnt_destroy(%struct.TYPE_5__* %33)
%54 = load i32, i32* @YPERR_YPBIND
br label %57
55: ; preds = %42
%56 = call i32 @clnt_destroy(%struct.TYPE_5__* %33)
br label %57
57: ; preds = %55, %50, %35
%58 = phi i32 [ %41, %35 ], [ %54, %50 ], [ 0, %55 ]
ret i32 %58
}