#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_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd, newsockfd, len, fd;
  struct sockaddr_in serv, cli;
  char buffer[256], c[2000], cc[20000];
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  bzero((char *)&serv, sizeof(serv));
  serv.sin_port = htons(atoi(argv[1]));
  serv.sin_family = AF_INET;
  printf(" Status: Attempting to connect to server\n ");
  connect(sockfd, (struct sockaddr *)&serv, sizeof(serv));
  printf(" Status: Connected \n ");
  printf(" Enter file name: ");
  scanf("%s", buffer);
  write(sockfd, buffer, strlen(buffer));
  bzero(c, 2000);
  printf(" Waiting for Server to respond.. \n \n");
  read(sockfd, c, 1999);
  printf("%s", c);
  printf(" \n ");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5730,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x8,%esi
call   1090 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   10b0 <connect@plt>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x130(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x572c(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x5728(%rbp)
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x572c(%rbp),%edi
mov    -0x5728(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    -0x900(%rbp),%rdi
mov    $0x7d0,%esi
call   1090 <bzero@plt>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x900(%rbp),%rsi
mov    $0x7cf,%edx
call   1070 <read@plt>
lea    -0x900(%rbp),%rsi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x5730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x8e8,%rsp
mov    %rsi,%rbx
mov    0x2e21(%rip),%r15
mov    (%r15),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x8,%esi
call   10a0 <bzero@plt>
mov    0x8(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
lea    0xdf0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   10c0 <connect@plt>
lea    0xdfe(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe0b(%rip),%r14
lea    0x10(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0x110(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x7d0,%esi
call   10a0 <bzero@plt>
lea    0xdce(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x7cf,%edx
call   1080 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdc6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x8e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [43 x i8] c" Status: Attempting to connect to server\0A \00"
@.str.1 = [22 x i8] c" Status: Connected \0A \00"
@.str.2 = [19 x i8] c" Enter file name: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [37 x i8] c" Waiting for Server to respond.. \0A \0A\00"
@.str.5 = [4 x i8] c" \0A \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca [256 x i8]
%13 = alloca [2000 x i8]
%14 = alloca [20000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %6
%18 = bitcast %struct.sockaddr_in* %10 to i8*
%19 = call i32 @bzero(i8* %18, i32 8)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
%24 = call i32 @htons(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %26, i32* %27
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* %6
%30 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%31 = call i32 @connect(i32 %29, %struct.sockaddr* %30, i32 8)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %6
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @write(i32 %36, i8* %37, i32 %39)
%41 = getelementptr inbounds [2000 x i8], [2000 x i8]* %13, i64 0, i64 0
%42 = call i32 @bzero(i8* %41, i32 2000)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32, i32* %6
%45 = getelementptr inbounds [2000 x i8], [2000 x i8]* %13, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 1999)
%47 = getelementptr inbounds [2000 x i8], [2000 x i8]* %13, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [43 x i8] c" Status: Attempting to connect to server\0A \00"
@.str.1 = [22 x i8] c" Status: Connected \0A \00"
@.str.2 = [19 x i8] c" Enter file name: \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.5 = [4 x i8] c" \0A \00"
@str = [36 x i8] c" Waiting for Server to respond.. \0A \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca [2000 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = call i32 @bzero(i8* %6, i32 8)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = tail call i32 @htons(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %18, i32* %19
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @connect(i32 %11, %struct.sockaddr* %21, i32 8)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%26 = call i32 @strlen(i8* %7)
%27 = call i32 @write(i32 %11, i8* %7, i32 %26)
%28 = call i32 @bzero(i8* %8, i32 2000)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%30 = call i32 @read(i32 %11, i8* %8, i32 1999)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}