#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 */
typedef int uint32_t;
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_sock;
typedef int /*<<< orphan*/ client_sock;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ Die(char *);
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, unsigned int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int listen(int, int);
char *malloc(long);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, long, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  int result;
  char buf[256];
  struct sockaddr_in server_sock, client_sock;
  int client_sock_fd = -1;
  int server_sock_fd = -1;
  unsigned int clientlen = sizeof(client_sock);
  int received = 0;
  char recv_buf[256];
  int sent_total_len = 0;
  int sent_cur_len = 0;
  FILE *fp = NULL;
  char *test_file_buf = NULL;
  long test_file_size = 0;
  char *local_host_ip = "127.0.0.1";
  uint32_t port = 3000;
  if ((fp = fopen("test_file.html", "r")) != 0) {
    fseek(fp, 0, SEEK_END);
    test_file_size = ftell(fp) + 1;
    test_file_buf = malloc(test_file_size);
    fseek(fp, 0, SEEK_SET);
    fread(test_file_buf, test_file_size, 1, fp);
    fclose(fp);
  } else {
    Die("failed to open test file");
  }
  memset(&server_sock, 0, sizeof(client_sock));
  server_sock.sin_family = AF_INET;
  server_sock.sin_addr.s_addr = inet_addr(local_host_ip);
  server_sock.sin_port = htons(port);
  printf(">> Listening for connections on port 3000...");
  fflush(stdout);
  if ((server_sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    Die("failed to create socket fd");
  }
  if ((result = bind(server_sock_fd, (struct sockaddr *)&server_sock,
                     sizeof(server_sock))) < 0) {
    Die("failed to bind server socket");
  }
  if ((result = listen(server_sock_fd, 256)) < 0) {
    Die("Failed to listen on server socket");
  }
  while (1) {
    if ((client_sock_fd = accept(server_sock_fd,
                                 (struct sockaddr *)&client_sock, &clientlen)) <
        0) {
    } else {
      while (received < 256) {
        if ((result = recv(client_sock_fd, recv_buf, 256 - 1, 0)) < 0) {
          Die("failed to receive bytes from client");
        }
        received += result;
        recv_buf[result] = '\0';
        if (strcmp(recv_buf, "fetch") == 0) {
        } else {
          printf("wrong input from client");
        }
        printf(recv_buf);
        while (1) {
          if ((sent_cur_len = send(client_sock_fd, test_file_buf,
                                   test_file_size - sent_total_len, 0)) > 0) {
            sent_total_len += sent_cur_len;
            if (sent_total_len == test_file_size) {
              printf("file transmitted");
              break;
            }
          } else if (sent_cur_len == 0) {
            Die("zero bytes transmitted to client");
          } else {
            printf("file transmitted completed");
            break;
          }
        }
        close(client_sock_fd);
        close(server_sock_fd);
        return 0;
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x144(%rbp)
ff ff ff
movl   $0xffffffff,-0x148(%rbp)
ff ff ff
movl   $0xc,-0x14c(%rbp)
movl   $0x0,-0x150(%rbp)
movl   $0x0,-0x254(%rbp)
movl   $0x0,-0x258(%rbp)
movq   $0x0,-0x260(%rbp)
movq   $0x0,-0x268(%rbp)
movq   $0x0,-0x270(%rbp)
lea    0xd43(%rip),%rax
mov    %rax,-0x278(%rbp)
movl   $0xbb8,-0x27c(%rbp)
lea    0xd35(%rip),%rdi
lea    0xd3d(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x260(%rbp)
cmp    $0x0,%rax
je     137b <main+0x13b>
mov    -0x260(%rbp),%rdi
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1120 <fseek@plt>
mov    -0x260(%rbp),%rdi
call   10d0 <ftell@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x270(%rbp)
mov    -0x270(%rbp),%rdi
call   10e0 <malloc@plt>
mov    %rax,-0x268(%rbp)
mov    -0x260(%rbp),%rdi
mov    0x2c7e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1120 <fseek@plt>
mov    -0x268(%rbp),%rdi
mov    -0x270(%rbp),%rsi
mov    -0x260(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x260(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1387 <main+0x147>
lea    0xc99(%rip),%rdi
call   1110 <Die@plt>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x128(%rbp)
mov    -0x278(%rbp),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x12c(%rbp)
mov    -0x27c(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x130(%rbp)
lea    0xc61(%rip),%rdi
call   1080 <printf@plt>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
call   10f0 <fflush@plt>
mov    0x2bcb(%rip),%rax
mov    (%rax),%edi
mov    0x2bd2(%rip),%rax
mov    (%rax),%esi
mov    0x2bd9(%rip),%rax
mov    (%rax),%edx
call   1160 <socket@plt>
mov    %eax,-0x148(%rbp)
cmp    $0x0,%eax
jge    1421 <main+0x1e1>
lea    0xc45(%rip),%rdi
call   1110 <Die@plt>
mov    -0x148(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0xc,%edx
call   1130 <bind@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1450 <main+0x210>
lea    0xc31(%rip),%rdi
call   1110 <Die@plt>
mov    -0x148(%rbp),%edi
mov    $0x100,%esi
call   1100 <listen@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1478 <main+0x238>
lea    0xc26(%rip),%rdi
call   1110 <Die@plt>
jmp    147d <main+0x23d>
mov    -0x148(%rbp),%edi
lea    -0x140(%rbp),%rsi
lea    -0x14c(%rbp),%rdx
call   1150 <accept@plt>
mov    %eax,-0x144(%rbp)
cmp    $0x0,%eax
jge    14aa <main+0x26a>
jmp    1614 <main+0x3d4>
jmp    14af <main+0x26f>
cmpl   $0x100,-0x150(%rbp)
jge    160f <main+0x3cf>
mov    -0x144(%rbp),%edi
lea    -0x250(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    14f0 <main+0x2b0>
lea    0xbd0(%rip),%rdi
call   1110 <Die@plt>
mov    -0x14(%rbp),%eax
add    -0x150(%rbp),%eax
mov    %eax,-0x150(%rbp)
movslq -0x14(%rbp),%rax
movb   $0x0,-0x250(%rbp,%rax,1)
lea    -0x250(%rbp),%rdi
lea    0xbc6(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    152d <main+0x2ed>
jmp    1539 <main+0x2f9>
lea    0xbb1(%rip),%rdi
call   1080 <printf@plt>
lea    -0x250(%rbp),%rdi
call   1080 <printf@plt>
mov    -0x144(%rbp),%edi
mov    -0x268(%rbp),%rsi
mov    -0x270(%rbp),%rdx
movslq -0x254(%rbp),%rax
sub    %rax,%rdx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %eax,-0x258(%rbp)
cmp    $0x0,%eax
jle    15b5 <main+0x375>
mov    -0x258(%rbp),%eax
add    -0x254(%rbp),%eax
mov    %eax,-0x254(%rbp)
movslq -0x254(%rbp),%rax
cmp    -0x270(%rbp),%rax
jne    15b0 <main+0x370>
lea    0xb57(%rip),%rdi
call   1080 <printf@plt>
jmp    15ee <main+0x3ae>
jmp    15e9 <main+0x3a9>
cmpl   $0x0,-0x258(%rbp)
jne    15d3 <main+0x393>
lea    0xb45(%rip),%rdi
call   1110 <Die@plt>
jmp    15e4 <main+0x3a4>
lea    0xb55(%rip),%rdi
call   1080 <printf@plt>
jmp    15ee <main+0x3ae>
jmp    15e9 <main+0x3a9>
jmp    1545 <main+0x305>
mov    -0x144(%rbp),%edi
call   10a0 <close@plt>
mov    -0x148(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x280,%rsp
pop    %rbp
ret
jmp    1614 <main+0x3d4>
jmp    147d <main+0x23d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
movl   $0xc,0xc(%rsp)
lea    0xdaa(%rip),%rdi
lea    0xdb2(%rip),%rsi
call   1140 <fopen@plt>
test   %rax,%rax
je     12d4 <main+0x94>
mov    %rax,%rbx
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1120 <fseek@plt>
mov    %rbx,%rdi
call   10d0 <ftell@plt>
add    $0x1,%eax
movslq %eax,%rbp
mov    %rbp,%rdi
call   10e0 <malloc@plt>
mov    %rax,%r15
mov    0x2d19(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1120 <fseek@plt>
mov    %r15,%rdi
mov    %rbp,(%rsp)
mov    %rbp,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    12e9 <main+0xa9>
lea    0xd40(%rip),%rdi
call   1110 <Die@plt>
xor    %r15d,%r15d
xor    %eax,%eax
mov    %rax,(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
lea    0xcf2(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0xbb8,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0xd08(%rip),%rdi
call   1080 <printf@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
call   10f0 <fflush@plt>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
mov    0x2c79(%rip),%rax
mov    (%rax),%esi
mov    0x2c80(%rip),%rax
mov    (%rax),%edx
call   1160 <socket@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    1372 <main+0x132>
lea    0xcf4(%rip),%rdi
call   1110 <Die@plt>
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0xc,%edx
call   1130 <bind@plt>
test   %eax,%eax
jns    1394 <main+0x154>
lea    0xced(%rip),%rdi
call   1110 <Die@plt>
mov    %r13d,%edi
mov    $0x100,%esi
call   1100 <listen@plt>
test   %eax,%eax
jns    13b1 <main+0x171>
lea    0xced(%rip),%rdi
call   1110 <Die@plt>
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1150 <accept@plt>
test   %eax,%eax
js     13c0 <main+0x180>
mov    %eax,%ebx
lea    0x30(%rsp),%rsi
mov    %eax,%edi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    13f9 <main+0x1b9>
lea    0xcc7(%rip),%rdi
call   1110 <Die@plt>
movslq %ebp,%rax
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xcd7(%rip),%rsi
lea    0x30(%rsp),%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1423 <main+0x1e3>
lea    0xcc7(%rip),%rdi
call   1080 <printf@plt>
lea    0x30(%rsp),%rdi
call   1080 <printf@plt>
xor    %r12d,%r12d
lea    0xcd7(%rip),%rbp
mov    (%rsp),%r14
movslq %r12d,%rax
sub    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %eax,%eax
jg     1470 <main+0x230>
jne    1488 <main+0x248>
mov    %rbp,%rdi
call   1110 <Die@plt>
jmp    1450 <main+0x210>
nop
add    %eax,%r12d
movslq %r12d,%rax
mov    (%rsp),%r14
cmp    %rax,%r14
jne    143b <main+0x1fb>
lea    0xc77(%rip),%rdi
jmp    148f <main+0x24f>
lea    0xca0(%rip),%rdi
call   1080 <printf@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [15 x i8] c"test_file.html\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [25 x i8] c"failed to open test file\00"
@AF_INET = global i32 0
@.str.4 = [45 x i8] c">> Listening for connections on port 3000...\00"
@stdout = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.5 = [27 x i8] c"failed to create socket fd\00"
@.str.6 = [29 x i8] c"failed to bind server socket\00"
@.str.7 = [34 x i8] c"Failed to listen on server socket\00"
@.str.8 = [36 x i8] c"failed to receive bytes from client\00"
@.str.9 = [6 x i8] c"fetch\00"
@.str.10 = [24 x i8] c"wrong input from client\00"
@.str.11 = [17 x i8] c"file transmitted\00"
@.str.12 = [33 x i8] c"zero bytes transmitted to client\00"
@.str.13 = [27 x i8] c"file transmitted completed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [256 x i8]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i8*
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %10
store i32 -1, i32* %11
store i32 12, i32* %12
store i32 0, i32* %13
store i32 0, i32* %15
store i32 0, i32* %16
store i32* null, i32** %17
store i8* null, i8** %18
store i64 0, i64* %19
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %20
store i32 3000, i32* %21
%22 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %17
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %43
24: ; preds = %2
%25 = load i32*, i32** %17
%26 = load i32, i32* @SEEK_END
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i32*, i32** %17
%29 = call i32 @ftell(i32* %28)
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
store i64 %31, i64* %19
%32 = load i64, i64* %19
%33 = call i8* @malloc(i64 %32)
store i8* %33, i8** %18
%34 = load i32*, i32** %17
%35 = load i32, i32* @SEEK_SET
%36 = call i32 @fseek(i32* %34, i32 0, i32 %35)
%37 = load i8*, i8** %18
%38 = load i64, i64* %19
%39 = load i32*, i32** %17
%40 = call i32 @fread(i8* %37, i64 %38, i32 1, i32* %39)
%41 = load i32*, i32** %17
%42 = call i32 @fclose(i32* %41)
br label %45
43: ; preds = %2
%44 = call i32 @Die(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %24
%46 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %47, i32* %48
%49 = load i8*, i8** %20
%50 = call i32 @inet_addr(i8* %49)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 0
store i32 %50, i32* %52
%53 = load i32, i32* %21
%54 = call i32 @htons(i32 %53)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %54, i32* %55
%56 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%57 = load i32, i32* @stdout
%58 = call i32 @fflush(i32 %57)
%59 = load i32, i32* @PF_INET
%60 = load i32, i32* @SOCK_STREAM
%61 = load i32, i32* @IPPROTO_TCP
%62 = call i32 @socket(i32 %59, i32 %60, i32 %61)
store i32 %62, i32* %11
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %45
%65 = call i32 @Die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %66
66: ; preds = %64, %45
%67 = load i32, i32* %11
%68 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%69 = call i32 @bind(i32 %67, %struct.sockaddr* %68, i32 12)
store i32 %69, i32* %6
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %66
%72 = call i32 @Die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %73
73: ; preds = %71, %66
%74 = load i32, i32* %11
%75 = call i32 @listen(i32 %74, i32 256)
store i32 %75, i32* %6
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = call i32 @Die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
br label %79
79: ; preds = %77, %73
br label %80
80: ; preds = %79, %148
%81 = load i32, i32* %11
%82 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%83 = call i32 @accept(i32 %81, %struct.sockaddr* %82, i32* %12)
store i32 %83, i32* %10
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %86
85: ; preds = %80
br label %148
86: ; preds = %80
br label %87
87: ; preds = %86
%88 = load i32, i32* %13
%89 = icmp slt i32 %88, 256
br i1 %89, label %90, label %147
90: ; preds = %87
%91 = load i32, i32* %10
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%93 = call i32 @recv(i32 %91, i8* %92, i32 255, i32 0)
store i32 %93, i32* %6
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %90
%96 = call i32 @Die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
br label %97
97: ; preds = %95, %90
%98 = load i32, i32* %6
%99 = load i32, i32* %13
%100 = add nsw i32 %99, %98
store i32 %100, i32* %13
%101 = load i32, i32* %6
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 %102
store i8 0, i8* %103
%104 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%105 = call i64 @strcmp(i8* %104, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %97
br label %110
108: ; preds = %97
%109 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
br label %110
110: ; preds = %108, %107
%111 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%112 = call i32 @printf(i8* %111)
br label %113
113: ; preds = %110, %141
%114 = load i32, i32* %10
%115 = load i8*, i8** %18
%116 = load i64, i64* %19
%117 = load i32, i32* %15
%118 = sext i32 %117 to i64
%119 = sub nsw i64 %116, %118
%120 = call i32 @send(i32 %114, i8* %115, i64 %119, i32 0)
store i32 %120, i32* %16
%121 = icmp sgt i32 %120, 0
br i1 %121, label %122, label %133
122: ; preds = %113
%123 = load i32, i32* %16
%124 = load i32, i32* %15
%125 = add nsw i32 %124, %123
store i32 %125, i32* %15
%126 = load i32, i32* %15
%127 = sext i32 %126 to i64
%128 = load i64, i64* %19
%129 = icmp eq i64 %127, %128
br i1 %129, label %130, label %132
130: ; preds = %122
%131 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0))
br label %142
132: ; preds = %122
br label %141
133: ; preds = %113
%134 = load i32, i32* %16
%135 = icmp eq i32 %134, 0
br i1 %135, label %136, label %138
136: ; preds = %133
%137 = call i32 @Die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0))
br label %140
138: ; preds = %133
%139 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0))
br label %142
140: ; preds = %136
br label %141
141: ; preds = %140, %132
br label %113
142: ; preds = %138, %130
%143 = load i32, i32* %10
%144 = call i32 @close(i32 %143)
%145 = load i32, i32* %11
%146 = call i32 @close(i32 %145)
ret i32 0
147: ; preds = %87
br label %148
148: ; preds = %147, %85
br label %80
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [15 x i8] c"test_file.html\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [25 x i8] c"failed to open test file\00"
@AF_INET = global i32 0
@.str.4 = [45 x i8] c">> Listening for connections on port 3000...\00"
@stdout = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.5 = [27 x i8] c"failed to create socket fd\00"
@.str.6 = [29 x i8] c"failed to bind server socket\00"
@.str.7 = [34 x i8] c"Failed to listen on server socket\00"
@.str.8 = [36 x i8] c"failed to receive bytes from client\00"
@.str.9 = [6 x i8] c"fetch\00"
@.str.10 = [24 x i8] c"wrong input from client\00"
@.str.11 = [17 x i8] c"file transmitted\00"
@.str.12 = [33 x i8] c"zero bytes transmitted to client\00"
@.str.13 = [27 x i8] c"file transmitted completed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %24, label %13
13: ; preds = %2
%14 = load i32, i32* @SEEK_END
%15 = tail call i32 @fseek(i32* %11, i32 0, i32 %14)
%16 = tail call i32 @ftell(i32* %11)
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = tail call i8* @malloc(i64 %18)
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %11, i32 0, i32 %20)
%22 = tail call i32 @fread(i8* %19, i64 %18, i32 1, i32* %11)
%23 = tail call i32 @fclose(i32* %11)
br label %26
24: ; preds = %2
%25 = tail call i32 @Die(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %13
%27 = phi i8* [ %19, %13 ], [ null, %24 ]
%28 = phi i64 [ %18, %13 ], [ 0, %24 ]
%29 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %30, i32* %31
%32 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %32, i32* %33
%34 = call i32 @htons(i32 3000)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %34, i32* %35
%36 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
%39 = load i32, i32* @PF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = load i32, i32* @IPPROTO_TCP
%42 = call i32 @socket(i32 %39, i32 %40, i32 %41)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %26
%45 = call i32 @Die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %26
%47 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%48 = call i32 @bind(i32 %42, %struct.sockaddr* %47, i32 12)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @Die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
%53 = call i32 @listen(i32 %42, i32 256)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @Die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
%58 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %59
59: ; preds = %59, %57
%60 = call i32 @accept(i32 %42, %struct.sockaddr* %58, i32* %5)
%61 = icmp sgt i32 %60, -1
br i1 %61, label %62, label %59
62: ; preds = %59
%63 = call i32 @recv(i32 %60, i8* %10, i32 255, i32 0)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @Die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
br label %67
67: ; preds = %65, %62
%68 = sext i32 %63 to i64
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %68
store i8 0, i8* %69
%70 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%71 = icmp eq i64 %70, 0
br i1 %71, label %74, label %72
72: ; preds = %67
%73 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
br label %74
74: ; preds = %67, %72
%75 = call i32 @printf(i8* %10)
br label %76
76: ; preds = %83, %74
%77 = phi i32 [ %84, %83 ], [ 0, %74 ]
%78 = sext i32 %77 to i64
%79 = sub nsw i64 %28, %78
br label %80
80: ; preds = %76, %89
%81 = call i32 @send(i32 %60, i8* %27, i64 %79, i32 0)
%82 = icmp sgt i32 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = add nsw i32 %81, %77
%85 = sext i32 %84 to i64
%86 = icmp eq i64 %28, %85
br i1 %86, label %91, label %76
87: ; preds = %80
%88 = icmp eq i32 %81, 0
br i1 %88, label %89, label %91
89: ; preds = %87
%90 = call i32 @Die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0))
br label %80
91: ; preds = %83, %87
%92 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0), %87 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), %83 ]
%93 = call i32 @printf(i8* dereferenceable(1) %92)
%94 = call i32 @close(i32 %60)
%95 = call i32 @close(i32 %42)
ret i32 0
}