#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 {
  char sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EAGAIN;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int errno;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int listen(int, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main() {
  int sockfd, nsockfd, sin_size;
  struct sockaddr_in addr_local;
  struct sockaddr_in addr_remote;
  char revbuf[512];
  int start = 0, i = 0;
  char fname[512];
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    fprintf(stderr, "ERROR: Failed to obtain Socket Descriptor. (errno = %d)\n",
            errno);
    exit(1);
  } else
    printf("[TCP Server] Obtaining socket descriptor successfully.\n");
  addr_local.sin_family = AF_INET;
  addr_local.sin_port = htons(4444);
  addr_local.sin_addr.s_addr = INADDR_ANY;
  bzero(&(addr_local.sin_zero), 8);
  if (bind(sockfd, (struct sockaddr *)&addr_local, sizeof(struct sockaddr)) ==
      -1) {
    fprintf(stderr, "ERROR: Failed to bind Port. (errno = %d)\n", errno);
    exit(1);
  } else
    printf("[TCP Server] Binded tcp port %d in addr 127.0.0.1 sucessfully.\n",
           4444);
  if (listen(sockfd, 5) == -1) {
    fprintf(stderr, "ERROR: Failed to listen Port. (errno = %d)\n", errno);
    exit(1);
  } else
    printf("[TCP Server] Listening the port %d successfully.\n", 4444);
  int success = 0;
  while (success == 0) {
    sin_size = sizeof(struct sockaddr_in);
    if ((nsockfd = accept(sockfd, (struct sockaddr *)&addr_remote,
                          (socklen_t *)&sin_size)) == -1) {
      fprintf(stderr, "ERROR: Obtaining new Socket Despcritor. (errno = %d)\n",
              errno);
      exit(1);
    } else {
      printf("[Server] Server got connection from %s.\n",
             inet_ntoa(addr_remote.sin_addr));
    }
    char *fr_name = "./receive.txt";
    FILE *fr = fopen(fr_name, "a");
    if (fr == NULL)
      printf("File %s Cannot be opened file on server.\n", fr_name);
    else {
      bzero(revbuf, 512);
      int fr_block_sz = 0;
      while ((fr_block_sz = recv(nsockfd, revbuf, 512, 0)) > 0) {
        if (!start) {
          for (i = 0; i < 512; i++) {
            if (revbuf[i] == '\0') {
              start = 1;
              break;
            }
            fname[i] = revbuf[i];
          }
          fname[i] = '\0';
          printf("GOT NAME : %s, len %zd  Size %d \n", fname, strlen(fname),
                 fr_block_sz);
        } else {
          int write_sz = fwrite(revbuf, sizeof(char), fr_block_sz, fr);
          if (write_sz < fr_block_sz) {
            error("File write failed on server.\n");
          }
          bzero(revbuf, 512);
          if (fr_block_sz == 0) {
            printf("Going to break! %d \n", fr_block_sz);
            break;
          }
        }
      }
      if (fr_block_sz < 0) {
        if (errno == EAGAIN) {
          printf("recv() timed out.\n");
        } else {
          fprintf(stderr, "recv() failed due to errno = %d\n", errno);
          exit(1);
        }
      }
      printf("Ok received from client!\n");
      start = 0;
      fclose(fr);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x234(%rbp)
movl   $0x0,-0x238(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1273 <main+0x73>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
lea    0xd9c(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x115c,%edi
call   1070 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   10e0 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12f6 <main+0xf6>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
mov    0x2ce2(%rip),%rax
mov    (%rax),%edx
lea    0xd8a(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xd9e(%rip),%rdi
mov    $0x115c,%esi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1347 <main+0x147>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
mov    0x2c91(%rip),%rax
mov    (%rax),%edx
lea    0xda3(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xdb9(%rip),%rdi
mov    $0x115c,%esi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x444(%rbp)
cmpl   $0x0,-0x444(%rbp)
jne    163f <main+0x43f>
movl   $0x10,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    13bc <main+0x1bc>
mov    0x2c35(%rip),%rax
mov    (%rax),%edi
mov    0x2c1c(%rip),%rax
mov    (%rax),%edx
lea    0xd8c(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x2c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xdbc(%rip),%rax
mov    %rax,-0x450(%rbp)
mov    -0x450(%rbp),%rdi
lea    0xdb5(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x458(%rbp)
cmpq   $0x0,-0x458(%rbp)
jne    1425 <main+0x225>
mov    -0x450(%rbp),%rsi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    163a <main+0x43a>
lea    -0x230(%rbp),%rdi
mov    $0x200,%esi
call   10e0 <bzero@plt>
movl   $0x0,-0x45c(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x45c(%rbp)
cmp    $0x0,%eax
jle    15b1 <main+0x3b1>
cmpl   $0x0,-0x234(%rbp)
jne    152e <main+0x32e>
movl   $0x0,-0x238(%rbp)
cmpl   $0x200,-0x238(%rbp)
jge    14e3 <main+0x2e3>
movslq -0x238(%rbp),%rax
movsbl -0x230(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    14b3 <main+0x2b3>
movl   $0x1,-0x234(%rbp)
jmp    14e3 <main+0x2e3>
movslq -0x238(%rbp),%rax
mov    -0x230(%rbp,%rax,1),%cl
movslq -0x238(%rbp),%rax
mov    %cl,-0x440(%rbp,%rax,1)
mov    -0x238(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x238(%rbp)
jmp    147c <main+0x27c>
movslq -0x238(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
lea    -0x440(%rbp),%rax
mov    %rax,-0x468(%rbp)
lea    -0x440(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x468(%rbp),%rsi
mov    %eax,%edx
mov    -0x45c(%rbp),%ecx
lea    0xcb0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15ac <main+0x3ac>
lea    -0x230(%rbp),%rdi
mov    -0x45c(%rbp),%edx
mov    -0x458(%rbp),%rcx
mov    $0x1,%esi
call   1110 <fwrite@plt>
mov    %eax,-0x460(%rbp)
mov    -0x460(%rbp),%eax
cmp    -0x45c(%rbp),%eax
jge    1570 <main+0x370>
lea    0xc89(%rip),%rdi
call   10c0 <error@plt>
lea    -0x230(%rbp),%rdi
mov    $0x200,%esi
call   10e0 <bzero@plt>
cmpl   $0x0,-0x45c(%rbp)
jne    15a7 <main+0x3a7>
mov    -0x45c(%rbp),%esi
lea    0xc77(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    15b1 <main+0x3b1>
jmp    15ac <main+0x3ac>
jmp    1440 <main+0x240>
cmpl   $0x0,-0x45c(%rbp)
jge    1616 <main+0x416>
mov    0x29fb(%rip),%rax
mov    (%rax),%eax
mov    0x29e2(%rip),%rcx
cmp    (%rcx),%eax
jne    15e9 <main+0x3e9>
lea    0xc4a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1611 <main+0x411>
mov    0x29e0(%rip),%rax
mov    (%rax),%edi
mov    0x29c7(%rip),%rax
mov    (%rax),%edx
lea    0xc38(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1616 <main+0x416>
lea    0xc3e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x234(%rbp)
mov    -0x458(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1364 <main+0x164>
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2dc0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
jne    125d <main+0x4d>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    0x2d71(%rip),%rax
mov    (%rax),%edx
lea    0xda8(%rip),%rsi
jmp    135d <main+0x14d>
mov    %eax,%r13d
lea    0xf94(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%eax
mov    %eax,0x1c(%rsp)
mov    $0x115c,%edi
call   1080 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x2d59(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   10f0 <bzero@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12d2 <main+0xc2>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
mov    0x2cfc(%rip),%rax
mov    (%rax),%edx
lea    0xd6c(%rip),%rsi
jmp    135d <main+0x14d>
lea    0xd8a(%rip),%rdi
mov    $0x115c,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r13d,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1312 <main+0x102>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
mov    0x2cb9(%rip),%rax
mov    (%rax),%edx
lea    0xd93(%rip),%rsi
jmp    135d <main+0x14d>
lea    0xdb6(%rip),%rdi
mov    $0x115c,%esi
xor    %eax,%eax
call   1090 <printf@plt>
movl   $0x10,0x8(%rsp)
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r13d,%edi
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
jne    136c <main+0x15c>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
mov    0x2c6c(%rip),%rax
mov    (%rax),%edx
lea    0xda4(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    %eax,%r15d
lea    0xdea(%rip),%rbp
lea    0x230(%rsp),%r14
lea    0x30(%rsp),%r12
mov    %r13d,0xc(%rsp)
jmp    13df <main+0x1cf>
nopw   0x0(%rax,%rax,1)
test   %r13d,%r13d
mov    0xc(%rsp),%r13d
lea    0xdc1(%rip),%rbp
js     1580 <main+0x370>
lea    0xe86(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
movl   $0x10,0x8(%rsp)
mov    %r13d,%edi
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1100 <accept@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     1344 <main+0x134>
mov    0x24(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xd48(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
lea    0xd6b(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1560 <main+0x350>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x200,%esi
call   10f0 <bzero@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    1390 <main+0x180>
xor    %ebp,%ebp
jmp    147f <main+0x26f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x200,%esi
call   10f0 <bzero@plt>
mov    $0x1,%ebp
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    1390 <main+0x180>
test   %ebp,%ebp
je     14b0 <main+0x2a0>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbx,%rcx
call   1120 <fwrite@plt>
cmp    %r13d,%eax
jge    1450 <main+0x240>
lea    0xd1a(%rip),%rdi
call   10d0 <error@plt>
jmp    1450 <main+0x240>
nopl   0x0(%rax)
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x230(%rsp,%rax,1),%ecx
mov    $0x1,%ebp
test   %cl,%cl
je     1530 <main+0x320>
mov    %cl,0x30(%rsp,%rax,1)
movzbl 0x231(%rsp,%rax,1),%ecx
test   %cl,%cl
je     151a <main+0x30a>
mov    %cl,0x31(%rsp,%rax,1)
movzbl 0x232(%rsp,%rax,1),%ecx
test   %cl,%cl
je     1520 <main+0x310>
mov    %cl,0x32(%rsp,%rax,1)
movzbl 0x233(%rsp,%rax,1),%ecx
test   %cl,%cl
je     1526 <main+0x316>
mov    %cl,0x33(%rsp,%rax,1)
add    $0x4,%rax
cmp    $0x200,%rax
jne    14c0 <main+0x2b0>
xor    %ebp,%ebp
mov    $0x200,%eax
jmp    1530 <main+0x320>
add    $0x1,%rax
jmp    1530 <main+0x320>
add    $0x2,%rax
jmp    1530 <main+0x320>
add    $0x3,%rax
nopw   0x0(%rax,%rax,1)
mov    %eax,%eax
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r12,%rdi
call   1070 <strlen@plt>
lea    0xc54(%rip),%rdi
mov    %r12,%rsi
mov    %eax,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1090 <printf@plt>
jmp    1462 <main+0x252>
nopw   0x0(%rax,%rax,1)
lea    0xc09(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    13b9 <main+0x1a9>
cs nopw 0x0(%rax,%rax,1)
mov    0x2a39(%rip),%rax
mov    (%rax),%edx
mov    0x2a20(%rip),%rax
cmp    (%rax),%edx
jne    15a5 <main+0x395>
lea    0xcb0(%rip),%rdi
call   1040 <puts@plt>
jmp    13a5 <main+0x195>
mov    0x2a24(%rip),%rax
mov    (%rax),%edi
lea    0xc25(%rip),%rsi
jmp    135d <main+0x14d>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [57 x i8] c"ERROR: Failed to obtain Socket Descriptor. (errno = %d)\0A\00"
@errno = global i32 0
@.str.1 = [56 x i8] c"[TCP Server] Obtaining socket descriptor successfully.\0A\00"
@INADDR_ANY = global i32 0
@.str.2 = [42 x i8] c"ERROR: Failed to bind Port. (errno = %d)\0A\00"
@.str.3 = [64 x i8] c"[TCP Server] Binded tcp port %d in addr 127.0.0.1 sucessfully.\0A\00"
@.str.4 = [44 x i8] c"ERROR: Failed to listen Port. (errno = %d)\0A\00"
@.str.5 = [50 x i8] c"[TCP Server] Listening the port %d successfully.\0A\00"
@.str.6 = [54 x i8] c"ERROR: Obtaining new Socket Despcritor. (errno = %d)\0A\00"
@.str.7 = [41 x i8] c"[Server] Server got connection from %s.\0A\00"
@.str.8 = [14 x i8] c"./receive.txt\00"
@.str.9 = [2 x i8] c"a\00"
@.str.10 = [42 x i8] c"File %s Cannot be opened file on server.\0A\00"
@.str.11 = [34 x i8] c"GOT NAME : %s, len %zd Size %d \0A\00"
@.str.12 = [30 x i8] c"File write failed on server.\0A\00"
@.str.13 = [21 x i8] c"Going to break! %d \0A\00"
@EAGAIN = global i32 0
@.str.14 = [19 x i8] c"recv() timed out.\0A\00"
@.str.15 = [33 x i8] c"recv() failed due to errno = %d\0A\00"
@.str.16 = [26 x i8] c"Ok received from client!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca [512 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %8
store i32 0, i32* %9
%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* %2
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %25
20: ; preds = %0
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 3
store i32 %28, i32* %29
%30 = call i32 @htons(i32 4444)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i32, i32* @INADDR_ANY
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
store i32 %32, i32* %34
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%36 = call i32 @bzero(i8* %35, i32 8)
%37 = load i32, i32* %2
%38 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%39 = call i32 @bind(i32 %37, %struct.sockaddr* %38, i32 4)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %46
41: ; preds = %27
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %27
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i32 4444)
br label %48
48: ; preds = %46
%49 = load i32, i32* %2
%50 = call i32 @listen(i32 %49, i32 5)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i32 4444)
br label %59
59: ; preds = %57
store i32 0, i32* %11
br label %60
60: ; preds = %169, %59
%61 = load i32, i32* %11
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %170
63: ; preds = %60
store i32 16, i32* %4
%64 = load i32, i32* %2
%65 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%66 = call i32 @accept(i32 %64, %struct.sockaddr* %65, i32* %4)
store i32 %66, i32* %3
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %73
68: ; preds = %63
%69 = load i32, i32* @stderr
%70 = load i32, i32* @errno
%71 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0), i32 %70)
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %63
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%75 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i8* @inet_ntoa(i32 %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %77)
br label %79
79: ; preds = %73
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8** %12
%80 = load i8*, i8** %12
%81 = call i32* @fopen(i8* %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %81, i32** %13
%82 = load i32*, i32** %13
%83 = icmp eq i32* %82, null
br i1 %83, label %84, label %87
84: ; preds = %79
%85 = load i8*, i8** %12
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i8* %85)
br label %169
87: ; preds = %79
%88 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%89 = call i32 @bzero(i8* %88, i32 512)
store i32 0, i32* %14
br label %90
90: ; preds = %149, %87
%91 = load i32, i32* %3
%92 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%93 = call i32 @recv(i32 %91, i8* %92, i32 512, i32 0)
store i32 %93, i32* %14
%94 = icmp sgt i32 %93, 0
br i1 %94, label %95, label %150
95: ; preds = %90
%96 = load i32, i32* %8
%97 = icmp ne i32 %96, 0
br i1 %97, label %130, label %98
98: ; preds = %95
store i32 0, i32* %9
br label %99
99: ; preds = %118, %98
%100 = load i32, i32* %9
%101 = icmp slt i32 %100, 512
br i1 %101, label %102, label %121
102: ; preds = %99
%103 = load i32, i32* %9
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 %104
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = icmp eq i32 %107, 0
br i1 %108, label %109, label %110
109: ; preds = %102
store i32 1, i32* %8
br label %121
110: ; preds = %102
%111 = load i32, i32* %9
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 %112
%114 = load i8, i8* %113
%115 = load i32, i32* %9
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 %116
store i8 %114, i8* %117
br label %118
118: ; preds = %110
%119 = load i32, i32* %9
%120 = add nsw i32 %119, 1
store i32 %120, i32* %9
br label %99
121: ; preds = %109, %99
%122 = load i32, i32* %9
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 %123
store i8 0, i8* %124
%125 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%126 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%127 = call i32 @strlen(i8* %126)
%128 = load i32, i32* %14
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i8* %125, i32 %127, i32 %128)
br label %149
130: ; preds = %95
%131 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%132 = load i32, i32* %14
%133 = load i32*, i32** %13
%134 = call i32 @fwrite(i8* %131, i32 1, i32 %132, i32* %133)
store i32 %134, i32* %15
%135 = load i32, i32* %15
%136 = load i32, i32* %14
%137 = icmp slt i32 %135, %136
br i1 %137, label %138, label %140
138: ; preds = %130
%139 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0))
br label %140
140: ; preds = %138, %130
%141 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%142 = call i32 @bzero(i8* %141, i32 512)
%143 = load i32, i32* %14
%144 = icmp eq i32 %143, 0
br i1 %144, label %145, label %148
145: ; preds = %140
%146 = load i32, i32* %14
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0), i32 %146)
br label %150
148: ; preds = %140
br label %149
149: ; preds = %148, %121
br label %90
150: ; preds = %145, %90
%151 = load i32, i32* %14
%152 = icmp slt i32 %151, 0
br i1 %152, label %153, label %165
153: ; preds = %150
%154 = load i32, i32* @errno
%155 = load i32, i32* @EAGAIN
%156 = icmp eq i32 %154, %155
br i1 %156, label %157, label %159
157: ; preds = %153
%158 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.14, i64 0, i64 0))
br label %164
159: ; preds = %153
%160 = load i32, i32* @stderr
%161 = load i32, i32* @errno
%162 = call i32 @fprintf(i32 %160, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.15, i64 0, i64 0), i32 %161)
%163 = call i32 @exit(i32 1)
unreachable
164: ; preds = %157
br label %165
165: ; preds = %164, %150
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.16, i64 0, i64 0))
store i32 0, i32* %8
%167 = load i32*, i32** %13
%168 = call i32 @fclose(i32* %167)
br label %169
169: ; preds = %165, %84
br label %60
170: ; preds = %60
%171 = load i32, i32* %1
ret i32 %171
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [57 x i8] c"ERROR: Failed to obtain Socket Descriptor. (errno = %d)\0A\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [42 x i8] c"ERROR: Failed to bind Port. (errno = %d)\0A\00"
@.str.3 = [64 x i8] c"[TCP Server] Binded tcp port %d in addr 127.0.0.1 sucessfully.\0A\00"
@.str.4 = [44 x i8] c"ERROR: Failed to listen Port. (errno = %d)\0A\00"
@.str.5 = [50 x i8] c"[TCP Server] Listening the port %d successfully.\0A\00"
@.str.6 = [54 x i8] c"ERROR: Obtaining new Socket Despcritor. (errno = %d)\0A\00"
@.str.7 = [41 x i8] c"[Server] Server got connection from %s.\0A\00"
@.str.8 = [14 x i8] c"./receive.txt\00"
@.str.9 = [2 x i8] c"a\00"
@.str.10 = [42 x i8] c"File %s Cannot be opened file on server.\0A\00"
@.str.11 = [34 x i8] c"GOT NAME : %s, len %zd Size %d \0A\00"
@.str.12 = [30 x i8] c"File write failed on server.\0A\00"
@EAGAIN = global i32 0
@.str.15 = [33 x i8] c"recv() failed due to errno = %d\0A\00"
@str = [55 x i8] c"[TCP Server] Obtaining socket descriptor successfully.\00"
@str.17 = [25 x i8] c"Ok received from client!\00"
@str.18 = [18 x i8] c"recv() timed out.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = bitcast i32* %1 to i8*
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 3
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 4444)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %26, i32* %27
%28 = call i32 @bzero(i8* %7, i32 8)
%29 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%30 = call i32 @bind(i32 %13, %struct.sockaddr* %29, i32 4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %37
32: ; preds = %20
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %20
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i32 4444)
%39 = call i32 @listen(i32 %13, i32 5)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %37
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i32 4444)
%48 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
store i32 16, i32* %1
%49 = call i32 @accept(i32 %13, %struct.sockaddr* %48, i32* %1)
%50 = icmp eq i32 %49, -1
br i1 %50, label %53, label %51
51: ; preds = %46
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
br label %58
53: ; preds = %136, %46
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0), i32 %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %51, %136
%59 = phi i32 [ %49, %51 ], [ %137, %136 ]
%60 = load i32, i32* %52
%61 = call i8* @inet_ntoa(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %61)
%63 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%64 = icmp eq i32* %63, null
br i1 %64, label %65, label %67
65: ; preds = %58
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %136
67: ; preds = %58
%68 = call i32 @bzero(i8* %9, i32 512)
%69 = call i32 @recv(i32 %59, i8* %9, i32 512, i32 0)
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %120
71: ; preds = %67, %116
%72 = phi i32 [ %118, %116 ], [ %69, %67 ]
%73 = phi i32 [ %117, %116 ], [ 0, %67 ]
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %109
75: ; preds = %71, %98
%76 = phi i64 [ %100, %98 ], [ 0, %71 ]
%77 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = icmp eq i8 %78, 0
br i1 %79, label %102, label %80
80: ; preds = %75
%81 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %76
store i8 %78, i8* %81
%82 = or i64 %76, 1
%83 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %82
%84 = load i8, i8* %83
%85 = icmp eq i8 %84, 0
br i1 %85, label %102, label %86
86: ; preds = %80
%87 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %82
store i8 %84, i8* %87
%88 = or i64 %76, 2
%89 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %88
%90 = load i8, i8* %89
%91 = icmp eq i8 %90, 0
br i1 %91, label %102, label %92
92: ; preds = %86
%93 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %88
store i8 %90, i8* %93
%94 = or i64 %76, 3
%95 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %94
%96 = load i8, i8* %95
%97 = icmp eq i8 %96, 0
br i1 %97, label %102, label %98
98: ; preds = %92
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %94
store i8 %96, i8* %99
%100 = add nuw nsw i64 %76, 4
%101 = icmp eq i64 %100, 512
br i1 %101, label %102, label %75
102: ; preds = %98, %92, %86, %80, %75
%103 = phi i64 [ %76, %75 ], [ %82, %80 ], [ %88, %86 ], [ %94, %92 ], [ 512, %98 ]
%104 = phi i32 [ 1, %75 ], [ 1, %80 ], [ 1, %86 ], [ 1, %92 ], [ 0, %98 ]
%105 = and i64 %103, 4294967295
%106 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %105
store i8 0, i8* %106
%107 = call i32 @strlen(i8* %10)
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i8* %10, i32 %107, i32 %72)
br label %116
109: ; preds = %71
%110 = call i32 @fwrite(i8* %9, i32 1, i32 %72, i32* %63)
%111 = icmp slt i32 %110, %72
br i1 %111, label %112, label %114
112: ; preds = %109
%113 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0))
br label %114
114: ; preds = %112, %109
%115 = call i32 @bzero(i8* %9, i32 512)
br label %116
116: ; preds = %114, %102
%117 = phi i32 [ 1, %114 ], [ %104, %102 ]
%118 = call i32 @recv(i32 %59, i8* %9, i32 512, i32 0)
%119 = icmp sgt i32 %118, 0
br i1 %119, label %71, label %120
120: ; preds = %116, %67
%121 = phi i32 [ %69, %67 ], [ %118, %116 ]
%122 = icmp slt i32 %121, 0
br i1 %122, label %123, label %133
123: ; preds = %120
%124 = load i32, i32* @errno
%125 = load i32, i32* @EAGAIN
%126 = icmp eq i32 %124, %125
br i1 %126, label %127, label %129
127: ; preds = %123
%128 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.18, i64 0, i64 0))
br label %133
129: ; preds = %123
%130 = load i32, i32* @stderr
%131 = call i32 @fprintf(i32 %130, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.15, i64 0, i64 0), i32 %124)
%132 = call i32 @exit(i32 1)
unreachable
133: ; preds = %127, %120
%134 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.17, i64 0, i64 0))
%135 = call i32 @fclose(i32* %63)
br label %136
136: ; preds = %133, %65
store i32 16, i32* %1
%137 = call i32 @accept(i32 %13, %struct.sockaddr* %48, i32* %1)
%138 = icmp eq i32 %137, -1
br i1 %138, label %53, label %58
}