#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, TYPE_1__ *, int);
scalar_t__ bind_tohost(struct sockaddr_in *, char *, char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ errx(int, char *, char *);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ inet_aton(char *, TYPE_1__ *);
char *optarg;
int optind;
int /*<<< orphan*/ usage();
int /*<<< orphan*/ yp_get_default_domain(char **);
int main(int argc, char *argv[]) {
  struct sockaddr_in sin;
  struct hostent *hent;
  char *domainname;
  int c;
  yp_get_default_domain(&domainname);
  bzero(&sin, sizeof sin);
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  while ((c = getopt(argc, argv, "h:d:")) != -1)
    switch (c) {
    case 'd':
      domainname = optarg;
      break;
    case 'h':
      if (inet_aton(optarg, &sin.sin_addr) == 0) {
        hent = gethostbyname(optarg);
        if (hent == NULL)
          errx(1, "host %s unknown\n", optarg);
        bcopy(hent->h_addr, &sin.sin_addr, sizeof(sin.sin_addr));
      }
      break;
    default:
      usage();
    }
  if (optind + 1 != argc)
    usage();
  if (bind_tohost(&sin, domainname, argv[optind]))
    exit(1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
call   1080 <yp_get_default_domain@plt>
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdf8(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     12cb <main+0x11b>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x64,%eax
je     123e <main+0x8e>
jmp    122d <main+0x7d>
mov    -0x30(%rbp),%eax
sub    $0x68,%eax
je     1251 <main+0xa1>
jmp    12bf <main+0x10f>
mov    0x2db3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12c6 <main+0x116>
mov    0x2da0(%rip),%rax
mov    (%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <inet_aton@plt>
cmp    $0x0,%eax
jne    12ba <main+0x10a>
mov    0x2d84(%rip),%rax
mov    (%rax),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12a6 <main+0xf6>
mov    0x2d66(%rip),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
lea    0xd64(%rip),%rsi
call   1040 <errx@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1090 <bcopy@plt>
jmp    12c6 <main+0x116>
mov    $0x0,%al
call   10a0 <usage@plt>
jmp    11fa <main+0x4a>
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
je     12e7 <main+0x137>
mov    $0x0,%al
call   10a0 <usage@plt>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x2ce2(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    -0x18(%rbp),%rdi
call   1030 <bind_tohost@plt>
cmp    $0x0,%rax
je     131a <main+0x16a>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    %edi,%ebp
lea    0x10(%rsp),%rdi
call   1080 <yp_get_default_domain@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0xdfb(%rip),%r15
mov    0x2dec(%rip),%r12
jmp    1220 <main+0x70>
mov    (%rbx),%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1090 <bcopy@plt>
nopl   (%rax)
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r15,%rdx
call   10c0 <getopt@plt>
cmp    $0x64,%eax
je     1250 <main+0xa0>
cmp    $0x68,%eax
je     1260 <main+0xb0>
cmp    $0xffffffff,%eax
je     129b <main+0xeb>
xor    %eax,%eax
call   10a0 <usage@plt>
jmp    1220 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%rax
mov    %rax,0x10(%rsp)
jmp    1220 <main+0x70>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%rdi
mov    %r14,%rsi
call   1070 <inet_aton@plt>
test   %eax,%eax
jne    1220 <main+0x70>
mov    (%r12),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    120e <main+0x5e>
mov    (%r12),%rdx
mov    $0x1,%edi
lea    0xd74(%rip),%rsi
call   1040 <errx@plt>
jmp    120e <main+0x5e>
mov    0x2d36(%rip),%rbx
mov    (%rbx),%eax
lea    0x1(%rax),%ecx
cmp    %ebp,%ecx
je     12b4 <main+0x104>
xor    %eax,%eax
call   10a0 <usage@plt>
mov    (%rbx),%eax
mov    0x10(%rsp),%rsi
cltq
mov    0x0(%r13,%rax,8),%rdx
lea    0x8(%rsp),%rdi
call   1030 <bind_tohost@plt>
test   %rax,%rax
jne    12d6 <main+0x126>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_3__, i32 }
%struct.TYPE_3__ = type { i32 }
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
@.str = [5 x i8] c"h:d:\00"
@optarg = global i8* null
@.str.1 = [17 x i8] c"host %s unknown\0A\00"
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @yp_get_default_domain(i8** %8)
%11 = call i32 @bzero(%struct.sockaddr_in* %6, i32 8)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_LOOPBACK
%15 = call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
store i32 %15, i32* %17
br label %18
18: ; preds = %49, %2
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @getopt(i32 %19, i8** %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %21, i32* %9
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %50
23: ; preds = %18
%24 = load i32, i32* %9
switch i32 %24, label %47 [
i32 100, label %25
i32 104, label %27
]
25: ; preds = %23
%26 = load i8*, i8** @optarg
store i8* %26, i8** %8
br label %49
27: ; preds = %23
%28 = load i8*, i8** @optarg
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%30 = call i32 @inet_aton(i8* %28, %struct.TYPE_3__* %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %46
32: ; preds = %27
%33 = load i8*, i8** @optarg
%34 = call %struct.hostent* @gethostbyname(i8* %33)
store %struct.hostent* %34, %struct.hostent** %7
%35 = load %struct.hostent*, %struct.hostent** %7
%36 = icmp eq %struct.hostent* %35, null
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i8*, i8** @optarg
%39 = call i32 @errx(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %32
%41 = load %struct.hostent*, %struct.hostent** %7
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%45 = call i32 @bcopy(i32 %43, %struct.TYPE_3__* %44, i32 4)
br label %46
46: ; preds = %40, %27
br label %49
47: ; preds = %23
%48 = call i32 (...) @usage()
br label %49
49: ; preds = %47, %46, %25
br label %18
50: ; preds = %18
%51 = load i32, i32* @optind
%52 = add nsw i32 %51, 1
%53 = load i32, i32* %4
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = call i32 (...) @usage()
br label %57
57: ; preds = %55, %50
%58 = load i8*, i8** %8
%59 = load i8**, i8*** %5
%60 = load i32, i32* @optind
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = call i64 @bind_tohost(%struct.sockaddr_in* %6, i8* %58, i8* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %57
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %57
%69 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_3__, i32 }
%struct.TYPE_3__ = type { i32 }
%struct.hostent = type { i32 }
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
@.str = [5 x i8] c"h:d:\00"
@optarg = global i8* null
@.str.1 = [17 x i8] c"host %s unknown\0A\00"
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i8*
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = call i32 @yp_get_default_domain(i8** %4)
%8 = call i32 @bzero(%struct.sockaddr_in* %3, i32 8)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* @INADDR_LOOPBACK
%12 = call i32 @htonl(i32 %11)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %12, i32* %14
br label %15
15: ; preds = %23, %2
%16 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %16, label %35 [
i32 -1, label %37
i32 100, label %17
i32 104, label %19
]
17: ; preds = %15
%18 = load i8*, i8** @optarg
store i8* %18, i8** %4
br label %23
19: ; preds = %15
%20 = load i8*, i8** @optarg
%21 = call i32 @inet_aton(i8* %20, %struct.TYPE_3__* %13)
%22 = icmp eq i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %19, %31, %35, %17
br label %15
24: ; preds = %19
%25 = load i8*, i8** @optarg
%26 = call %struct.hostent* @gethostbyname(i8* %25)
%27 = icmp eq %struct.hostent* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i8*, i8** @optarg
%30 = call i32 @errx(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %24
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i64 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @bcopy(i32 %33, %struct.TYPE_3__* %13, i32 4)
br label %23
35: ; preds = %15
%36 = call i32 (...) @usage()
br label %23
37: ; preds = %15
%38 = load i32, i32* @optind
%39 = add nsw i32 %38, 1
%40 = icmp eq i32 %39, %0
br i1 %40, label %44, label %41
41: ; preds = %37
%42 = call i32 (...) @usage()
%43 = load i32, i32* @optind
br label %44
44: ; preds = %41, %37
%45 = phi i32 [ %43, %41 ], [ %38, %37 ]
%46 = load i8*, i8** %4
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = call i64 @bind_tohost(%struct.sockaddr_in* %3, i8* %46, i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %44
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %44
%55 = call i32 @exit(i32 0)
unreachable
}