#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 {
  char *sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ GetLocalOs(char *, int *);
int /*<<< orphan*/ GetLocalTime(int, int *);
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  char OS[16];
  int *valid;
  GetLocalOs(OS, valid);
  int startUpTime;
  GetLocalTime(startUpTime, valid);
  int clientSocket;
  int PORT = atoi(argv[2]);
  char buffer[1024];
  struct sockaddr_in serverAddr;
  socklen_t addr_size;
  clientSocket = socket(PF_INET, SOCK_STREAM, 0);
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(PORT);
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
  addr_size = sizeof serverAddr;
  connect(clientSocket, (struct sockaddr *)&serverAddr, addr_size);
  printf("Please enter a message for server: ");
  memset(buffer, '\0', 1024);
  fgets(buffer, 1024, stdin);
  send(clientSocket, buffer, 1024, 0);
  memset(buffer, '\0', 1024);
  recv(clientSocket, buffer, 1024, 0);
  printf("Data received: %s", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <GetLocalOs@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   10c0 <GetLocalTime@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x30(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x448(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x44c(%rbp)
lea    0xdbe(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x450(%rbp)
mov    -0x458(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
movl   $0x18,-0x45c(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x458(%rbp),%rsi
mov    -0x45c(%rbp),%edx
call   10d0 <connect@plt>
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x440(%rbp),%rdi
mov    0x2d32(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
mov    -0x30(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x30(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x440(%rbp),%rsi
lea    0xd27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%rbx
lea    0x20(%rsp),%rdi
call   10a0 <GetLocalOs@plt>
call   10c0 <GetLocalTime@plt>
mov    0x10(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %ebx,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xde0(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x10(%rsp)
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x18,%edx
call   10d0 <connect@plt>
lea    0xdbd(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xd78(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [36 x i8] c"Please enter a message for server: \00"
@stdin = global i32 0
@.str.2 = [18 x i8] c"Data received: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [16 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%15 = load i32*, i32** %7
%16 = call i32 @GetLocalOs(i8* %14, i32* %15)
%17 = load i32, i32* %8
%18 = load i32*, i32** %7
%19 = call i32 @GetLocalTime(i32 %17, i32* %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %10
%24 = load i32, i32* @PF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %9
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 3
store i32 %27, i32* %28
%29 = load i32, i32* %10
%30 = call i32 @htons(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %30, i32* %31
%32 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
store i32 %32, i32* %34
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @memset(i8* %36, i8 signext 0, i32 8)
store i32 24, i32* %13
%38 = load i32, i32* %9
%39 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%40 = load i32, i32* %13
%41 = call i32 @connect(i32 %38, %struct.sockaddr* %39, i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%44 = call i32 @memset(i8* %43, i8 signext 0, i32 1024)
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%46 = load i32, i32* @stdin
%47 = call i32 @fgets(i8* %45, i32 1024, i32 %46)
%48 = load i32, i32* %9
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%50 = call i32 @send(i32 %48, i8* %49, i32 1024, i32 0)
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%52 = call i32 @memset(i8* %51, i8 signext 0, i32 1024)
%53 = load i32, i32* %9
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%55 = call i32 @recv(i32 %53, i8* %54, i32 1024, i32 0)
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %56)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [36 x i8] c"Please enter a message for server: \00"
@stdin = global i32 0
@.str.2 = [18 x i8] c"Data received: %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%7 = call i32 @GetLocalOs(i8* %6, i32* undef)
%8 = call i32 @GetLocalTime(i32 undef, i32* undef)
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = call i32 @atoi(i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = bitcast %struct.sockaddr_in* %5 to i8*
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 3
store i32 %17, i32* %18
%19 = call i32 @htons(i32 %11)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = call i32 @memset(i8* undef, i8 signext 0, i32 8)
%24 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%25 = call i32 @connect(i32 %16, %struct.sockaddr* %24, i32 24)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @memset(i8* %12, i8 signext 0, i32 1024)
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %12, i32 1024, i32 %28)
%30 = call i32 @send(i32 %16, i8* %12, i32 1024, i32 0)
%31 = call i32 @memset(i8* %12, i8 signext 0, i32 1024)
%32 = call i32 @recv(i32 %16, i8* %12, i32 1024, i32 0)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %12)
ret i32 0
}