#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 */

/* Type definitions */
struct stat {
  int st_size;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ server_addr;
typedef int off_t;
typedef int /*<<< orphan*/ file_size;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int sendfile(int, int, int *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int server_socket;
  int peer_socket;
  socklen_t sock_len;
  ssize_t len;
  struct sockaddr_in server_addr;
  struct sockaddr_in peer_addr;
  int fd;
  int sent_bytes = 0;
  char file_size[256];
  struct stat file_stat;
  off_t offset;
  int remain_data;
  server_socket = socket(AF_INET, SOCK_STREAM, 0);
  if (server_socket == -1) {
    fprintf(stderr, "Error creating socket --> %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  memset(&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  inet_pton(AF_INET, "127.0.0.1", &(server_addr.sin_addr));
  server_addr.sin_port = htons(5000);
  if ((bind(server_socket, (struct sockaddr *)&server_addr,
            sizeof(struct sockaddr))) == -1) {
    fprintf(stderr, "Error on bind --> %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((listen(server_socket, 5)) == -1) {
    fprintf(stderr, "Error on listen --> %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  fd = open("server_side.txt", O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "Error opening file --> %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (fstat(fd, &file_stat) < 0) {
    fprintf(stderr, "Error fstat --> %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "File Size: \n%d bytes\n", file_stat.st_size);
  sock_len = sizeof(struct sockaddr_in);
  peer_socket = accept(server_socket, (struct sockaddr *)&peer_addr, &sock_len);
  if (peer_socket == -1) {
    fprintf(stderr, "Error on accept --> %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "Accept peer --> %s\n", inet_ntoa(peer_addr.sin_addr));
  sprintf(file_size, "%d", file_stat.st_size);
  len = send(peer_socket, file_size, sizeof(file_size), 0);
  if (len < 0) {
    fprintf(stderr, "Error on sending greetings --> %s", strerror(errno));
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "Server sent %d bytes for the size\n", len);
  offset = 0;
  remain_data = file_stat.st_size;
  while (((sent_bytes = sendfile(peer_socket, fd, &offset, BUFSIZ)) > 0) &&
         (remain_data > 0)) {
    fprintf(stdout,
            "1. Server sent %d bytes from file's data, offset is now : %d and "
            "remaining data = %d\n",
            sent_bytes, offset, remain_data);
    remain_data -= sent_bytes;
    fprintf(stdout,
            "2. Server sent %d bytes from file's data, offset is now : %d and "
            "remaining data = %d\n",
            sent_bytes, offset, remain_data);
  }
  close(peer_socket);
  close(server_socket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x50(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1298 <main+0x88>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x164(%rbp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x164(%rbp),%edi
mov    %rax,%rdx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rdx
lea    0xd55(%rip),%rsi
call   1090 <inet_pton@plt>
mov    $0x1388,%edi
call   1040 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1336 <main+0x126>
mov    0x2cd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x168(%rbp)
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x168(%rbp),%edi
mov    %rax,%rdx
lea    0xd06(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    138e <main+0x17e>
mov    0x2c7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x16c(%rbp)
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x16c(%rbp),%edi
mov    %rax,%rdx
lea    0xcc3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c29(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2c4b(%rip),%rax
mov    (%rax),%esi
lea    0xcb5(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    13f2 <main+0x1e2>
mov    0x2c19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x170(%rbp)
mov    0x2bf2(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x170(%rbp),%edi
mov    %rax,%rdx
lea    0xc86(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2bc5(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x4c(%rbp),%edi
lea    -0x158(%rbp),%rsi
call   1120 <fstat@plt>
cmp    $0x0,%rax
jge    144d <main+0x23d>
mov    0x2bbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x174(%rbp)
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x174(%rbp),%edi
mov    %rax,%rdx
lea    0xc45(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2b54(%rip),%rax
mov    (%rax),%edi
mov    -0x158(%rbp),%edx
lea    0xc2d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xc,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    14d0 <main+0x2c0>
mov    0x2b3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x178(%rbp)
mov    0x2b14(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x178(%rbp),%edi
mov    %rax,%rdx
lea    0xbeb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2ae7(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2ad1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x17c(%rbp)
mov    -0x48(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    -0x17c(%rbp),%edi
mov    %rax,%rdx
lea    0xbc6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x150(%rbp),%rdi
mov    -0x158(%rbp),%edx
lea    0xbbf(%rip),%rsi
call   10f0 <sprintf@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    157e <main+0x36e>
mov    0x2a8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x180(%rbp)
mov    0x2a66(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x180(%rbp),%edi
mov    %rax,%rdx
lea    0xb6b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a39(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2a23(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xb64(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x15c(%rbp)
mov    -0x158(%rbp),%eax
mov    %eax,-0x160(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x4c(%rbp),%esi
mov    0x2a04(%rip),%rax
mov    (%rax),%ecx
lea    -0x15c(%rbp),%rdx
call   10b0 <sendfile@plt>
mov    %eax,%ecx
mov    %ecx,-0x50(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x181(%rbp)
jle    15f0 <main+0x3e0>
cmpl   $0x0,-0x160(%rbp)
setg   %al
mov    %al,-0x181(%rbp)
mov    -0x181(%rbp),%al
test   $0x1,%al
jne    1603 <main+0x3f3>
jmp    1667 <main+0x457>
mov    0x299e(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%edx
mov    -0x15c(%rbp),%ecx
mov    -0x160(%rbp),%r8d
lea    0xaf6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x50(%rbp),%ecx
mov    -0x160(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x160(%rbp)
mov    0x2966(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%edx
mov    -0x15c(%rbp),%ecx
mov    -0x160(%rbp),%r8d
lea    0xb14(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    15af <main+0x39f>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    0x2dc0(%rip),%r14
mov    (%r14),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
je     1446 <main+0x236>
mov    %eax,%ebp
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r14),%edi
mov    %edi,0x28(%rsp)
lea    0xdb5(%rip),%rsi
mov    %rbx,%rdx
call   1090 <inet_pton@plt>
mov    $0x1388,%edi
call   1040 <htons@plt>
mov    %eax,0x24(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
je     1469 <main+0x259>
mov    %ebp,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
je     148c <main+0x27c>
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
lea    0xd98(%rip),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     14ac <main+0x29c>
mov    %eax,%r15d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1120 <fstat@plt>
test   %rax,%rax
js     14cc <main+0x2bc>
mov    0x2cc0(%rip),%r14
mov    (%r14),%edi
mov    0x10(%rsp),%ebx
lea    0xd9a(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
movl   $0xc,0x1c(%rsp)
lea    0x30(%rsp),%rsi
lea    0x1c(%rsp),%rdx
mov    %ebp,%edi
call   10e0 <accept@plt>
cmp    $0xffffffff,%eax
je     14ec <main+0x2dc>
mov    %eax,%r12d
mov    %ebp,0x18(%rsp)
mov    (%r14),%ebp
mov    0x30(%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0xd82(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xd83(%rip),%rsi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
call   10f0 <sprintf@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %rax,%rax
js     150c <main+0x2fc>
mov    (%r14),%edi
lea    0xd74(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
movl   $0x0,0xc(%rsp)
mov    0x2c25(%rip),%rax
mov    (%rax),%ecx
lea    0xc(%rsp),%rdx
mov    %r12d,%edi
mov    %r15d,%r14d
mov    %r15d,%esi
call   10b0 <sendfile@plt>
test   %ebx,%ebx
jle    1421 <main+0x211>
mov    %eax,%ebp
test   %eax,%eax
jle    1421 <main+0x211>
lea    0xc(%rsp),%r15
nop
mov    0x2be1(%rip),%r13
mov    0x0(%r13),%edi
mov    0xc(%rsp),%ecx
lea    0xd43(%rip),%rsi
mov    %ebp,%edx
mov    %ebx,%r8d
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x0(%r13),%edi
mov    0xc(%rsp),%ecx
mov    %ebx,%r8d
sub    %ebp,%r8d
lea    0xd78(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2bb9(%rip),%rax
mov    (%rax),%ecx
mov    %r12d,%edi
mov    %r14d,%esi
mov    %r15,%rdx
call   10b0 <sendfile@plt>
sub    %ebp,%ebx
jle    1421 <main+0x211>
mov    %eax,%ebp
test   %eax,%eax
jg     13c0 <main+0x1b0>
mov    %r12d,%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b83(%rip),%rax
mov    (%rax),%ebx
mov    0x2b62(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xb9c(%rip),%rsi
jmp    152a <main+0x31a>
mov    0x2b60(%rip),%rax
mov    (%rax),%ebx
mov    0x2b3f(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xba0(%rip),%rsi
jmp    152a <main+0x31a>
mov    0x2b3d(%rip),%rax
mov    (%rax),%ebx
mov    0x2b1c(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xb92(%rip),%rsi
jmp    152a <main+0x31a>
mov    0x2b1d(%rip),%rax
mov    (%rax),%ebx
mov    0x2afc(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xb99(%rip),%rsi
jmp    152a <main+0x31a>
mov    0x2afd(%rip),%rax
mov    (%rax),%ebx
mov    0x2adc(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xb93(%rip),%rsi
jmp    152a <main+0x31a>
mov    0x2add(%rip),%rax
mov    (%rax),%ebx
mov    0x2abc(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xb9c(%rip),%rsi
jmp    152a <main+0x31a>
mov    0x2abd(%rip),%rax
mov    (%rax),%ebx
mov    0x2a9c(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xbaa(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2a73(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Error creating socket --> %s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [21 x i8] c"Error on bind --> %s\00"
@.str.3 = [23 x i8] c"Error on listen --> %s\00"
@.str.4 = [16 x i8] c"server_side.txt\00"
@O_RDONLY = global i32 0
@.str.5 = [26 x i8] c"Error opening file --> %s\00"
@.str.6 = [19 x i8] c"Error fstat --> %s\00"
@stdout = global i32 0
@.str.7 = [22 x i8] c"File Size: \0A%d bytes\0A\00"
@.str.8 = [23 x i8] c"Error on accept --> %s\00"
@.str.9 = [20 x i8] c"Accept peer --> %s\0A\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [34 x i8] c"Error on sending greetings --> %s\00"
@.str.12 = [35 x i8] c"Server sent %d bytes for the size\0A\00"
@BUFSIZ = global i32 0
@.str.13 = [86 x i8] c"1. Server sent %d bytes from file's data, offset is now : %d and remaining data = %d\0A\00"
@.str.14 = [86 x i8] c"2. Server sent %d bytes from file's data, offset is now : %d and remaining data = %d\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 i64
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i32
%14 = alloca [256 x i8]
%15 = alloca %struct.stat
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %13
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %2
%31 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 12)
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%36 = call i32 @inet_pton(i32 %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %35)
%37 = call i32 @htons(i32 5000)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %37, i32* %38
%39 = load i32, i32* %6
%40 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%41 = call i32 @bind(i32 %39, %struct.sockaddr* %40, i32 4)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %50
43: ; preds = %30
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %30
%51 = load i32, i32* %6
%52 = call i32 @listen(i32 %51, i32 5)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %61
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %50
%62 = load i32, i32* @O_RDONLY
%63 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %62)
store i32 %63, i32* %12
%64 = load i32, i32* %12
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %73
66: ; preds = %61
%67 = load i32, i32* @stderr
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %61
%74 = load i32, i32* %12
%75 = call i64 @fstat(i32 %74, %struct.stat* %15)
%76 = icmp slt i64 %75, 0
br i1 %76, label %77, label %84
77: ; preds = %73
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %80)
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %73
%85 = load i32, i32* @stdout
%86 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
%87 = load i32, i32* %86
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %87)
store i32 12, i32* %8
%89 = load i32, i32* %6
%90 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%91 = call i32 @accept(i32 %89, %struct.sockaddr* %90, i32* %8)
store i32 %91, i32* %7
%92 = load i32, i32* %7
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %101
94: ; preds = %84
%95 = load i32, i32* @stderr
%96 = load i32, i32* @errno
%97 = call i8* @strerror(i32 %96)
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %97)
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %84
%102 = load i32, i32* @stdout
%103 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%104 = load i32, i32* %103
%105 = call i8* @inet_ntoa(i32 %104)
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %105)
%107 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%108 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
%109 = load i32, i32* %108
%110 = call i32 @sprintf(i8* %107, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %109)
%111 = load i32, i32* %7
%112 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%113 = call i64 @send(i32 %111, i8* %112, i32 256, i32 0)
store i64 %113, i64* %9
%114 = load i64, i64* %9
%115 = icmp slt i64 %114, 0
br i1 %115, label %116, label %123
116: ; preds = %101
%117 = load i32, i32* @stderr
%118 = load i32, i32* @errno
%119 = call i8* @strerror(i32 %118)
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i8* %119)
%121 = load i32, i32* @EXIT_FAILURE
%122 = call i32 @exit(i32 %121)
unreachable
123: ; preds = %101
%124 = load i32, i32* @stdout
%125 = load i64, i64* %9
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), i64 %125)
store i32 0, i32* %16
%127 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
%128 = load i32, i32* %127
store i32 %128, i32* %17
br label %129
129: ; preds = %140, %123
%130 = load i32, i32* %7
%131 = load i32, i32* %12
%132 = load i32, i32* @BUFSIZ
%133 = call i32 @sendfile(i32 %130, i32 %131, i32* %16, i32 %132)
store i32 %133, i32* %13
%134 = icmp sgt i32 %133, 0
br i1 %134, label %135, label %138
135: ; preds = %129
%136 = load i32, i32* %17
%137 = icmp sgt i32 %136, 0
br label %138
138: ; preds = %135, %129
%139 = phi i1 [ false, %129 ], [ %137, %135 ]
br i1 %139, label %140, label %154
140: ; preds = %138
%141 = load i32, i32* @stdout
%142 = load i32, i32* %13
%143 = load i32, i32* %16
%144 = load i32, i32* %17
%145 = call i32 (i32, i8*, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.13, i64 0, i64 0), i32 %142, i32 %143, i32 %144)
%146 = load i32, i32* %13
%147 = load i32, i32* %17
%148 = sub nsw i32 %147, %146
store i32 %148, i32* %17
%149 = load i32, i32* @stdout
%150 = load i32, i32* %13
%151 = load i32, i32* %16
%152 = load i32, i32* %17
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.14, i64 0, i64 0), i32 %150, i32 %151, i32 %152)
br label %129
154: ; preds = %138
%155 = load i32, i32* %7
%156 = call i32 @close(i32 %155)
%157 = load i32, i32* %6
%158 = call i32 @close(i32 %157)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Error creating socket --> %s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [21 x i8] c"Error on bind --> %s\00"
@.str.3 = [23 x i8] c"Error on listen --> %s\00"
@.str.4 = [16 x i8] c"server_side.txt\00"
@O_RDONLY = global i32 0
@.str.5 = [26 x i8] c"Error opening file --> %s\00"
@.str.6 = [19 x i8] c"Error fstat --> %s\00"
@stdout = global i32 0
@.str.7 = [22 x i8] c"File Size: \0A%d bytes\0A\00"
@.str.8 = [23 x i8] c"Error on accept --> %s\00"
@.str.9 = [20 x i8] c"Accept peer --> %s\0A\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [34 x i8] c"Error on sending greetings --> %s\00"
@.str.12 = [35 x i8] c"Server sent %d bytes for the size\0A\00"
@BUFSIZ = global i32 0
@.str.13 = [86 x i8] c"1. Server sent %d bytes from file's data, offset is now : %d and remaining data = %d\0A\00"
@.str.14 = [86 x i8] c"2. Server sent %d bytes from file's data, offset is now : %d and remaining data = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [256 x i8]
%7 = alloca %struct.stat
%8 = alloca i32
%9 = bitcast i32* %3 to i8*
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = bitcast %struct.stat* %7 to i8*
%14 = bitcast i32* %8 to i8*
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %2
%27 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%31 = call i32 @inet_pton(i32 %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %30)
%32 = call i32 @htons(i32 5000)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i32 @bind(i32 %17, %struct.sockaddr* %34, i32 4)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %44
37: ; preds = %26
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %26
%45 = call i32 @listen(i32 %17, i32 5)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %44
%55 = load i32, i32* @O_RDONLY
%56 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %65
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %54
%66 = call i64 @fstat(i32 %56, %struct.stat* %7)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %75
68: ; preds = %65
%69 = load i32, i32* @stderr
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %71)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %65
%76 = load i32, i32* @stdout
%77 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%78 = load i32, i32* %77
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %78)
store i32 12, i32* %3
%80 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%81 = call i32 @accept(i32 %17, %struct.sockaddr* %80, i32* %3)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %90
83: ; preds = %75
%84 = load i32, i32* @stderr
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %86)
%88 = load i32, i32* @EXIT_FAILURE
%89 = call i32 @exit(i32 %88)
unreachable
90: ; preds = %75
%91 = load i32, i32* @stdout
%92 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%93 = load i32, i32* %92
%94 = call i8* @inet_ntoa(i32 %93)
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %94)
%96 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %78)
%97 = call i64 @send(i32 %81, i8* %12, i32 256, i32 0)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %106
99: ; preds = %90
%100 = load i32, i32* @stderr
%101 = load i32, i32* @errno
%102 = call i8* @strerror(i32 %101)
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0), i8* %102)
%104 = load i32, i32* @EXIT_FAILURE
%105 = call i32 @exit(i32 %104)
unreachable
106: ; preds = %90
%107 = load i32, i32* @stdout
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), i64 %97)
store i32 0, i32* %8
%109 = load i32, i32* @BUFSIZ
%110 = call i32 @sendfile(i32 %81, i32 %56, i32* %8, i32 %109)
%111 = icmp sgt i32 %110, 0
%112 = icmp sgt i32 %78, 0
%113 = and i1 %112, %111
br i1 %113, label %114, label %129
114: ; preds = %106, %114
%115 = phi i32 [ %125, %114 ], [ %110, %106 ]
%116 = phi i32 [ %120, %114 ], [ %78, %106 ]
%117 = load i32, i32* @stdout
%118 = load i32, i32* %8
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.13, i64 0, i64 0), i32 %115, i32 %118, i32 %116)
%120 = sub nsw i32 %116, %115
%121 = load i32, i32* @stdout
%122 = load i32, i32* %8
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.14, i64 0, i64 0), i32 %115, i32 %122, i32 %120)
%124 = load i32, i32* @BUFSIZ
%125 = call i32 @sendfile(i32 %81, i32 %56, i32* %8, i32 %124)
%126 = icmp sgt i32 %125, 0
%127 = icmp sgt i32 %120, 0
%128 = and i1 %127, %126
br i1 %128, label %114, label %129
129: ; preds = %114, %106
%130 = call i32 @close(i32 %81)
%131 = call i32 @close(i32 %17)
ret i32 0
}