#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;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int sockfd;
  struct sockaddr_in servaddr;
  char sendline[4096], recvline[4096];
  if (argc != 2) {
    perror("Usage: TCPClient <IP address of the server>\n");
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("Problem in creating the socket");
    exit(2);
  }
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = inet_addr(argv[1]);
  servaddr.sin_port = htons(3000);
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    perror("Problem in connecting to the server");
    exit(3);
  }
  while (1) {
    if (recv(sockfd, recvline, 4096, 0) == 0) {
      printf("The server closed the connection\n");
      exit(4);
    }
    fprintf(stdout, "Date TIme received back from the server is : %s\n",
            recvline);
    bzero(recvline, 4096);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e9 <main+0x39>
lea    0xe26(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1224 <main+0x74>
lea    0xe18(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xbb8,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    128e <main+0xde>
lea    0xdcd(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
jmp    1293 <main+0xe3>
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jne    12c9 <main+0x119>
lea    0xdb6(%rip),%rdi
call   1050 <printf@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    -0x2020(%rbp),%rdx
lea    0xdb2(%rip),%rsi
call   1080 <fprintf@plt>
lea    -0x2020(%rbp),%rdi
mov    $0x1000,%esi
call   10a0 <bzero@plt>
jmp    1293 <main+0xe3>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1018,%rsp
cmp    $0x2,%edi
jne    11f9 <main+0x49>
mov    %rsi,%r14
mov    0x2e1c(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
jns    120f <main+0x5f>
lea    0xe43(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xe00(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%r15d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%r14),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0xbb8,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %rax,%rax
jns    1270 <main+0xc0>
lea    0xdeb(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     12d2 <main+0x122>
mov    0x2d40(%rip),%r14
lea    0xdd9(%rip),%rbx
lea    0x10(%rsp),%rbp
nopl   0x0(%rax)
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1080 <fprintf@plt>
mov    %rbp,%rdi
mov    $0x1000,%esi
call   10a0 <bzero@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jne    12a0 <main+0xf0>
lea    0xdc8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [45 x i8] c"Usage: TCPClient <IP address of the server>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"Problem in creating the socket\00"
@.str.2 = [36 x i8] c"Problem in connecting to the server\00"
@.str.3 = [34 x i8] c"The server closed the connection\0A\00"
@stdout = global i32 0
@.str.4 = [49 x i8] c"Date TIme received back from the server is : %s\0A\00"
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 [4096 x i8]
%9 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %15
%24 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %25, i32* %26
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @inet_addr(i8* %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = call i32 @htons(i32 3000)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* %6
%36 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%37 = call i64 @connect(i32 %35, %struct.sockaddr* %36, i32 12)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %23
%40 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 3)
unreachable
42: ; preds = %23
br label %43
43: ; preds = %42, %51
%44 = load i32, i32* %6
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%46 = call i64 @recv(i32 %44, i8* %45, i32 4096, i32 0)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 @exit(i32 4)
unreachable
51: ; preds = %43
%52 = load i32, i32* @stdout
%53 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%54 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%56 = call i32 @bzero(i8* %55, i32 4096)
br label %43
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [45 x i8] c"Usage: TCPClient <IP address of the server>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"Problem in creating the socket\00"
@.str.2 = [36 x i8] c"Problem in connecting to the server\00"
@stdout = global i32 0
@.str.4 = [49 x i8] c"Date TIme received back from the server is : %s\0A\00"
@str = [33 x i8] c"The server closed the connection\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [4096 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 2)
unreachable
19: ; preds = %11
%20 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @inet_addr(i8* %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = call i32 @htons(i32 3000)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i64 @connect(i32 %14, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %19
%33 = call i64 @recv(i32 %14, i8* %6, i32 4096, i32 0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %41
35: ; preds = %19
%36 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 3)
unreachable
38: ; preds = %41, %32
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%40 = call i32 @exit(i32 4)
unreachable
41: ; preds = %32, %41
%42 = load i32, i32* @stdout
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%44 = call i32 @bzero(i8* %6, i32 4096)
%45 = call i64 @recv(i32 %14, i8* %6, i32 4096, i32 0)
%46 = icmp eq i64 %45, 0
br i1 %46, label %38, label %41
}