#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*/ cli_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_RDONLY;
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*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  struct sockaddr_in serv_addr, cli_addr;
  socklen_t cli_len;
  int sockfd, clifd, fd;
  char buf[10];
  int bytes;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <port>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  fd = open("file_server.c", O_RDONLY);
  if (fd == -1) {
    perror("open() failed");
    exit(EXIT_FAILURE);
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd == -1) {
    perror("socket() failed");
    exit(EXIT_FAILURE);
  }
  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(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1) {
    fprintf(stderr, "bind() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (listen(sockfd, 5) == -1) {
    fprintf(stderr, "listen() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  cli_len = sizeof(cli_addr);
  clifd = accept(sockfd, (struct sockaddr *)&cli_addr, &cli_len);
  if (clifd == -1) {
    fprintf(stderr, "accept() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  while (1) {
    bytes = read(fd, buf, sizeof(buf) - 1);
    buf[bytes] = '\0';
    if (bytes == 0) {
      break;
    } else if (bytes < sizeof(buf) - 1) {
      break;
    }
    write(clifd, buf, bytes);
  }
  shutdown(clifd, SHUT_WR);
  bytes = read(clifd, buf, sizeof(buf) - 1);
  buf[bytes] = '\0';
  printf("[recv] %s\n", buf);
  close(fd);
  close(clifd);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     126a <main+0x4a>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xda9(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
lea    0xd98(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    12a6 <main+0x86>
lea    0xd8d(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    12e6 <main+0xc6>
lea    0xd5b(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0xffffffff,%eax
jne    137e <main+0x15e>
mov    0x2c75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2c59(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xcd3(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x38(%rbp),%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
jne    13ce <main+0x1ae>
mov    0x2c25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2c09(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xc96(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
movl   $0xc,-0x34(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    142c <main+0x20c>
mov    0x2bc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,%rdx
lea    0xc4d(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2b83(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
jmp    1431 <main+0x211>
mov    -0x40(%rbp),%edi
lea    -0x4a(%rbp),%rsi
mov    $0x9,%edx
call   10a0 <read@plt>
mov    %eax,-0x50(%rbp)
movslq -0x50(%rbp),%rax
movb   $0x0,-0x4a(%rbp,%rax,1)
cmpl   $0x0,-0x50(%rbp)
jne    145d <main+0x23d>
jmp    1489 <main+0x269>
movslq -0x50(%rbp),%rax
cmp    $0x9,%rax
jae    1470 <main+0x250>
jmp    1489 <main+0x269>
jmp    1475 <main+0x255>
mov    -0x3c(%rbp),%edi
lea    -0x4a(%rbp),%rsi
mov    -0x50(%rbp),%edx
call   1030 <write@plt>
jmp    1431 <main+0x211>
mov    -0x3c(%rbp),%edi
mov    0x2b4d(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x3c(%rbp),%edi
lea    -0x4a(%rbp),%rsi
mov    $0x9,%edx
call   10a0 <read@plt>
mov    %eax,-0x50(%rbp)
movslq -0x50(%rbp),%rax
movb   $0x0,-0x4a(%rbp,%rax,1)
lea    -0x4a(%rbp),%rsi
lea    0xbb9(%rip),%rdi
call   1060 <printf@plt>
mov    -0x40(%rbp),%edi
call   1090 <close@plt>
mov    -0x3c(%rbp),%edi
call   1090 <close@plt>
mov    -0x38(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r15
cmp    $0x2,%edi
jne    13c9 <main+0x1a9>
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
lea    0xdca(%rip),%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     13de <main+0x1be>
mov    %eax,%r12d
mov    0x2d88(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
je     13e7 <main+0x1c7>
mov    %eax,%r14d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%r15),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0xffffffff,%eax
je     13f5 <main+0x1d5>
mov    %r14d,%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
je     1415 <main+0x1f5>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
je     1435 <main+0x215>
mov    %eax,%ebp
lea    0x2(%rsp),%rsi
mov    %r12d,%edi
mov    $0x9,%edx
call   10a0 <read@plt>
movslq %eax,%rcx
movb   $0x0,0x2(%rsp,%rcx,1)
cmp    $0x9,%eax
jb     1369 <main+0x149>
lea    0x2(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x9,%edx
call   10a0 <read@plt>
movslq %eax,%rcx
movb   $0x0,0x2(%rsp,%rcx,1)
cmp    $0x8,%ecx
ja     1340 <main+0x120>
mov    0x2c70(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1040 <shutdown@plt>
lea    0x2(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x9,%edx
call   10a0 <read@plt>
cltq
movb   $0x0,0x2(%rsp,%rax,1)
lea    0xce0(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %r12d,%edi
call   1090 <close@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r14d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bf0(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xc24(%rip),%rsi
jmp    1458 <main+0x238>
lea    0xc3b(%rip),%rdi
jmp    13ee <main+0x1ce>
lea    0xc40(%rip),%rdi
call   10f0 <perror@plt>
jmp    145d <main+0x23d>
mov    0x2bc4(%rip),%rax
mov    (%rax),%ebx
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xc2b(%rip),%rsi
jmp    1453 <main+0x233>
mov    0x2ba4(%rip),%rax
mov    (%rax),%ebx
mov    0x2b8b(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xc1e(%rip),%rsi
jmp    1453 <main+0x233>
mov    0x2b84(%rip),%rax
mov    (%rax),%ebx
mov    0x2b6b(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xc13(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10b0 <fprintf@plt>
mov    0x2b44(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <port>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"file_server.c\00"
@O_RDONLY = global i32 0
@.str.2 = [14 x i8] c"open() failed\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [16 x i8] c"socket() failed\00"
@INADDR_ANY = global i32 0
@.str.4 = [19 x i8] c"bind() failed: %s\0A\00"
@errno = global i32 0
@.str.5 = [21 x i8] c"listen() failed: %s\0A\00"
@.str.6 = [21 x i8] c"accept() failed: %s\0A\00"
@SHUT_WR = global i32 0
@.str.7 = [11 x i8] c"[recv] %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [10 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 %24
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 %26, i32* %11
%27 = load i32, i32* %11
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %24
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %33
%40 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %33
%44 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%45 = load i32, i32* @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %45, i32* %46
%47 = load i32, i32* @INADDR_ANY
%48 = call i32 @htonl(i32 %47)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %49, i32 0, i32 0
store i32 %48, i32* %50
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
%55 = call i32 @htons(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %55, i32* %56
%57 = load i32, i32* %9
%58 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%59 = call i32 @bind(i32 %57, %struct.sockaddr* %58, i32 12)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %68
61: ; preds = %43
%62 = load i32, i32* @stderr
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %43
%69 = load i32, i32* %9
%70 = call i32 @listen(i32 %69, i32 5)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %79
72: ; preds = %68
%73 = load i32, i32* @stderr
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %75)
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %68
store i32 12, i32* %8
%80 = load i32, i32* %9
%81 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%82 = call i32 @accept(i32 %80, %struct.sockaddr* %81, i32* %8)
store i32 %82, i32* %10
%83 = load i32, i32* %10
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %92
85: ; preds = %79
%86 = load i32, i32* @stderr
%87 = load i32, i32* @errno
%88 = call i8* @strerror(i32 %87)
%89 = call i32 @fprintf(i32 %86, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %88)
%90 = load i32, i32* @EXIT_FAILURE
%91 = call i32 @exit(i32 %90)
unreachable
92: ; preds = %79
br label %93
93: ; preds = %92, %109
%94 = load i32, i32* %11
%95 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%96 = call i32 @read(i32 %94, i8* %95, i32 9)
store i32 %96, i32* %13
%97 = load i32, i32* %13
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 %98
store i8 0, i8* %99
%100 = load i32, i32* %13
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %103
102: ; preds = %93
br label %114
103: ; preds = %93
%104 = load i32, i32* %13
%105 = sext i32 %104 to i64
%106 = icmp ult i64 %105, 9
br i1 %106, label %107, label %108
107: ; preds = %103
br label %114
108: ; preds = %103
br label %109
109: ; preds = %108
%110 = load i32, i32* %10
%111 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%112 = load i32, i32* %13
%113 = call i32 @write(i32 %110, i8* %111, i32 %112)
br label %93
114: ; preds = %107, %102
%115 = load i32, i32* %10
%116 = load i32, i32* @SHUT_WR
%117 = call i32 @shutdown(i32 %115, i32 %116)
%118 = load i32, i32* %10
%119 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%120 = call i32 @read(i32 %118, i8* %119, i32 9)
store i32 %120, i32* %13
%121 = load i32, i32* %13
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 %122
store i8 0, i8* %123
%124 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%125 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %124)
%126 = load i32, i32* %11
%127 = call i32 @close(i32 %126)
%128 = load i32, i32* %10
%129 = call i32 @close(i32 %128)
%130 = load i32, i32* %9
%131 = call i32 @close(i32 %130)
ret i32 0
}

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