#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 {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
unsigned short atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int getopt(int, char **, char *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned short);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int sockfd;
  int option_char = 0;
  char *hostname = "localhost";
  unsigned short portno = 8888;
  char port_char[15];
  char *message = "Hello World!";
  char message_buff[16];
  int num_bytes_received;
  char ip_info[INET6_ADDRSTRLEN];
  struct addrinfo hints, *servinfo;
  int res;
  while ((option_char = getopt(argc, argv, "s:p:m:h")) != -1) {
    switch (option_char) {
    case 's':
      hostname = optarg;
      break;
    case 'p':
      portno = atoi(optarg);
      break;
    case 'm':
      message = optarg;
      break;
    case 'h':
      fprintf(stdout, "%s",
              "usage:\n"
              "  echoclient [options]\n"
              "options:\n"
              "  -s                  Server (Default: localhost)\n"
              "  -p                  Port (Default: 8888)\n"
              "  -m                  Message to send to server (Default: "
              "\"Hello World!\"\n"
              "  -h                  Show this help message\n");
      exit(0);
      break;
    default:
      fprintf(stderr, "%s",
              "usage:\n"
              "  echoclient [options]\n"
              "options:\n"
              "  -s                  Server (Default: localhost)\n"
              "  -p                  Port (Default: 8888)\n"
              "  -m                  Message to send to server (Default: "
              "\"Hello World!\"\n"
              "  -h                  Show this help message\n");
      exit(1);
    }
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  snprintf(port_char, sizeof port_char, "%d", portno);
  if ((res = getaddrinfo(hostname, port_char, &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(res));
    return 1;
  }
  printf("getaddrinfo is executed\n");
  if ((sockfd = socket(servinfo->ai_family, servinfo->ai_socktype,
                       servinfo->ai_protocol)) == -1) {
    perror("client: socket");
    exit(1);
  }
  printf("socket is created\n");
  if (connect(sockfd, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
    close(sockfd);
    perror("client: connect");
    exit(1);
  }
  inet_ntop(servinfo->ai_family,
            get_in_addr((struct sockaddr *)servinfo->ai_addr), ip_info,
            sizeof ip_info);
  printf("client: connecting to %s\n", ip_info);
  if (send(sockfd, message, 16, 0) == -1) {
    perror("send");
    exit(1);
  }
  if ((num_bytes_received = recv(sockfd, message_buff, 16 - 1, 0)) == -1) {
    perror("recv");
    exit(1);
  }
  message_buff[num_bytes_received] = '\0';
  printf("client: i've go this message back from server: %s\n", message_buff);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xdf9(%rip),%rax
mov    %rax,-0x20(%rbp)
movw   $0x22b8,-0x22(%rbp)
lea    0xdf2(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xa0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdb7(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     135c <main+0x14c>
mov    -0x18(%rbp),%eax
add    $0xffffff98,%eax
mov    %eax,%ecx
mov    %rcx,-0xa8(%rbp)
sub    $0xb,%eax
ja     1331 <main+0x121>
mov    -0xa8(%rbp),%rax
lea    0xd39(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d21(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1357 <main+0x147>
mov    0x2d0e(%rip),%rax
mov    (%rax),%rdi
call   10f0 <atoi@plt>
mov    %ax,-0x22(%rbp)
jmp    1357 <main+0x147>
mov    0x2cf6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1357 <main+0x147>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
lea    0xd31(%rip),%rsi
lea    0xd2d(%rip),%rdx
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
lea    0xd0e(%rip),%rsi
lea    0xd0a(%rip),%rdx
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1282 <main+0x72>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10a0 <memset@plt>
mov    0x2c65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x31(%rbp),%rdi
mov    $0xf,%esi
lea    0xdb9(%rip),%rdx
movzwl -0x22(%rbp),%ecx
call   1080 <snprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x31(%rbp),%rsi
lea    -0x80(%rbp),%rdx
lea    -0x88(%rbp),%rcx
call   1120 <getaddrinfo@plt>
mov    %eax,-0x8c(%rbp)
cmp    $0x0,%eax
je     1409 <main+0x1f9>
mov    0x2bfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x8c(%rbp),%edi
call   1090 <gai_strerror@plt>
mov    -0xac(%rbp),%edi
mov    %rax,%rdx
lea    0xd62(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1591 <main+0x381>
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x88(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x88(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x88(%rbp),%rax
mov    0x10(%rax),%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    145c <main+0x24c>
lea    0xd2d(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xd26(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x88(%rbp),%rax
mov    (%rax),%rsi
mov    -0x88(%rbp),%rax
mov    0xc(%rax),%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
jne    14ad <main+0x29d>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
lea    0xcfe(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x88(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0xb0(%rbp)
mov    -0x88(%rbp),%rax
mov    (%rax),%rdi
call   1050 <get_in_addr@plt>
mov    -0xb0(%rbp),%edi
mov    -0x98(%rbp),%rdx
mov    %eax,%esi
mov    -0xa0(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x98(%rbp),%rsi
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xffffffff,%eax
jne    1530 <main+0x320>
lea    0xca5(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0xf,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x54(%rbp)
cmp    $0xffffffff,%eax
jne    1565 <main+0x355>
lea    0xc75(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movslq -0x54(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rsi
lea    0xc57(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsp,-0x40(%rbp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x50(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
lea    0xd9c(%rip),%r13
movw   $0x22b8,-0x2a(%rbp)
lea    0xd99(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xd9b(%rip),%r12
mov    0x2d75(%rip),%r15
jmp    1293 <main+0x73>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%r13
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10f0 <getopt@plt>
cmp    $0x73,%eax
je     1290 <main+0x70>
cmp    $0x6c,%eax
jle    12d0 <main+0xb0>
cmp    $0x6d,%eax
je     12c7 <main+0xa7>
cmp    $0x70,%eax
jne    147f <main+0x25f>
mov    (%r15),%rdi
call   1100 <atoi@plt>
mov    %ax,-0x2a(%rbp)
jmp    1293 <main+0x73>
mov    (%r15),%rax
mov    %rax,-0x48(%rbp)
jmp    1293 <main+0x73>
cmp    $0xffffffff,%eax
jne    1457 <main+0x237>
lea    -0x88(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10b0 <memset@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    0x2cbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
movzwl -0x2a(%rbp),%ecx
lea    0xe0b(%rip),%rdx
lea    -0x97(%rbp),%rbx
mov    %rbx,%rdi
mov    $0xf,%esi
call   1090 <snprintf@plt>
lea    -0x38(%rbp),%rcx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1130 <getaddrinfo@plt>
test   %eax,%eax
je     1367 <main+0x147>
mov    0x2c85(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   10a0 <gai_strerror@plt>
lea    0xdcd(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10d0 <fprintf@plt>
mov    $0x1,%ebx
jmp    143f <main+0x21f>
lea    0xe39(%rip),%rdi
call   1060 <puts@plt>
mov    -0x38(%rbp),%rax
mov    0x14(%rax),%esi
mov    0x8(%rax),%edi
mov    0x10(%rax),%edx
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
je     14a5 <main+0x285>
mov    %eax,%r14d
lea    0xe27(%rip),%rdi
call   1060 <puts@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
mov    0xc(%rax),%edx
mov    %r14d,%edi
call   1120 <connect@plt>
cmp    $0xffffffff,%eax
je     14ae <main+0x28e>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%ebx
mov    (%rax),%rdi
call   1050 <get_in_addr@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    -0x58(%rbp),%rbx
mov    %rbx,%rdx
mov    -0x50(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xd6e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14d,%edi
mov    -0x48(%rbp),%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
je     14bf <main+0x29f>
lea    -0x70(%rbp),%rsi
xor    %ebx,%ebx
mov    %r14d,%edi
mov    $0xf,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
je     14c8 <main+0x2a8>
cltq
movb   $0x0,-0x70(%rbp,%rax,1)
lea    0xd40(%rip),%rdi
lea    -0x70(%rbp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x68,%eax
jne    147f <main+0x25f>
mov    0x2b55(%rip),%rax
mov    (%rax),%edi
lea    0xbb3(%rip),%rsi
lea    0xbaf(%rip),%rdx
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
lea    0xb90(%rip),%rsi
lea    0xb8c(%rip),%rdx
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xc85(%rip),%rdi
jmp    14cf <main+0x2af>
mov    %r14d,%edi
call   10c0 <close@plt>
lea    0xc83(%rip),%rdi
jmp    14cf <main+0x2af>
lea    0xca4(%rip),%rdi
jmp    14cf <main+0x2af>
lea    0xca0(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"localhost\00"
@.str.1 = [13 x i8] c"Hello World!\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.2 = [8 x i8] c"s:p:m:h\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [251 x i8] c"usage:\0A echoclient [options]\0Aoptions:\0A -s Server (Default: localhost)\0A -p Port (Default: 8888)\0A -m Message to send to server (Default: \22Hello World!\22\0A -h Show this help message\0A\00"
@stderr = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.7 = [25 x i8] c"getaddrinfo is executed\0A\00"
@.str.8 = [15 x i8] c"client: socket\00"
@.str.9 = [19 x i8] c"socket is created\0A\00"
@.str.10 = [16 x i8] c"client: connect\00"
@.str.11 = [26 x i8] c"client: connecting to %s\0A\00"
@.str.12 = [5 x i8] c"send\00"
@.str.13 = [5 x i8] c"recv\00"
@.str.14 = [51 x i8] c"client: i've go this message back from server: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i16
%10 = alloca [15 x i8]
%11 = alloca i8*
%12 = alloca [16 x i8]
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca %struct.addrinfo
%17 = alloca %struct.addrinfo*
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %8
store i16 8888, i16* %9
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %11
%20 = load i32, i32* @INET6_ADDRSTRLEN
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %14
%23 = alloca i8, i64 %21
store i64 %21, i64* %15
br label %24
24: ; preds = %46, %2
%25 = load i32, i32* %4
%26 = load i8**, i8*** %5
%27 = call i32 @getopt(i32 %25, i8** %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 %27, i32* %7
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %47
29: ; preds = %24
%30 = load i32, i32* %7
switch i32 %30, label %42 [
i32 115, label %31
i32 112, label %33
i32 109, label %36
i32 104, label %38
]
31: ; preds = %29
%32 = load i8*, i8** @optarg
store i8* %32, i8** %8
br label %46
33: ; preds = %29
%34 = load i8*, i8** @optarg
%35 = call zeroext i16 @atoi(i8* %34)
store i16 %35, i16* %9
br label %46
36: ; preds = %29
%37 = load i8*, i8** @optarg
store i8* %37, i8** %11
br label %46
38: ; preds = %29
%39 = load i32, i32* @stdout
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %29
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %36, %33, %31
br label %24
47: ; preds = %24
%48 = call i32 @memset(%struct.addrinfo* %16, i32 0, i32 24)
%49 = load i32, i32* @AF_INET
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %16, i32 0, i32 1
store i32 %49, i32* %50
%51 = load i32, i32* @SOCK_STREAM
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %16, i32 0, i32 4
store i32 %51, i32* %52
%53 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%54 = load i16, i16* %9
%55 = call i32 @snprintf(i8* %53, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i16 zeroext %54)
%56 = load i8*, i8** %8
%57 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%58 = call i32 @getaddrinfo(i8* %56, i8* %57, %struct.addrinfo* %16, %struct.addrinfo** %17)
store i32 %58, i32* %18
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %47
%61 = load i32, i32* @stderr
%62 = load i32, i32* %18
%63 = call i8* @gai_strerror(i32 %62)
%64 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %63)
store i32 1, i32* %3
store i32 1, i32* %19
br label %130
65: ; preds = %47
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%67 = load %struct.addrinfo*, %struct.addrinfo** %17
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %67, i32 0, i32 1
%69 = load i32, i32* %68
%70 = load %struct.addrinfo*, %struct.addrinfo** %17
%71 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %70, i32 0, i32 4
%72 = load i32, i32* %71
%73 = load %struct.addrinfo*, %struct.addrinfo** %17
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i32 0, i32 3
%75 = load i32, i32* %74
%76 = call i32 @socket(i32 %69, i32 %72, i32 %75)
store i32 %76, i32* %6
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %81
78: ; preds = %65
%79 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %65
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%83 = load i32, i32* %6
%84 = load %struct.addrinfo*, %struct.addrinfo** %17
%85 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %84, i32 0, i32 0
%86 = load i64, i64* %85
%87 = load %struct.addrinfo*, %struct.addrinfo** %17
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %87, i32 0, i32 2
%89 = load i32, i32* %88
%90 = call i32 @connect(i32 %83, i64 %86, i32 %89)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %97
92: ; preds = %81
%93 = load i32, i32* %6
%94 = call i32 @close(i32 %93)
%95 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %81
%98 = load %struct.addrinfo*, %struct.addrinfo** %17
%99 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %98, i32 0, i32 1
%100 = load i32, i32* %99
%101 = load %struct.addrinfo*, %struct.addrinfo** %17
%102 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %101, i32 0, i32 0
%103 = load i64, i64* %102
%104 = inttoptr i64 %103 to %struct.sockaddr*
%105 = call i32 @get_in_addr(%struct.sockaddr* %104)
%106 = trunc i64 %21 to i32
%107 = call i32 @inet_ntop(i32 %100, i32 %105, i8* %23, i32 %106)
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %23)
%109 = load i32, i32* %6
%110 = load i8*, i8** %11
%111 = call i32 @send(i32 %109, i8* %110, i32 16, i32 0)
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %116
113: ; preds = %97
%114 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%115 = call i32 @exit(i32 1)
unreachable
116: ; preds = %97
%117 = load i32, i32* %6
%118 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%119 = call i32 @recv(i32 %117, i8* %118, i32 15, i32 0)
store i32 %119, i32* %13
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %124
121: ; preds = %116
%122 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%123 = call i32 @exit(i32 1)
unreachable
124: ; preds = %116
%125 = load i32, i32* %13
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 %126
store i8 0, i8* %127
%128 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.14, i64 0, i64 0), i8* %128)
store i32 0, i32* %3
store i32 1, i32* %19
br label %130
130: ; preds = %124, %60
%131 = load i8*, i8** %14
%132 = load i32, i32* %3
ret i32 %132
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"localhost\00"
@.str.1 = [13 x i8] c"Hello World!\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.2 = [8 x i8] c"s:p:m:h\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [251 x i8] c"usage:\0A echoclient [options]\0Aoptions:\0A -s Server (Default: localhost)\0A -p Port (Default: 8888)\0A -m Message to send to server (Default: \22Hello World!\22\0A -h Show this help message\0A\00"
@stderr = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.8 = [15 x i8] c"client: socket\00"
@.str.10 = [16 x i8] c"client: connect\00"
@.str.11 = [26 x i8] c"client: connecting to %s\0A\00"
@.str.12 = [5 x i8] c"send\00"
@.str.13 = [5 x i8] c"recv\00"
@.str.14 = [51 x i8] c"client: i've go this message back from server: %s\0A\00"
@str = [24 x i8] c"getaddrinfo is executed\00"
@str.15 = [18 x i8] c"socket is created\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [15 x i8]
%4 = alloca [16 x i8]
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @INET6_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = bitcast %struct.addrinfo* %5 to i8*
%14 = bitcast %struct.addrinfo** %6 to i8*
br label %15
15: ; preds = %30, %2
%16 = phi i8* [ %31, %30 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %2 ]
%17 = phi i16 [ %20, %30 ], [ 8888, %2 ]
%18 = phi i8* [ %23, %30 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
br label %19
19: ; preds = %15, %27
%20 = phi i16 [ %17, %15 ], [ %29, %27 ]
%21 = phi i8* [ %18, %15 ], [ %23, %27 ]
br label %22
22: ; preds = %19, %25
%23 = phi i8* [ %26, %25 ], [ %21, %19 ]
%24 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
switch i32 %24, label %36 [
i32 -1, label %40
i32 115, label %25
i32 112, label %27
i32 109, label %30
i32 104, label %32
]
25: ; preds = %22
%26 = load i8*, i8** @optarg
br label %22
27: ; preds = %22
%28 = load i8*, i8** @optarg
%29 = tail call zeroext i16 @atoi(i8* %28)
br label %19
30: ; preds = %22
%31 = load i8*, i8** @optarg
br label %15
32: ; preds = %22
%33 = load i32, i32* @stdout
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str.4, i64 0, i64 0))
%35 = tail call i32 @exit(i32 0)
unreachable
36: ; preds = %22
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([251 x i8], [251 x i8]* @.str.4, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %22
%41 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 24)
%42 = load i32, i32* @AF_INET
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 1
store i32 %42, i32* %43
%44 = load i32, i32* @SOCK_STREAM
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %44, i32* %45
%46 = call i32 @snprintf(i8* %7, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i16 zeroext %20)
%47 = call i32 @getaddrinfo(i8* %23, i8* %7, %struct.addrinfo* %5, %struct.addrinfo** %6)
%48 = icmp eq i32 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %40
%50 = load i32, i32* @stderr
%51 = call i8* @gai_strerror(i32 %47)
%52 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %51)
br label %105
53: ; preds = %40
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%55 = load %struct.addrinfo*, %struct.addrinfo** %6
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i64 0, i32 1
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i64 0, i32 4
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i64 0, i32 3
%61 = load i32, i32* %60
%62 = call i32 @socket(i32 %57, i32 %59, i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %67
64: ; preds = %53
%65 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %53
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.15, i64 0, i64 0))
%69 = load %struct.addrinfo*, %struct.addrinfo** %6
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i64 0, i32 0
%71 = load i64, i64* %70
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i64 0, i32 2
%73 = load i32, i32* %72
%74 = call i32 @connect(i32 %62, i64 %71, i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %80
76: ; preds = %67
%77 = call i32 @close(i32 %62)
%78 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %67
%81 = load %struct.addrinfo*, %struct.addrinfo** %6
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %81, i64 0, i32 1
%83 = load i32, i32* %82
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %81, i64 0, i32 0
%85 = load i64, i64* %84
%86 = inttoptr i64 %85 to %struct.sockaddr*
%87 = call i32 @get_in_addr(%struct.sockaddr* %86)
%88 = call i32 @inet_ntop(i32 %83, i32 %87, i8* %12, i32 %9)
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %12)
%90 = call i32 @send(i32 %62, i8* %16, i32 16, i32 0)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %95
92: ; preds = %80
%93 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %80
%96 = call i32 @recv(i32 %62, i8* %8, i32 15, i32 0)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %95
%102 = sext i32 %96 to i64
%103 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %102
store i8 0, i8* %103
%104 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.14, i64 0, i64 0), i8* %8)
br label %105
105: ; preds = %101, %49
%106 = phi i32 [ 1, %49 ], [ 0, %101 ]
ret i32 %106
}