#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 socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ clnt_addr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SHUT_WR;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error_handling(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int serverSocket;
  int clientSocket;
  FILE *fp;
  struct sockaddr_in serv_addr, clnt_addr;
  socklen_t clnt_addr_size;
  char buf[30];
  int read_cnt;
  if (argc != 2) {
    printf("Usage : %s <port>\n", argv[0]);
    exit(1);
  }
  fp = fopen("file_server.c", "rb");
  serverSocket = socket(PF_INET, SOCK_STREAM, 0);
  if (serverSocket == -1) {
    error_handling("socket() error");
  }
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  serv_addr.sin_port = htons(atoi(argv[1]));
  if (bind(serverSocket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) ==
      -1) {
    error_handling("bind() error");
  }
  if (listen(serverSocket, 5) == -1) {
    error_handling("listen() error");
  }
  clnt_addr_size = sizeof(clnt_addr);
  clientSocket =
      accept(serverSocket, (struct sockaddr *)&clnt_addr, &clnt_addr_size);
  while (1) {
    read_cnt = fread((void *)buf, 1, 30, fp);
    if (read_cnt < 30) {
      write(clientSocket, buf, read_cnt);
      break;
    }
    write(clientSocket, buf, 30);
  }
  shutdown(clientSocket, SHUT_WR);
  read(clientSocket, buf, 30);
  printf("Message from client: %s \n", buf);
  fclose(fp);
  close(clientSocket);
  close(serverSocket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1260 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdaf(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xdac(%rip),%rdi
lea    0xdb3(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12a9 <main+0x89>
lea    0xd80(%rip),%rdi
call   10d0 <error_handling@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1313 <main+0xf3>
lea    0xd25(%rip),%rdi
call   10d0 <error_handling@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1335 <main+0x115>
lea    0xd10(%rip),%rdi
call   10d0 <error_handling@plt>
movl   $0xc,-0x44(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1e,%edx
call   1030 <fread@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x1e,-0x74(%rbp)
jge    1387 <main+0x167>
mov    -0x18(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
call   1040 <write@plt>
jmp    139d <main+0x17d>
mov    -0x18(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x1e,%edx
call   1040 <write@plt>
jmp    134f <main+0x12f>
mov    -0x18(%rbp),%edi
mov    0x2c39(%rip),%rax
mov    (%rax),%esi
call   1060 <shutdown@plt>
mov    -0x18(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x1e,%edx
call   10c0 <read@plt>
lea    -0x70(%rbp),%rsi
lea    0xc85(%rip),%rdi
call   1080 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%edi
call   10b0 <close@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r15
cmp    $0x2,%edi
jne    13ce <main+0x1ae>
lea    0xdd4(%rip),%rdi
lea    0xddb(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%r12
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    127b <main+0x5b>
lea    0xdae(%rip),%rdi
call   10d0 <error_handling@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%r15),%rdi
call   1120 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12e3 <main+0xc3>
lea    0xd55(%rip),%rdi
call   10d0 <error_handling@plt>
mov    %r14d,%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1301 <main+0xe1>
lea    0xd44(%rip),%rdi
call   10d0 <error_handling@plt>
movl   $0xc,0xc(%rsp)
lea    0x40(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
call   1110 <accept@plt>
mov    %eax,%ebp
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1e,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    $0x1e,%eax
jl     1369 <main+0x149>
lea    0x20(%rsp),%rbx
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1e,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1e,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    $0x1e,%eax
jge    1340 <main+0x120>
lea    0x20(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    0x2c5f(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1060 <shutdown@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1e,%edx
call   10c0 <read@plt>
lea    0xcaf(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%rsi
lea    0xc28(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Usage : %s <port>\0A\00"
@.str.1 = [14 x i8] c"file_server.c\00"
@.str.2 = [3 x i8] c"rb\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.4 = [13 x i8] c"bind() error\00"
@.str.5 = [15 x i8] c"listen() error\00"
@SHUT_WR = global i32 0
@.str.6 = [26 x i8] c"Message from client: %s \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 %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca [30 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %8
%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* %6
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %22
%32 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %33, i32* %34
%35 = load i32, i32* @INADDR_ANY
%36 = call i32 @htonl(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
store i32 %36, i32* %38
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
%43 = call i32 @htons(i32 %42)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %43, i32* %44
%45 = load i32, i32* %6
%46 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%47 = call i32 @bind(i32 %45, %struct.sockaddr* %46, i32 12)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %31
%50 = call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %31
%52 = load i32, i32* %6
%53 = call i32 @listen(i32 %52, i32 5)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %57
57: ; preds = %55, %51
store i32 12, i32* %11
%58 = load i32, i32* %6
%59 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%60 = call i32 @accept(i32 %58, %struct.sockaddr* %59, i32* %11)
store i32 %60, i32* %7
br label %61
61: ; preds = %57, %72
%62 = getelementptr inbounds [30 x i8], [30 x i8]* %12, i64 0, i64 0
%63 = load i32*, i32** %8
%64 = call i32 @fread(i8* %62, i32 1, i32 30, i32* %63)
store i32 %64, i32* %13
%65 = load i32, i32* %13
%66 = icmp slt i32 %65, 30
br i1 %66, label %67, label %72
67: ; preds = %61
%68 = load i32, i32* %7
%69 = getelementptr inbounds [30 x i8], [30 x i8]* %12, i64 0, i64 0
%70 = load i32, i32* %13
%71 = call i32 @write(i32 %68, i8* %69, i32 %70)
br label %76
72: ; preds = %61
%73 = load i32, i32* %7
%74 = getelementptr inbounds [30 x i8], [30 x i8]* %12, i64 0, i64 0
%75 = call i32 @write(i32 %73, i8* %74, i32 30)
br label %61
76: ; preds = %67
%77 = load i32, i32* %7
%78 = load i32, i32* @SHUT_WR
%79 = call i32 @shutdown(i32 %77, i32 %78)
%80 = load i32, i32* %7
%81 = getelementptr inbounds [30 x i8], [30 x i8]* %12, i64 0, i64 0
%82 = call i32 @read(i32 %80, i8* %81, i32 30)
%83 = getelementptr inbounds [30 x i8], [30 x i8]* %12, i64 0, i64 0
%84 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %83)
%85 = load i32*, i32** %8
%86 = call i32 @fclose(i32* %85)
%87 = load i32, i32* %7
%88 = call i32 @close(i32 %87)
%89 = load i32, i32* %6
%90 = call i32 @close(i32 %89)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Usage : %s <port>\0A\00"
@.str.1 = [14 x i8] c"file_server.c\00"
@.str.2 = [3 x i8] c"rb\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.4 = [13 x i8] c"bind() error\00"
@.str.5 = [15 x i8] c"listen() error\00"
@SHUT_WR = global i32 0
@.str.6 = [26 x i8] c"Message from client: %s \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [30 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 2
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @PF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = call i32 @htonl(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %29, i32* %30
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
%34 = call i32 @htons(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %34, i32* %35
%36 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%37 = call i32 @bind(i32 %20, %struct.sockaddr* %36, i32 12)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %24
%40 = call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39, %24
%42 = call i32 @listen(i32 %20, i32 5)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
store i32 12, i32* %5
%47 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%48 = call i32 @accept(i32 %20, %struct.sockaddr* %47, i32* %5)
%49 = call i32 @fread(i8* %10, i32 1, i32 30, i32* %17)
%50 = icmp slt i32 %49, 30
br i1 %50, label %51, label %61
51: ; preds = %61, %46
%52 = phi i32 [ %49, %46 ], [ %63, %61 ]
%53 = call i32 @write(i32 %48, i8* %10, i32 %52)
%54 = load i32, i32* @SHUT_WR
%55 = call i32 @shutdown(i32 %48, i32 %54)
%56 = call i32 @read(i32 %48, i8* %10, i32 30)
%57 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %10)
%58 = call i32 @fclose(i32* %17)
%59 = call i32 @close(i32 %48)
%60 = call i32 @close(i32 %20)
ret i32 0
61: ; preds = %46, %61
%62 = call i32 @write(i32 %48, i8* %10, i32 30)
%63 = call i32 @fread(i8* %10, i32 1, i32 30, i32* %17)
%64 = icmp slt i32 %63, 30
br i1 %64, label %51, label %61
}