#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*/ server_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  int sockfd, n;
  struct sockaddr_in server_addr;
  char filename[256], buff[1024];
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  server_addr.sin_port = htons(5600);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  printf("[CLIENT] Socket created\n");
  connect(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr));
  printf("[CLIENT] Connected to server\n");
  printf("Enter filename: ");
  scanf("%s", filename);
  write(sockfd, filename, strlen(filename));
  printf("[CLIENT] Waiting for server\n");
  n = read(sockfd, buff, 1024);
  buff[n] = '\0';
  printf("[CLIENT] Reply from server\n");
  fputs(buff, stdout);
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xe1b(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x15e0,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    0xded(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
lea    0xde9(%rip),%rdi
call   1060 <printf@plt>
lea    0xdfb(%rip),%rdi
call   1060 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xdf9(%rip),%rdi
call   10b0 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x52c(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x528(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x52c(%rbp),%edi
mov    -0x528(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xdb9(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x520(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
movb   $0x0,-0x520(%rbp,%rax,1)
lea    0xda7(%rip),%rdi
call   1060 <printf@plt>
lea    -0x520(%rbp),%rdi
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x518,%rsp
mov    0x2e08(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe13(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x15e0,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
lea    0xe00(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10e0 <connect@plt>
lea    0xdfd(%rip),%rdi
call   1030 <puts@plt>
lea    0xdc5(%rip),%rdi
call   1070 <printf@plt>
lea    0xdca(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   10c0 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xdda(%rip),%rdi
call   1030 <puts@plt>
lea    0x110(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
cltq
movb   $0x0,0x110(%rsp,%rax,1)
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <fputs@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@.str.1 = [25 x i8] c"[CLIENT] Socket created\0A\00"
@.str.2 = [30 x i8] c"[CLIENT] Connected to server\0A\00"
@.str.3 = [17 x i8] c"Enter filename: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [29 x i8] c"[CLIENT] Waiting for server\0A\00"
@.str.6 = [28 x i8] c"[CLIENT] Reply from server\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [256 x i8]
%6 = alloca [1024 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %7, i32* %8
%9 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i32 0, i32 0
store i32 %9, i32* %11
%12 = call i32 @htons(i32 5600)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %2
%17 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %2
%19 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%20 = call i32 @connect(i32 %18, %struct.sockaddr* %19, i32 12)
%21 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %2
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @write(i32 %25, i8* %26, i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* %2
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 1024)
store i32 %33, i32* %3
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = load i32, i32* @stdout
%40 = call i32 @fputs(i8* %38, i32 %39)
%41 = load i32, i32* %2
%42 = call i32 @close(i32 %41)
%43 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@.str.3 = [17 x i8] c"Enter filename: \00"
@.str.4 = [3 x i8] c"%s\00"
@stdout = global i32 0
@str = [24 x i8] c"[CLIENT] Socket created\00"
@str.7 = [29 x i8] c"[CLIENT] Connected to server\00"
@str.8 = [28 x i8] c"[CLIENT] Waiting for server\00"
@str.9 = [27 x i8] c"[CLIENT] Reply from server\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [256 x i8]
%3 = alloca [1024 x i8]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %7, i32* %8
%9 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 5600)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %11, i32* %12
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%17 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%18 = call i32 @connect(i32 %15, %struct.sockaddr* %17, i32 12)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%22 = call i32 @strlen(i8* %5)
%23 = call i32 @write(i32 %15, i8* %5, i32 %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0))
%25 = call i32 @read(i32 %15, i8* %6, i32 1024)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.9, i64 0, i64 0))
%29 = load i32, i32* @stdout
%30 = call i32 @fputs(i8* %6, i32 %29)
%31 = call i32 @close(i32 %15)
%32 = call i32 @exit(i32 0)
unreachable
}