#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ serverAddress;
typedef int in_port_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int BUFSIZ;
int /*<<< orphan*/ DieWithSystemMessage(char *);
int /*<<< orphan*/ DieWithUserMessage(char *, char *);
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_DEBUG;
int atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
size_t recv(int, char *, int, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
size_t strlen(char *);
size_t write(int, char *, size_t);
int main(int argc, char *argv[]) {
  int result;
  if (argc < 3 || argc > 4)
    DieWithUserMessage("Parameter(s)",
                       "<Server Address> <Echo Word> [<Server Port>]");
  char *serverIP = argv[1];
  char *echoString = argv[2];
  in_port_t serverPort = (argc == 4) ? atoi(argv[3]) : 7;
  int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock < 0)
    DieWithSystemMessage("socket() failed");
  int debug = 1;
  result = setsockopt(sock, SOL_SOCKET, SO_DEBUG, (void *)&debug,
                      sizeof((void *)&debug));
  if (result < 0)
    DieWithSystemMessage("setsockopt() failed");
  struct sockaddr_in serverAddress;
  memset(&serverAddress, 0, sizeof(struct sockaddr_in));
  serverAddress.sin_family = AF_INET;
  serverAddress.sin_port = htons(serverPort);
  result = inet_pton(AF_INET, serverIP, &serverAddress.sin_addr.s_addr);
  if (result == 0)
    DieWithUserMessage("inet_pton() failed", "invalid address string");
  else if (result < 0)
    DieWithSystemMessage("inet_pton() failed");
  result =
      connect(sock, (struct sockaddr *)&serverAddress, sizeof(serverAddress));
  if (result < 0)
    DieWithSystemMessage("connect() failed");
  size_t echoStringLen = strlen(echoString);
  ssize_t numByte = write(sock, echoString, echoStringLen);
  if (numByte < 0)
    DieWithSystemMessage("write() failed");
  else if (numByte != echoStringLen)
    DieWithUserMessage("write()", "unexpected number of bytes");
  unsigned int totalByteReceive = 0;
  printf("Received :\n");
  numByte = 0;
  do {
    char buffer[BUFSIZ];
    numByte = recv(sock, buffer, BUFSIZ - 1, 0);
    if (numByte < 0)
      DieWithSystemMessage("recv() failed");
    printf("%s\n", buffer);
    totalByteReceive += numByte;
  } while (numByte > 0);
  printf("Total byte received : %d", totalByteReceive);
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     120d <main+0x2d>
cmpl   $0x4,-0x8(%rbp)
jle    1220 <main+0x40>
lea    0xdec(%rip),%rdi
lea    0xdf2(%rip),%rsi
call   10d0 <DieWithUserMessage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1257 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x6c(%rbp)
jmp    1264 <main+0x84>
mov    $0x7,%eax
mov    %eax,-0x6c(%rbp)
jmp    1264 <main+0x84>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
mov    0x2d55(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    12a3 <main+0xc3>
lea    0xd9c(%rip),%rdi
call   10a0 <DieWithSystemMessage@plt>
movl   $0x1,-0x34(%rbp)
mov    -0x30(%rbp),%edi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
mov    0x2d13(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    $0x8,%r8d
call   1040 <setsockopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12e7 <main+0x107>
lea    0xd68(%rip),%rdi
call   10a0 <DieWithSystemMessage@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   10c0 <inet_pton@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1349 <main+0x169>
lea    0xd26(%rip),%rdi
lea    0xd32(%rip),%rsi
call   10d0 <DieWithUserMessage@plt>
jmp    1364 <main+0x184>
cmpl   $0x0,-0x14(%rbp)
jge    135f <main+0x17f>
lea    0xd04(%rip),%rdi
call   10a0 <DieWithSystemMessage@plt>
jmp    1364 <main+0x184>
mov    -0x30(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    138e <main+0x1ae>
lea    0xcff(%rip),%rdi
call   10a0 <DieWithSystemMessage@plt>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1050 <write@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jae    13cb <main+0x1eb>
lea    0xcd8(%rip),%rdi
call   10a0 <DieWithSystemMessage@plt>
jmp    13f1 <main+0x211>
mov    -0x50(%rbp),%rax
cmp    -0x48(%rbp),%rax
je     13ec <main+0x20c>
lea    0xcc8(%rip),%rdi
lea    0xcc9(%rip),%rsi
call   10d0 <DieWithUserMessage@plt>
jmp    13f1 <main+0x211>
movl   $0x0,-0x54(%rbp)
lea    0xccc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movq   $0x0,-0x50(%rbp)
mov    0x2ba3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x78(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%edi
mov    0x2b74(%rip),%rax
mov    (%rax),%edx
sub    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jae    146b <main+0x28b>
lea    0xc71(%rip),%rdi
call   10a0 <DieWithSystemMessage@plt>
mov    -0x78(%rbp),%rsi
lea    0xc6f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x50(%rbp),%rcx
mov    -0x54(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x54(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,%rsp
cmpq   $0x0,-0x50(%rbp)
ja     140e <main+0x22e>
mov    -0x54(%rbp),%esi
lea    0xc43(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x30(%rbp),%edi
call   10b0 <close@plt>
xor    %eax,%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    $0x18,%rsp
mov    %rsi,%rbx
lea    -0x5(%rdi),%eax
cmp    $0xfffffffd,%eax
ja     1233 <main+0x43>
lea    0xded(%rip),%rdi
lea    0xdf3(%rip),%rsi
call   10e0 <DieWithUserMessage@plt>
mov    0x8(%rbx),%rax
mov    %rax,-0x30(%rbp)
mov    0x10(%rbx),%r14
mov    $0x7,%r12d
jmp    1256 <main+0x66>
mov    0x8(%rbx),%rax
mov    0x10(%rbx),%r14
mov    $0x7,%r12d
cmp    $0x4,%edi
mov    %rax,-0x30(%rbp)
jne    1256 <main+0x66>
mov    0x18(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r12d
mov    0x2d83(%rip),%r15
mov    (%r15),%edi
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    128a <main+0x9a>
lea    0xdb5(%rip),%rdi
call   10b0 <DieWithSystemMessage@plt>
movl   $0x1,-0x34(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
mov    0x2d2f(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    %r13d,%edi
mov    $0x8,%r8d
call   1050 <setsockopt@plt>
test   %eax,%eax
jns    12c5 <main+0xd5>
lea    0xd8a(%rip),%rdi
call   10b0 <DieWithSystemMessage@plt>
lea    -0x40(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    (%r15),%eax
mov    %eax,-0x38(%rbp)
mov    %r12d,%edi
call   1080 <htons@plt>
mov    %eax,-0x3c(%rbp)
mov    (%r15),%edi
mov    -0x30(%rbp),%rsi
mov    %rbx,%rdx
call   10d0 <inet_pton@plt>
test   %eax,%eax
je     130c <main+0x11c>
jns    131f <main+0x12f>
lea    0xd59(%rip),%rdi
call   10b0 <DieWithSystemMessage@plt>
jmp    131f <main+0x12f>
lea    0xd4b(%rip),%rdi
lea    0xd57(%rip),%rsi
call   10e0 <DieWithUserMessage@plt>
lea    -0x40(%rbp),%rsi
mov    %r13d,%edi
mov    $0xc,%edx
call   1100 <connect@plt>
test   %eax,%eax
jns    1340 <main+0x150>
lea    0xd4d(%rip),%rdi
call   10b0 <DieWithSystemMessage@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbx
mov    %r13d,%r15d
mov    %r13d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1060 <write@plt>
cmp    %rbx,%rax
je     1374 <main+0x184>
lea    0xd31(%rip),%rdi
lea    0xd32(%rip),%rsi
call   10e0 <DieWithUserMessage@plt>
lea    0xd5a(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    0x2c2f(%rip),%r12
mov    %r15d,-0x30(%rbp)
nopl   (%rax)
mov    %rsp,%r13
mov    (%r12),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    (%r12),%edx
add    $0xffffffff,%edx
mov    -0x30(%rbp),%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %ebx,%ebx
add    %r15,%rbx
mov    %r13,%rsp
test   %r15,%r15
jne    1390 <main+0x1a0>
lea    0xce1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    -0x30(%rbp),%edi
call   10c0 <close@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"Parameter(s)\00"
@.str.1 = [45 x i8] c"<Server Address> <Echo Word> [<Server Port>]\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@SOL_SOCKET = global i32 0
@SO_DEBUG = global i32 0
@.str.3 = [20 x i8] c"setsockopt() failed\00"
@.str.4 = [19 x i8] c"inet_pton() failed\00"
@.str.5 = [23 x i8] c"invalid address string\00"
@.str.6 = [17 x i8] c"connect() failed\00"
@.str.7 = [15 x i8] c"write() failed\00"
@.str.8 = [8 x i8] c"write()\00"
@.str.9 = [27 x i8] c"unexpected number of bytes\00"
@.str.10 = [12 x i8] c"Received :\0A\00"
@BUFSIZ = global i32 0
@.str.11 = [14 x i8] c"recv() failed\00"
@.str.12 = [4 x i8] c"%s\0A\00"
@.str.13 = [25 x i8] c"Total byte received : %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 3
br i1 %19, label %23, label %20
20: ; preds = %2
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 4
br i1 %22, label %23, label %25
23: ; preds = %20, %2
%24 = call i32 @DieWithUserMessage(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %7
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
store i8* %31, i8** %8
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 4
br i1 %33, label %34, label %39
34: ; preds = %25
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
br label %40
39: ; preds = %25
br label %40
40: ; preds = %39, %34
%41 = phi i32 [ %38, %34 ], [ 7, %39 ]
store i32 %41, i32* %9
%42 = load i32, i32* @AF_INET
%43 = load i32, i32* @SOCK_STREAM
%44 = load i32, i32* @IPPROTO_TCP
%45 = call i32 @socket(i32 %42, i32 %43, i32 %44)
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %40
%49 = call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %40
store i32 1, i32* %11
%51 = load i32, i32* %10
%52 = load i32, i32* @SOL_SOCKET
%53 = load i32, i32* @SO_DEBUG
%54 = bitcast i32* %11 to i8*
%55 = call i32 @setsockopt(i32 %51, i32 %52, i32 %53, i8* %54, i32 8)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %50
%59 = call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %58, %50
%61 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%62 = load i32, i32* @AF_INET
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %62, i32* %63
%64 = load i32, i32* %9
%65 = call i32 @htons(i32 %64)
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i32 %65, i32* %66
%67 = load i32, i32* @AF_INET
%68 = load i8*, i8** %7
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%70 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %69, i32 0, i32 0
%71 = call i32 @inet_pton(i32 %67, i8* %68, i32* %70)
store i32 %71, i32* %6
%72 = load i32, i32* %6
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %60
%75 = call i32 @DieWithUserMessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %82
76: ; preds = %60
%77 = load i32, i32* %6
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %81
81: ; preds = %79, %76
br label %82
82: ; preds = %81, %74
%83 = load i32, i32* %10
%84 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%85 = call i32 @connect(i32 %83, %struct.sockaddr* %84, i32 12)
store i32 %85, i32* %6
%86 = load i32, i32* %6
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %90
88: ; preds = %82
%89 = call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %90
90: ; preds = %88, %82
%91 = load i8*, i8** %8
%92 = call i64 @strlen(i8* %91)
store i64 %92, i64* %13
%93 = load i32, i32* %10
%94 = load i8*, i8** %8
%95 = load i64, i64* %13
%96 = call i64 @write(i32 %93, i8* %94, i64 %95)
store i64 %96, i64* %14
%97 = load i64, i64* %14
%98 = icmp ult i64 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %90
%100 = call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %108
101: ; preds = %90
%102 = load i64, i64* %14
%103 = load i64, i64* %13
%104 = icmp ne i64 %102, %103
br i1 %104, label %105, label %107
105: ; preds = %101
%106 = call i32 @DieWithUserMessage(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %107
107: ; preds = %105, %101
br label %108
108: ; preds = %107, %99
store i32 0, i32* %15
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
store i64 0, i64* %14
br label %110
110: ; preds = %131, %108
%111 = load i32, i32* @BUFSIZ
%112 = zext i32 %111 to i64
%113 = call i8* @llvm.stacksave()
store i8* %113, i8** %16
%114 = alloca i8, i64 %112
store i64 %112, i64* %17
%115 = load i32, i32* %10
%116 = load i32, i32* @BUFSIZ
%117 = sub nsw i32 %116, 1
%118 = call i64 @recv(i32 %115, i8* %114, i32 %117, i32 0)
store i64 %118, i64* %14
%119 = load i64, i64* %14
%120 = icmp ult i64 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %110
%122 = call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
br label %123
123: ; preds = %121, %110
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %114)
%125 = load i64, i64* %14
%126 = load i32, i32* %15
%127 = zext i32 %126 to i64
%128 = add i64 %127, %125
%129 = trunc i64 %128 to i32
store i32 %129, i32* %15
%130 = load i8*, i8** %16
br label %131
131: ; preds = %123
%132 = load i64, i64* %14
%133 = icmp ugt i64 %132, 0
br i1 %133, label %110, label %134
134: ; preds = %131
%135 = load i32, i32* %15
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i32 %135)
%137 = load i32, i32* %10
%138 = call i32 @close(i32 %137)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"Parameter(s)\00"
@.str.1 = [45 x i8] c"<Server Address> <Echo Word> [<Server Port>]\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@SOL_SOCKET = global i32 0
@SO_DEBUG = global i32 0
@.str.3 = [20 x i8] c"setsockopt() failed\00"
@.str.4 = [19 x i8] c"inet_pton() failed\00"
@.str.5 = [23 x i8] c"invalid address string\00"
@.str.6 = [17 x i8] c"connect() failed\00"
@.str.8 = [8 x i8] c"write()\00"
@.str.9 = [27 x i8] c"unexpected number of bytes\00"
@BUFSIZ = global i32 0
@.str.13 = [25 x i8] c"Total byte received : %d\00"
@str = [11 x i8] c"Received :\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = add i32 %0, -5
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = tail call i32 @DieWithUserMessage(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
br label %23
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = icmp eq i32 %0, 4
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
br label %23
23: ; preds = %7, %13, %19
%24 = phi i8* [ %17, %19 ], [ %17, %13 ], [ %12, %7 ]
%25 = phi i8* [ %15, %19 ], [ %15, %13 ], [ %10, %7 ]
%26 = phi i32 [ %22, %19 ], [ 7, %13 ], [ 7, %7 ]
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = load i32, i32* @IPPROTO_TCP
%30 = tail call i32 @socket(i32 %27, i32 %28, i32 %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = tail call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %23
%35 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%36 = load i32, i32* @SOL_SOCKET
%37 = load i32, i32* @SO_DEBUG
%38 = call i32 @setsockopt(i32 %30, i32 %36, i32 %37, i8* %35, i32 8)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
%43 = bitcast %struct.sockaddr_in* %4 to i8*
%44 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%45 = load i32, i32* @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %45, i32* %46
%47 = call i32 @htons(i32 %26)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %47, i32* %48
%49 = load i32, i32* @AF_INET
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
%51 = call i32 @inet_pton(i32 %49, i8* %25, i32* %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %42
%54 = call i32 @DieWithUserMessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %59
55: ; preds = %42
%56 = icmp slt i32 %51, 0
br i1 %56, label %57, label %59
57: ; preds = %55
%58 = call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %55, %57, %53
%60 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%61 = call i32 @connect(i32 %30, %struct.sockaddr* %60, i32 12)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 @DieWithSystemMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
%66 = call i64 @strlen(i8* dereferenceable(1) %24)
%67 = call i64 @write(i32 %30, i8* %24, i64 %66)
%68 = icmp eq i64 %67, %66
br i1 %68, label %71, label %69
69: ; preds = %65
%70 = call i32 @DieWithUserMessage(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %71
71: ; preds = %65, %69
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %73
73: ; preds = %73, %71
%74 = phi i64 [ 0, %71 ], [ %84, %73 ]
%75 = load i32, i32* @BUFSIZ
%76 = zext i32 %75 to i64
%77 = call i8* @llvm.stacksave()
%78 = alloca i8, i64 %76
%79 = load i32, i32* @BUFSIZ
%80 = add nsw i32 %79, -1
%81 = call i64 @recv(i32 %30, i8* %78, i32 %80, i32 0)
%82 = call i32 @puts(i8* %78)
%83 = and i64 %74, 4294967295
%84 = add i64 %81, %83
%85 = icmp eq i64 %81, 0
br i1 %85, label %86, label %73
86: ; preds = %73
%87 = trunc i64 %84 to i32
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i32 %87)
%89 = call i32 @close(i32 %30)
ret i32 0
}