#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 /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ dg_cli(int /*<<< orphan*/, int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  if (argc != 2) {
    printf("Usage: %s <IP/HOSTNAME>\n", argv[0]);
    exit(-1);
  }
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    exit(-1);
  }
  server = gethostbyname(argv[1]);
  if (NULL == server) {
    perror("gethostbyname");
    exit(-1);
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&(serv_addr.sin_addr.s_addr),
        server->h_length);
  serv_addr.sin_port = htons(10001);
  dg_cli(stdin, sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  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)
cmpl   $0x2,-0x8(%rbp)
je     11cd <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1208 <main+0x78>
lea    0xe20(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    123b <main+0xab>
lea    0xdf4(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   1060 <bcopy@plt>
mov    $0x2711,%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdx
mov    $0xc,%ecx
call   1090 <dg_cli@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11c9 <main+0x39>
mov    0x2e3f(%rip),%r15
mov    (%r15),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
jns    11e2 <main+0x52>
lea    0xe52(%rip),%rdi
jmp    11f9 <main+0x69>
mov    (%rbx),%rsi
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
jne    1208 <main+0x78>
lea    0xe27(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rbx),%rsi
lea    0xc(%rsp),%rdi
mov    (%rbx),%edx
call   1060 <memmove@plt>
mov    $0x2711,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%esi
mov    %r14,%rdx
mov    $0xc,%ecx
call   1090 <dg_cli@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"Usage: %s <IP/HOSTNAME>\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.hostent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call %struct.hostent* @gethostbyname(i8* %28)
store %struct.hostent* %29, %struct.hostent** %8
%30 = load %struct.hostent*, %struct.hostent** %8
%31 = icmp eq %struct.hostent* null, %30
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %25
%36 = bitcast %struct.sockaddr_in* %7 to i8*
%37 = call i32 @bzero(i8* %36, i32 12)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %38, i32* %39
%40 = load %struct.hostent*, %struct.hostent** %8
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %40, i32 0, i32 1
%42 = load i64, i64* %41
%43 = inttoptr i64 %42 to i8*
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%45 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %44, i32 0, i32 0
%46 = bitcast i32* %45 to i8*
%47 = load %struct.hostent*, %struct.hostent** %8
%48 = getelementptr inbounds %struct.hostent, %struct.hostent* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @bcopy(i8* %43, i8* %46, i32 %49)
%51 = call i32 @htons(i32 10001)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %51, i32* %52
%53 = load i32, i32* @stdin
%54 = load i32, i32* %6
%55 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%56 = call i32 @dg_cli(i32 %53, i32 %54, %struct.sockaddr* %55, i32 12)
%57 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"Usage: %s <IP/HOSTNAME>\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %10
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call %struct.hostent* @gethostbyname(i8* %20)
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 -1)
unreachable
26: ; preds = %18
%27 = call i32 @bzero(i8* %4, i32 12)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 1
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to i8*
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%34 = bitcast i32* %33 to i8*
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 0
%36 = load i32, i32* %35
%37 = tail call i32 @htons(i32 10001)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %37, i32* %38
%39 = load i32, i32* @stdin
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = call i32 @dg_cli(i32 %39, i32 %13, %struct.sockaddr* %40, i32 12)
%42 = call i32 @exit(i32 0)
unreachable
}