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

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

/* 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 htonl(int /*<<< orphan*/);
int inet_addr(char *);
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 ((sin.sin_addr.s_addr = inet_addr(optarg)) == -1) {
        hent = gethostbyname(optarg);
        if (hent == NULL)
          errx(1, "host %s unknown", optarg);
        bcopy(hent->h_addr_list[0], &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     12cd <main+0x11d>
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    12c1 <main+0x111>
mov    0x2db3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12c8 <main+0x118>
mov    0x2da0(%rip),%rax
mov    (%rax),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    12bc <main+0x10c>
mov    0x2d85(%rip),%rax
mov    (%rax),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12a5 <main+0xf5>
mov    0x2d67(%rip),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
lea    0xd65(%rip),%rsi
call   1040 <errx@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1090 <bcopy@plt>
jmp    12c8 <main+0x118>
mov    $0x0,%al
call   10a0 <usage@plt>
jmp    11fa <main+0x4a>
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
je     12e9 <main+0x139>
mov    $0x0,%al
call   10a0 <usage@plt>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x2ce0(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    -0x18(%rbp),%rdi
call   1030 <bind_tohost@plt>
cmp    $0x0,%rax
je     131c <main+0x16c>
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),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1090 <bcopy@plt>
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     129d <main+0xed>
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
call   1060 <inet_addr@plt>
mov    %eax,0x8(%rsp)
cmp    $0xffffffff,%eax
jne    1220 <main+0x70>
mov    (%r12),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    120e <main+0x5e>
mov    (%r12),%rdx
mov    $0x1,%edi
lea    0xd72(%rip),%rsi
call   1040 <errx@plt>
jmp    120e <main+0x5e>
mov    0x2d34(%rip),%rbx
mov    (%rbx),%eax
lea    0x1(%rax),%ecx
cmp    %ebp,%ecx
je     12b6 <main+0x106>
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    12d8 <main+0x128>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = 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 = [16 x i8] c"host %s unknown\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_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
br label %18
18: ; preds = %52, %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 %53
23: ; preds = %18
%24 = load i32, i32* %9
switch i32 %24, label %50 [
i32 100, label %25
i32 104, label %27
]
25: ; preds = %23
%26 = load i8*, i8** @optarg
store i8* %26, i8** %8
br label %52
27: ; preds = %23
%28 = load i8*, i8** @optarg
%29 = call i32 @inet_addr(i8* %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = icmp eq i32 %29, -1
br i1 %32, label %33, label %49
33: ; preds = %27
%34 = load i8*, i8** @optarg
%35 = call %struct.hostent* @gethostbyname(i8* %34)
store %struct.hostent* %35, %struct.hostent** %7
%36 = load %struct.hostent*, %struct.hostent** %7
%37 = icmp eq %struct.hostent* %36, null
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i8*, i8** @optarg
%40 = call i32 @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %33
%42 = load %struct.hostent*, %struct.hostent** %7
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 0
%44 = load i32*, i32** %43
%45 = getelementptr inbounds i32, i32* %44, i64 0
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%48 = call i32 @bcopy(i32 %46, %struct.TYPE_2__* %47, i32 4)
br label %49
49: ; preds = %41, %27
br label %52
50: ; preds = %23
%51 = call i32 (...) @usage()
br label %52
52: ; preds = %50, %49, %25
br label %18
53: ; preds = %18
%54 = load i32, i32* @optind
%55 = add nsw i32 %54, 1
%56 = load i32, i32* %4
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 (...) @usage()
br label %60
60: ; preds = %58, %53
%61 = load i8*, i8** %8
%62 = load i8**, i8*** %5
%63 = load i32, i32* @optind
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
%66 = load i8*, i8** %65
%67 = call i64 @bind_tohost(%struct.sockaddr_in* %6, i8* %61, i8* %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %60
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %60
%72 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = 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 = [16 x i8] c"host %s unknown\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 %36 [
i32 -1, label %38
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_addr(i8* %20)
store i32 %21, i32* %14
%22 = icmp eq i32 %21, -1
br i1 %22, label %24, label %23
23: ; preds = %19, %31, %36, %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 ([16 x i8], [16 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 = load i32, i32* %33
%35 = call i32 @bcopy(i32 %34, %struct.TYPE_2__* %13, i32 4)
br label %23
36: ; preds = %15
%37 = call i32 (...) @usage()
br label %23
38: ; preds = %15
%39 = load i32, i32* @optind
%40 = add nsw i32 %39, 1
%41 = icmp eq i32 %40, %0
br i1 %41, label %45, label %42
42: ; preds = %38
%43 = call i32 (...) @usage()
%44 = load i32, i32* @optind
br label %45
45: ; preds = %42, %38
%46 = phi i32 [ %44, %42 ], [ %39, %38 ]
%47 = load i8*, i8** %4
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8*, i8** %1, i64 %48
%50 = load i8*, i8** %49
%51 = call i64 @bind_tohost(%struct.sockaddr_in* %3, i8* %47, i8* %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %45
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %45
%56 = call i32 @exit(i32 0)
unreachable
}