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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd, newsockfd, len, port;
  FILE *fd;
  struct sockaddr_in serv, cli;
  char buffer[256], c[2000], cc[20000];
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  port = atoi(argv[1]);
  serv.sin_port = htons(port);
  serv.sin_addr.s_addr = INADDR_ANY;
  serv.sin_family = AF_INET;
  printf(" Status: Setting up... \n ");
  if (bind(sockfd, (struct sockaddr *)&serv, sizeof(serv)) < 0) {
    printf(" Error \n ");
    exit(0);
  }
  printf(" Status: Waiting for client... \n ");
  listen(sockfd, 10);
  len = sizeof(cli);
  newsockfd = accept(sockfd, (struct sockaddr *)&cli, &len);
  printf(" Status: Client connected... \n ");
  bzero(buffer, 255);
  read(newsockfd, buffer, 255);
  printf(" Status: Sending data... \n ");
  if ((fd = fopen(buffer, "r")) != NULL) {
    fgets(cc, 2000, fd);
    while (!feof(fd)) {
      fgets(c, 2000, fd);
      strcat(cc, c);
    }
  }
  write(newsockfd, cc, strlen(cc));
  printf(" Status: Done. \n ");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5750,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
lea    0xd91(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    12a2 <main+0xa2>
lea    0xd84(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    0xd7b(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
movl   $0xc,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x18(%rbp)
lea    0xd6a(%rip),%rdi
call   1060 <printf@plt>
lea    -0x150(%rbp),%rdi
mov    $0xff,%esi
call   10d0 <bzero@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0xff,%edx
call   1070 <read@plt>
lea    0xd59(%rip),%rdi
call   1060 <printf@plt>
lea    -0x150(%rbp),%rdi
lea    0xd62(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1398 <main+0x198>
lea    -0x5740(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x7d0,%esi
call   1080 <fgets@plt>
mov    -0x28(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1366 <main+0x166>
jmp    1393 <main+0x193>
lea    -0x920(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x7d0,%esi
call   1080 <fgets@plt>
lea    -0x5740(%rbp),%rdi
lea    -0x920(%rbp),%rsi
call   1100 <strcat@plt>
jmp    1348 <main+0x148>
jmp    1398 <main+0x198>
mov    -0x18(%rbp),%eax
mov    %eax,-0x574c(%rbp)
lea    -0x5740(%rbp),%rax
mov    %rax,-0x5748(%rbp)
lea    -0x5740(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x574c(%rbp),%edi
mov    -0x5748(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xcae(%rip),%rdi
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x5750,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x5728,%rsp
mov    %rsi,%rbp
mov    0x2dd1(%rip),%r14
mov    (%r14),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%ebx
mov    0x8(%rbp),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
lea    0xda5(%rip),%rdi
call   1060 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
test   %rax,%rax
js     1390 <main+0x190>
lea    0xda3(%rip),%rdi
call   1060 <printf@plt>
mov    %ebx,%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10e0 <accept@plt>
mov    %eax,%r14d
lea    0xd91(%rip),%rdi
call   1060 <printf@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
call   10d0 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1070 <read@plt>
lea    0xd83(%rip),%rdi
call   1060 <printf@plt>
lea    0xd93(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1357 <main+0x157>
mov    %rax,%rbx
lea    0x900(%rsp),%rdi
mov    $0x7d0,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1357 <main+0x157>
lea    0x130(%rsp),%rbp
lea    0x900(%rsp),%r15
mov    %rbp,%rdi
mov    $0x7d0,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1100 <strcat@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1330 <main+0x130>
lea    0x900(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xd09(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x5728,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc83(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   1110 <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
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [26 x i8] c" Status: Setting up... \0A \00"
@.str.1 = [10 x i8] c" Error \0A \00"
@.str.2 = [34 x i8] c" Status: Waiting for client... \0A \00"
@.str.3 = [32 x i8] c" Status: Client connected... \0A \00"
@.str.4 = [28 x i8] c" Status: Sending data... \0A \00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [18 x i8] c" Status: Done. \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 i32*
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca [256 x i8]
%14 = alloca [2000 x i8]
%15 = alloca [20000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = call i32 @htons(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %29, i32* %30
%31 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* %6
%33 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%34 = call i64 @bind(i32 %32, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %2
%37 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %2
%40 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* %6
%42 = call i32 @listen(i32 %41, i32 10)
store i32 12, i32* %8
%43 = load i32, i32* %6
%44 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%45 = call i32 @accept(i32 %43, %struct.sockaddr* %44, i32* %8)
store i32 %45, i32* %7
%46 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%48 = call i32 @bzero(i8* %47, i32 255)
%49 = load i32, i32* %7
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%51 = call i32 @read(i32 %49, i8* %50, i32 255)
%52 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %54, i32** %10
%55 = icmp ne i32* %54, null
br i1 %55, label %56, label %73
56: ; preds = %39
%57 = getelementptr inbounds [20000 x i8], [20000 x i8]* %15, i64 0, i64 0
%58 = load i32*, i32** %10
%59 = call i32 @fgets(i8* %57, i32 2000, i32* %58)
br label %60
60: ; preds = %65, %56
%61 = load i32*, i32** %10
%62 = call i32 @feof(i32* %61)
%63 = icmp ne i32 %62, 0
%64 = xor i1 %63, true
br i1 %64, label %65, label %72
65: ; preds = %60
%66 = getelementptr inbounds [2000 x i8], [2000 x i8]* %14, i64 0, i64 0
%67 = load i32*, i32** %10
%68 = call i32 @fgets(i8* %66, i32 2000, i32* %67)
%69 = getelementptr inbounds [20000 x i8], [20000 x i8]* %15, i64 0, i64 0
%70 = getelementptr inbounds [2000 x i8], [2000 x i8]* %14, i64 0, i64 0
%71 = call i32 @strcat(i8* %69, i8* %70)
br label %60
72: ; preds = %60
br label %73
73: ; preds = %72, %39
%74 = load i32, i32* %7
%75 = getelementptr inbounds [20000 x i8], [20000 x i8]* %15, i64 0, i64 0
%76 = getelementptr inbounds [20000 x i8], [20000 x i8]* %15, i64 0, i64 0
%77 = call i32 @strlen(i8* %76)
%78 = call i32 @write(i32 %74, i8* %75, i32 %77)
%79 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%80 = load i32, i32* %3
ret i32 %80
}

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
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [26 x i8] c" Status: Setting up... \0A \00"
@.str.1 = [10 x i8] c" Error \0A \00"
@.str.2 = [34 x i8] c" Status: Waiting for client... \0A \00"
@.str.3 = [32 x i8] c" Status: Client connected... \0A \00"
@.str.4 = [28 x i8] c" Status: Sending data... \0A \00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [18 x i8] c" Status: Done. \0A \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [256 x i8]
%7 = alloca [2000 x i8]
%8 = alloca [20000 x i8]
%9 = bitcast i32* %3 to i8*
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [20000 x i8], [20000 x i8]* %8, i64 0, i64 0
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = tail call i32 @htons(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %25, i32* %26
%27 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%28 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%29 = call i64 @bind(i32 %17, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %2
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %2
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @listen(i32 %17, i32 10)
store i32 12, i32* %3
%37 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%38 = call i32 @accept(i32 %17, %struct.sockaddr* %37, i32* %3)
%39 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @bzero(i8* %12, i32 255)
%41 = call i32 @read(i32 %38, i8* %12, i32 255)
%42 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %54, label %45
45: ; preds = %34
%46 = call i32 @fgets(i8* %14, i32 2000, i32* %43)
%47 = call i32 @feof(i32* %43)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %45, %49
%50 = call i32 @fgets(i8* %13, i32 2000, i32* %43)
%51 = call i32 @strcat(i8* %14, i8* %13)
%52 = call i32 @feof(i32* %43)
%53 = icmp eq i32 %52, 0
br i1 %53, label %49, label %54
54: ; preds = %49, %45, %34
%55 = call i32 @strlen(i8* %14)
%56 = call i32 @write(i32 %38, i8* %14, i32 %55)
%57 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}