#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_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ Remote_Address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
main(int argc, char *argv[]) {
  char buf[512];
  int client_socket;
  struct sockaddr_in localAddr_Active, Remote_Address;
  struct hostent *hp;
  if ((client_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("cannot create socket.\n");
    exit(1);
  }
  bzero(&Remote_Address, sizeof(Remote_Address));
  Remote_Address.sin_family = AF_INET;
  hp = gethostbyname(argv[1]);
  memcpy((unsigned char *)&Remote_Address.sin_addr, (unsigned char *)hp->h_addr,
         hp->h_length);
  Remote_Address.sin_port = htons(4096);
  if (connect(client_socket, &Remote_Address, sizeof(Remote_Address)) < 0) {
    printf("cannot connect to host : %s at Port : 4096\n", argv[1]);
    exit(1);
  }
  if ((write(client_socket, argv[2], strlen(argv[2]))) < 0) {
    printf("CLIENT: Problem with client write\n");
    exit(1);
  }
  if (read(client_socket, buf, 512) < 0) {
    printf("CLIENT: Problem with client read\n");
    exit(1);
  }
  printf("CLIENT: message from server : %s \n", buf);
  close(client_socket);
  printf("CLIENT: exit \n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x214(%rbp)
cmp    $0x0,%eax
jge    1219 <main+0x59>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x230(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x228(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <gethostbyname@plt>
mov    %rax,-0x238(%rbp)
lea    -0x230(%rbp),%rdi
add    $0x4,%rdi
mov    -0x238(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x238(%rbp),%rax
mov    (%rax),%edx
call   10a0 <memcpy@plt>
mov    $0x1000,%edi
call   1050 <htons@plt>
mov    %eax,-0x230(%rbp)
mov    -0x214(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    12c2 <main+0x102>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x214(%rbp),%eax
mov    %eax,-0x244(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x240(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x244(%rbp),%edi
mov    -0x240(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1320 <main+0x160>
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x214(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jge    1359 <main+0x199>
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x210(%rbp),%rsi
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x214(%rbp),%edi
call   1070 <close@plt>
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r14
mov    0x2e00(%rip),%r12
mov    (%r12),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
jns    120c <main+0x3c>
lea    0xe99(%rip),%rdi
jmp    12bf <main+0xef>
mov    %eax,%ebx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%r14),%rdi
call   10a0 <gethostbyname@plt>
lea    0x4(%rsp),%rdi
mov    0x8(%rax),%rsi
mov    (%rax),%edx
call   10b0 <memcpy@plt>
mov    $0x1000,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
jns    127c <main+0xac>
mov    0x8(%r14),%rsi
lea    0xd95(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x10(%r14),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    12a2 <main+0xd2>
lea    0xdde(%rip),%rdi
jmp    12bf <main+0xef>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x200,%edx
call   1090 <read@plt>
test   %rax,%rax
jns    12ce <main+0xfe>
lea    0xd9e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd57(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xd60(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [23 x i8] c"cannot create socket.\0A\00"
@.str.1 = [44 x i8] c"cannot connect to host : %s at Port : 4096\0A\00"
@.str.2 = [35 x i8] c"CLIENT: Problem with client write\0A\00"
@.str.3 = [34 x i8] c"CLIENT: Problem with client read\0A\00"
@.str.4 = [35 x i8] c"CLIENT: message from server : %s \0A\00"
@.str.5 = [15 x i8] c"CLIENT: exit \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.hostent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %20, i32* %21
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call %struct.hostent* @gethostbyname(i8* %24)
store %struct.hostent* %25, %struct.hostent** %10
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%27 = bitcast i32* %26 to i8*
%28 = load %struct.hostent*, %struct.hostent** %10
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i32 0, i32 1
%30 = load i64, i64* %29
%31 = inttoptr i64 %30 to i8*
%32 = load %struct.hostent*, %struct.hostent** %10
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @memcpy(i8* %27, i8* %31, i32 %34)
%36 = call i32 @htons(i32 4096)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %36, i32* %37
%38 = load i32, i32* %7
%39 = call i64 @connect(i32 %38, %struct.sockaddr_in* %9, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %18
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %18
%48 = load i32, i32* %7
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @strlen(i8* %54)
%56 = call i64 @write(i32 %48, i8* %51, i32 %55)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %47
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %47
%62 = load i32, i32* %7
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%64 = call i64 @read(i32 %62, i8* %63, i32 512)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %61
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %61
%70 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %70)
%72 = load i32, i32* %7
%73 = call i32 @close(i32 %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [44 x i8] c"cannot connect to host : %s at Port : 4096\0A\00"
@.str.4 = [35 x i8] c"CLIENT: message from server : %s \0A\00"
@str = [14 x i8] c"CLIENT: exit \00"
@str.6 = [33 x i8] c"CLIENT: Problem with client read\00"
@str.7 = [34 x i8] c"CLIENT: Problem with client write\00"
@str.8 = [22 x i8] c"cannot create socket.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call %struct.hostent* @gethostbyname(i8* %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%22 = bitcast i32* %21 to i8*
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i64 0, i32 1
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to i8*
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i64 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @memcpy(i8* %22, i8* %25, i32 %27)
%29 = call i32 @htons(i32 4096)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %29, i32* %30
%31 = call i64 @connect(i32 %9, %struct.sockaddr_in* %4, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %14
%34 = load i8*, i8** %18
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %14
%38 = getelementptr inbounds i8*, i8** %1, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @strlen(i8* %39)
%41 = call i64 @write(i32 %9, i8* %39, i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.7, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %37
%47 = call i64 @read(i32 %9, i8* %5, i32 512)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.6, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %46
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%54 = call i32 @close(i32 %9)
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%56 = call i32 @exit(i32 0)
unreachable
}