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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int close(int);
int connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(long *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
unsigned int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ write(int, char *, unsigned int);
int main(int argc, char *argv[]) {
  int hSocket;
  struct hostent *pHostInfo;
  struct sockaddr_in Address;
  long nHostAddress;
  char pBuffer[100];
  unsigned nReadAmount;
  char strHostName[255];
  int nHostPort;
  if (argc < 3) {
    printf("\nUsage: client host-name host-port\n");
    return 0;
  } else {
    strcpy(strHostName, argv[1]);
    nHostPort = atoi(argv[2]);
  }
  printf("\nMaking a socket");
  hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (hSocket == -1) {
    printf("\nCould not make a socket\n");
    return 0;
  }
  pHostInfo = gethostbyname(strHostName);
  memcpy(&nHostAddress, pHostInfo->h_addr, pHostInfo->h_length);
  Address.sin_addr.s_addr = nHostAddress;
  Address.sin_port = htons(nHostPort);
  Address.sin_family = AF_INET;
  printf("\nConnecting to %s on port %d\n", strHostName, nHostPort);
  if (connect(hSocket, (struct sockaddr *)&Address, sizeof(Address)) == -1) {
    printf("\nCould not connect to host\n");
    return 0;
  }
  nReadAmount = read(hSocket, pBuffer, 100);
  printf("\nCurrent time is %s", pBuffer);
  write(hSocket, pBuffer, nReadAmount);
  printf("\nWriting Current time to server");
  printf("\nClosing socket\n");
  if (close(hSocket) == -1) {
    printf("\nCould not close socket\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ed <main+0x3d>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1386 <main+0x1d6>
lea    -0x1b0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1b4(%rbp)
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1269 <main+0xb9>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1386 <main+0x1d6>
lea    -0x1b0(%rbp),%rdi
call   1090 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rdi
call   10a0 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1b4(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
lea    -0x1b0(%rbp),%rsi
mov    -0x1b4(%rbp),%edx
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1300 <main+0x150>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1386 <main+0x1d6>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x64,%edx
call   1080 <read@plt>
mov    %eax,-0xa4(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0xa4(%rbp),%edx
call   1040 <write@plt>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1386 <main+0x1d6>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x198,%rsp
cmp    $0x2,%edi
jg     11de <main+0x1e>
lea    0xee6(%rip),%rdi
jmp    130d <main+0x14d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0x90(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dd6(%rip),%r15
mov    (%r15),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     12fd <main+0x13d>
mov    %eax,%ebx
lea    0x90(%rsp),%r14
mov    %r14,%rdi
call   10a0 <gethostbyname@plt>
mov    (%rax),%edx
mov    0x4(%rax),%esi
lea    0x8(%rsp),%rdi
call   10b0 <memcpy@plt>
mov    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    %ebp,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
lea    0xd98(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     1306 <main+0x146>
lea    0x20(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1090 <read@plt>
mov    %eax,%ebp
lea    0xd77(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <write@plt>
lea    0xd6e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd80(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
jne    1312 <main+0x152>
lea    0xd78(%rip),%rdi
jmp    130d <main+0x14d>
lea    0xda2(%rip),%rdi
jmp    130d <main+0x14d>
lea    0xd7e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x198,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"\0AUsage: client host-name host-port\0A\00"
@.str.1 = [17 x i8] c"\0AMaking a socket\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [26 x i8] c"\0ACould not make a socket\0A\00"
@.str.3 = [30 x i8] c"\0AConnecting to %s on port %d\0A\00"
@.str.4 = [28 x i8] c"\0ACould not connect to host\0A\00"
@.str.5 = [20 x i8] c"\0ACurrent time is %s\00"
@.str.6 = [32 x i8] c"\0AWriting Current time to server\00"
@.str.7 = [17 x i8] c"\0AClosing socket\0A\00"
@.str.8 = [25 x i8] c"\0ACould not close socket\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca i64
%10 = alloca [100 x i8]
%11 = alloca i32
%12 = alloca [255 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %82
18: ; preds = %2
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strcpy(i8* %19, i8* %22)
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %13
br label %28
28: ; preds = %18
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_STREAM
%32 = load i32, i32* @IPPROTO_TCP
%33 = call i32 @socket(i32 %30, i32 %31, i32 %32)
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %28
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %82
38: ; preds = %28
%39 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%40 = call %struct.hostent* @gethostbyname(i8* %39)
store %struct.hostent* %40, %struct.hostent** %7
%41 = load %struct.hostent*, %struct.hostent** %7
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i32 0, i32 1
%43 = load i32, i32* %42
%44 = load %struct.hostent*, %struct.hostent** %7
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @memcpy(i64* %9, i32 %43, i32 %46)
%48 = load i64, i64* %9
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %49, i32 0, i32 0
store i64 %48, i64* %50
%51 = load i32, i32* %13
%52 = call i32 @htons(i32 %51)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %52, i32* %53
%54 = load i32, i32* @AF_INET
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %54, i32* %55
%56 = getelementptr inbounds [255 x i8], [255 x i8]* %12, i64 0, i64 0
%57 = load i32, i32* %13
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %56, i32 %57)
%59 = load i32, i32* %6
%60 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%61 = call i32 @connect(i32 %59, %struct.sockaddr* %60, i32 16)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %65
63: ; preds = %38
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %82
65: ; preds = %38
%66 = load i32, i32* %6
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%68 = call i32 @read(i32 %66, i8* %67, i32 100)
store i32 %68, i32* %11
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = load i32, i32* %6
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%73 = load i32, i32* %11
%74 = call i32 @write(i32 %71, i8* %72, i32 %73)
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%77 = load i32, i32* %6
%78 = call i32 @close(i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %82
80: ; preds = %65
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %82
82: ; preds = %16, %36, %63, %80, %65
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [17 x i8] c"\0AMaking a socket\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.3 = [30 x i8] c"\0AConnecting to %s on port %d\0A\00"
@.str.5 = [20 x i8] c"\0ACurrent time is %s\00"
@.str.6 = [32 x i8] c"\0AWriting Current time to server\00"
@str = [16 x i8] c"\0AClosing socket\00"
@str.9 = [24 x i8] c"\0ACould not close socket\00"
@str.10 = [27 x i8] c"\0ACould not connect to host\00"
@str.11 = [25 x i8] c"\0ACould not make a socket\00"
@str.12 = [35 x i8] c"\0AUsage: client host-name host-port\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i64
%5 = alloca [100 x i8]
%6 = alloca [255 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%11 = icmp slt i32 %0, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.12, i64 0, i64 0))
br label %58
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strcpy(i8* %10, i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = load i32, i32* @IPPROTO_TCP
%25 = call i32 @socket(i32 %22, i32 %23, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %14
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.11, i64 0, i64 0))
br label %58
29: ; preds = %14
%30 = call %struct.hostent* @gethostbyname(i8* %10)
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i64 0, i32 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i64 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @memcpy(i64* %4, i32 %32, i32 %34)
%36 = load i64, i64* %4
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i64 %36, i64* %37
%38 = call i32 @htons(i32 %20)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %38, i32* %39
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %40, i32* %41
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %10, i32 %20)
%43 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%44 = call i32 @connect(i32 %25, %struct.sockaddr* %43, i32 16)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %29
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.10, i64 0, i64 0))
br label %58
48: ; preds = %29
%49 = call i32 @read(i32 %25, i8* %9, i32 100)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%51 = call i32 @write(i32 %25, i8* %9, i32 %49)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%54 = call i32 @close(i32 %25)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %58
56: ; preds = %48
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.9, i64 0, i64 0))
br label %58
58: ; preds = %48, %56, %46, %27, %12
ret i32 0
}