#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_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef scalar_t__ ssize_t;
typedef int socklen_t;
typedef scalar_t__ off_t;
typedef int /*<<< orphan*/ file_size;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_PASSIVE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fstat(int, struct stat *);
char *gai_strerror(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int getopt(int, char **, char *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int sendfile(int, int, scalar_t__ *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
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 sockfd, new_fd;
  int option_char;
  int portno = 8888;
  char port_char[15];
  int maxnpending = 5;
  struct addrinfo hints, *servinfo;
  struct sockaddr_storage their_addr;
  socklen_t sin_size;
  char message_buff[256];
  int num_bytes_total;
  int res;
  int yes;
  char ip_info[INET6_ADDRSTRLEN];
  char *filename = "bar.txt";
  FILE *file_pointer;
  int num_bytes_sent;
  int fd;
  struct stat file_stat;
  off_t offset;
  int remain_data;
  char file_size[4];
  ssize_t len;
  int sent_bytes = 0;
  while ((option_char = getopt(argc, argv, "p:f:h")) != -1) {
    switch (option_char) {
    case 'p':
      portno = atoi(optarg);
      break;
    case 'f':
      filename = optarg;
      break;
    case 'h':
      fprintf(stdout, "%s",
              "usage:\n"
              "  transferserver [options]\n"
              "options:\n"
              "  -p                  Port (Default: 8888)\n"
              "  -f                  Filename (Default: bar.txt)\n"
              "  -h                  Show this help message\n");
      exit(0);
      break;
    default:
      fprintf(stderr, "%s",
              "usage:\n"
              "  transferserver [options]\n"
              "options:\n"
              "  -p                  Port (Default: 8888)\n"
              "  -f                  Filename (Default: bar.txt)\n"
              "  -h                  Show this help message\n");
      exit(1);
    }
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  snprintf(port_char, sizeof port_char, "%d", portno);
  if ((res = getaddrinfo(NULL, port_char, &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(res));
    return 1;
  }
  printf("getaddrinfo is executed\n");
  if ((sockfd = socket(servinfo->ai_family, servinfo->ai_socktype,
                       servinfo->ai_protocol)) == -1) {
    perror("server: socket");
    exit(1);
  }
  printf("socket is created\n");
  if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
    perror("setsockopt");
    exit(1);
  }
  printf("zombies are killed\n");
  if (bind(sockfd, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
    close(sockfd);
    perror("server:bind");
    exit(1);
  }
  printf("bind to socket\n");
  if (listen(sockfd, maxnpending) == -1) {
    perror("listen");
    exit(1);
  }
  printf("server: waiting for connections...\n");
  while (1) {
    sin_size = sizeof their_addr;
    if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) ==
        -1) {
      perror("accept");
      exit(1);
    }
    inet_ntop(their_addr.ss_family, get_in_addr((struct sockaddr *)&their_addr),
              ip_info, sizeof ip_info);
    printf("server: got connection from %s\n", ip_info);
    fd = open(filename, O_RDONLY);
    if (fd == -1) {
      fprintf(stderr, "Error opening file --> %s\n", strerror(errno));
      exit(1);
    }
    if (fstat(fd, &file_stat) < 0) {
      fprintf(stderr, "Error fstat --> %s\n", strerror(errno));
      exit(1);
    }
    fprintf(stdout, "File Size: \n%d bytes \n", (int)file_stat.st_size);
    sprintf(file_size, "%d", (int)file_stat.st_size);
    len = send(new_fd, file_size, sizeof(file_size), 0);
    if (len < 0) {
      fprintf(stderr, "Error on sending greetings --> %s", strerror(errno));
      exit(1);
    }
    fprintf(stdout, "server: sent %d bytes for the size\n", (int)len);
    offset = 0;
    remain_data = file_stat.st_size;
    while (((sent_bytes = sendfile(new_fd, fd, &offset, 256)) > 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, (int)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, (int)offset, remain_data);
    }
    close(sockfd);
    close(new_fd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x22b8,-0x20(%rbp)
movl   $0x5,-0x34(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x1e0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x188(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1d8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x190(%rbp)
lea    0xd16(%rip),%rax
mov    %rax,-0x198(%rbp)
movl   $0x0,-0x1cc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xcff(%rip),%rdx
call   1120 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     13d8 <main+0x158>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x1e4(%rbp)
sub    $0x66,%eax
je     1370 <main+0xf0>
jmp    1331 <main+0xb1>
mov    -0x1e4(%rbp),%eax
sub    $0x68,%eax
je     1386 <main+0x106>
jmp    1345 <main+0xc5>
mov    -0x1e4(%rbp),%eax
sub    $0x70,%eax
jne    13ab <main+0x12b>
jmp    1359 <main+0xd9>
mov    0x2c98(%rip),%rax
mov    (%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    13d3 <main+0x153>
mov    0x2c81(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x198(%rbp)
jmp    13d3 <main+0x153>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
lea    0xc71(%rip),%rdx
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
lea    0xc4c(%rip),%rdx
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    12fb <main+0x7b>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10a0 <memset@plt>
mov    0x2bd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2bad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2bc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x2f(%rbp),%rdi
mov    -0x20(%rbp),%ecx
mov    $0xf,%esi
lea    0xca5(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x2f(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1170 <getaddrinfo@plt>
mov    %eax,-0x178(%rbp)
cmp    $0x0,%eax
je     1492 <main+0x212>
mov    0x2b61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1e8(%rbp)
mov    -0x178(%rbp),%edi
call   1090 <gai_strerror@plt>
mov    -0x1e8(%rbp),%edi
mov    %rax,%rdx
lea    0xc55(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x188(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret
lea    0xc3f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x58(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%edx
call   11a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    14dc <main+0x25c>
lea    0xc24(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xc1d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2aec(%rip),%rax
mov    (%rax),%esi
mov    0x2a93(%rip),%rax
mov    (%rax),%edx
lea    -0x17c(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1530 <main+0x2b0>
lea    0xbf2(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xbe7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x58(%rbp),%rax
mov    (%rax),%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    157a <main+0x2fa>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
lea    0xbc7(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xbbd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x34(%rbp),%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
jne    15b2 <main+0x332>
lea    0xbab(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xb9c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    15c5 <main+0x345>
movl   $0x4,-0x64(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
lea    -0x64(%rbp),%rdx
call   1130 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    15fe <main+0x37e>
lea    0xb8a(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x60(%rbp),%eax
mov    %eax,-0x1ec(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <get_in_addr@plt>
mov    -0x1ec(%rbp),%edi
mov    -0x1d8(%rbp),%rdx
mov    %eax,%esi
mov    -0x1e0(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x1d8(%rbp),%rsi
lea    0xb45(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x198(%rbp),%rdi
mov    0x2970(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x1a8(%rbp)
cmpl   $0xffffffff,-0x1a8(%rbp)
jne    16a8 <main+0x428>
mov    0x293f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1f0(%rbp)
mov    0x2920(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x1f0(%rbp),%edi
mov    %rax,%rdx
lea    0xb09(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    -0x1a8(%rbp),%edi
lea    -0x1b0(%rbp),%rsi
call   1190 <fstat@plt>
cmp    $0x0,%rax
jge    1702 <main+0x482>
mov    0x28e5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1f4(%rbp)
mov    0x28c6(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x1f4(%rbp),%edi
mov    %rax,%rdx
lea    0xaca(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    0x288f(%rip),%rax
mov    (%rax),%edi
mov    -0x1b0(%rbp),%edx
lea    0xab7(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
lea    -0x1c0(%rbp),%rdi
mov    -0x1b0(%rbp),%edx
lea    0x991(%rip),%rsi
call   1150 <sprintf@plt>
mov    -0x18(%rbp),%edi
lea    -0x1c0(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,-0x1c8(%rbp)
cmpq   $0x0,-0x1c8(%rbp)
jge    17a1 <main+0x521>
mov    0x2846(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1f8(%rbp)
mov    0x2827(%rip),%rax
mov    (%rax),%edi
call   1180 <strerror@plt>
mov    -0x1f8(%rbp),%edi
mov    %rax,%rdx
lea    0xa56(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
mov    0x27f0(%rip),%rax
mov    (%rax),%edi
mov    -0x1c8(%rbp),%rax
mov    %eax,%edx
lea    0xa4e(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movq   $0x0,-0x1b8(%rbp)
mov    -0x1b0(%rbp),%eax
mov    %eax,-0x1bc(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1a8(%rbp),%esi
lea    -0x1b8(%rbp),%rdx
mov    $0x100,%ecx
call   10e0 <sendfile@plt>
mov    %eax,%ecx
mov    %ecx,-0x1cc(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1f9(%rbp)
jle    181b <main+0x59b>
cmpl   $0x0,-0x1bc(%rbp)
setg   %al
mov    %al,-0x1f9(%rbp)
mov    -0x1f9(%rbp),%al
test   $0x1,%al
jne    182e <main+0x5ae>
jmp    18a1 <main+0x621>
mov    0x2763(%rip),%rax
mov    (%rax),%edi
mov    -0x1cc(%rbp),%edx
mov    -0x1b8(%rbp),%rax
mov    %eax,%ecx
mov    -0x1bc(%rbp),%r8d
lea    0x9d8(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x1cc(%rbp),%ecx
mov    -0x1bc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1bc(%rbp)
mov    0x2722(%rip),%rax
mov    (%rax),%edi
mov    -0x1cc(%rbp),%edx
mov    -0x1b8(%rbp),%rax
mov    %eax,%ecx
mov    -0x1bc(%rbp),%r8d
lea    0x9ec(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    17d8 <main+0x558>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
mov    -0x18(%rbp),%edi
call   10b0 <close@plt>
jmp    15c0 <main+0x340>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsp,-0x30(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x78(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    $0x22b8,%r13d
lea    0xd23(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xd20(%rip),%r15
mov    0x2d09(%rip),%r12
jmp    130c <main+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r12),%rdi
call   1150 <atoi@plt>
mov    %eax,%r13d
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1130 <getopt@plt>
cmp    $0x70,%eax
je     1300 <main+0x70>
cmp    $0xffffffff,%eax
je     1337 <main+0xa7>
cmp    $0x66,%eax
jne    13ec <main+0x15c>
mov    (%r12),%rax
mov    %rax,-0x60(%rbp)
jmp    130c <main+0x7c>
lea    -0x98(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10b0 <memset@plt>
mov    0x2c74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2c45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2c5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
lea    0xd43(%rip),%rdx
lea    -0xa7(%rbp),%rbx
mov    %rbx,%rdi
mov    $0xf,%esi
mov    %r13d,%ecx
call   1090 <snprintf@plt>
lea    -0x68(%rbp),%rcx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1180 <getaddrinfo@plt>
test   %eax,%eax
je     143e <main+0x1ae>
mov    0x2bf8(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   10a0 <gai_strerror@plt>
lea    0xcff(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    -0x30(%rbp),%rsp
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x68,%eax
jne    1416 <main+0x186>
mov    0x2ba0(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
lea    0xc06(%rip),%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1170 <exit@plt>
mov    0x2b93(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
lea    0xbe1(%rip),%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
lea    0xe1d(%rip),%rdi
call   1050 <puts@plt>
mov    -0x68(%rbp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   11b0 <socket@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
jne    1470 <main+0x1e0>
lea    0xc6d(%rip),%rdi
jmp    153a <main+0x2aa>
lea    0xe03(%rip),%rdi
call   1050 <puts@plt>
mov    0x2b5d(%rip),%rax
mov    (%rax),%esi
mov    0x2b04(%rip),%rax
mov    (%rax),%edx
lea    -0x7c(%rbp),%rcx
mov    -0x30(%rbp),%edi
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    14b1 <main+0x221>
lea    0xc3b(%rip),%rdi
jmp    153a <main+0x2aa>
lea    0xdd4(%rip),%rdi
call   1050 <puts@plt>
mov    -0x68(%rbp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    -0x30(%rbp),%edi
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
jne    14e4 <main+0x254>
mov    -0x30(%rbp),%edi
call   10c0 <close@plt>
lea    0xc10(%rip),%rdi
jmp    153a <main+0x2aa>
lea    0xdb4(%rip),%rdi
call   1050 <puts@plt>
mov    -0x30(%rbp),%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    150b <main+0x27b>
lea    0xbf5(%rip),%rdi
jmp    153a <main+0x2aa>
lea    0xd9c(%rip),%rdi
call   1050 <puts@plt>
movl   $0x4,-0x3c(%rbp)
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
mov    -0x30(%rbp),%edi
call   1140 <accept@plt>
cmp    $0xffffffff,%eax
jne    1549 <main+0x2b9>
lea    0xbcb(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1170 <exit@plt>
mov    %eax,%r12d
lea    -0x38(%rbp),%rbx
mov    0x2a41(%rip),%r15
jmp    158c <main+0x2fc>
mov    -0x30(%rbp),%ebx
mov    %ebx,%edi
call   10c0 <close@plt>
mov    %r12d,%edi
call   10c0 <close@plt>
movl   $0x4,-0x3c(%rbp)
mov    %ebx,%edi
lea    -0x38(%rbp),%rbx
mov    %rbx,%rsi
lea    -0x3c(%rbp),%rdx
call   1140 <accept@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
je     1533 <main+0x2a3>
mov    -0x38(%rbp),%r14d
mov    %rbx,%rdi
call   1040 <get_in_addr@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    -0x70(%rbp),%rbx
mov    %rbx,%rdx
mov    -0x78(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xb58(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x29fb(%rip),%rax
mov    (%rax),%esi
mov    -0x60(%rbp),%rdi
call   1110 <open@plt>
cmp    $0xffffffff,%eax
je     16d8 <main+0x448>
mov    %eax,%r14d
mov    %eax,%edi
lea    -0x50(%rbp),%rsi
call   11a0 <fstat@plt>
test   %rax,%rax
js     16f8 <main+0x468>
mov    %r12d,%ebx
mov    (%r15),%edi
mov    -0x50(%rbp),%r13d
lea    0xb5a(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
lea    -0x54(%rbp),%rdi
lea    0xaae(%rip),%rsi
mov    %r13d,%edx
call   1160 <sprintf@plt>
mov    %r12d,%edi
lea    -0x54(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
js     1718 <main+0x488>
mov    (%r15),%edi
lea    0xb50(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
movq   $0x0,-0x48(%rbp)
mov    %ebx,%edi
mov    %r14d,%esi
lea    -0x48(%rbp),%rdx
mov    $0x100,%ecx
call   10f0 <sendfile@plt>
test   %r13d,%r13d
jle    1559 <main+0x2c9>
mov    %eax,%ebx
test   %eax,%eax
jle    1559 <main+0x2c9>
mov    (%r15),%edi
mov    -0x48(%rbp),%ecx
lea    0xb30(%rip),%rsi
mov    %ebx,%edx
mov    %r13d,%r8d
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    (%r15),%edi
mov    -0x48(%rbp),%ecx
mov    %r13d,%r8d
sub    %ebx,%r8d
lea    0xb66(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %r12d,%edi
mov    %r14d,%esi
lea    -0x48(%rbp),%rdx
mov    $0x100,%ecx
call   10f0 <sendfile@plt>
sub    %ebx,%r13d
jle    1559 <main+0x2c9>
mov    %eax,%ebx
test   %eax,%eax
jg     167b <main+0x3eb>
jmp    1559 <main+0x2c9>
mov    0x28d1(%rip),%rax
mov    (%rax),%ebx
mov    0x28b8(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
lea    0xa36(%rip),%rsi
jmp    1736 <main+0x4a6>
mov    0x28b1(%rip),%rax
mov    (%rax),%ebx
mov    0x2898(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
lea    0xa31(%rip),%rsi
jmp    1736 <main+0x4a6>
mov    0x2891(%rip),%rax
mov    (%rax),%ebx
mov    0x2878(%rip),%rax
mov    (%rax),%edi
call   1190 <strerror@plt>
lea    0xa3c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    142d <main+0x19d>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [8 x i8] c"bar.txt\00"
@.str.1 = [6 x i8] c"p:f:h\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [182 x i8] c"usage:\0A transferserver [options]\0Aoptions:\0A -p Port (Default: 8888)\0A -f Filename (Default: bar.txt)\0A -h Show this help message\0A\00"
@stderr = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.6 = [25 x i8] c"getaddrinfo is executed\0A\00"
@.str.7 = [15 x i8] c"server: socket\00"
@.str.8 = [19 x i8] c"socket is created\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.9 = [11 x i8] c"setsockopt\00"
@.str.10 = [20 x i8] c"zombies are killed\0A\00"
@.str.11 = [12 x i8] c"server:bind\00"
@.str.12 = [16 x i8] c"bind to socket\0A\00"
@.str.13 = [7 x i8] c"listen\00"
@.str.14 = [36 x i8] c"server: waiting for connections...\0A\00"
@.str.15 = [7 x i8] c"accept\00"
@.str.16 = [32 x i8] c"server: got connection from %s\0A\00"
@O_RDONLY = global i32 0
@.str.17 = [27 x i8] c"Error opening file --> %s\0A\00"
@errno = global i32 0
@.str.18 = [20 x i8] c"Error fstat --> %s\0A\00"
@.str.19 = [23 x i8] c"File Size: \0A%d bytes \0A\00"
@.str.20 = [34 x i8] c"Error on sending greetings --> %s\00"
@.str.21 = [36 x i8] c"server: sent %d bytes for the size\0A\00"
@.str.22 = [85 x i8] c"1. Server sent %d bytes from file's data, offset is now: %d and remaining data = %d\0A\00"
@.str.23 = [85 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 i32
%10 = alloca [15 x i8]
%11 = alloca i32
%12 = alloca %struct.addrinfo
%13 = alloca %struct.addrinfo*
%14 = alloca %struct.sockaddr_storage
%15 = alloca i32
%16 = alloca [256 x i8]
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i64
%22 = alloca i8*
%23 = alloca i32*
%24 = alloca i32
%25 = alloca i32
%26 = alloca %struct.stat
%27 = alloca i64
%28 = alloca i32
%29 = alloca [4 x i8]
%30 = alloca i64
%31 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 8888, i32* %9
store i32 5, i32* %11
%32 = load i32, i32* @INET6_ADDRSTRLEN
%33 = zext i32 %32 to i64
%34 = call i8* @llvm.stacksave()
store i8* %34, i8** %20
%35 = alloca i8, i64 %33
store i64 %33, i64* %21
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %22
store i32 0, i32* %31
br label %36
36: ; preds = %56, %2
%37 = load i32, i32* %4
%38 = load i8**, i8*** %5
%39 = call i32 @getopt(i32 %37, i8** %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %39, i32* %8
%40 = icmp ne i32 %39, -1
br i1 %40, label %41, label %57
41: ; preds = %36
%42 = load i32, i32* %8
switch i32 %42, label %52 [
i32 112, label %43
i32 102, label %46
i32 104, label %48
]
43: ; preds = %41
%44 = load i8*, i8** @optarg
%45 = call i32 @atoi(i8* %44)
store i32 %45, i32* %9
br label %56
46: ; preds = %41
%47 = load i8*, i8** @optarg
store i8* %47, i8** %22
br label %56
48: ; preds = %41
%49 = load i32, i32* @stdout
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %41
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %46, %43
br label %36
57: ; preds = %36
%58 = call i32 @memset(%struct.addrinfo* %12, i32 0, i32 24)
%59 = load i32, i32* @AF_INET
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 4
store i32 %59, i32* %60
%61 = load i32, i32* @SOCK_STREAM
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 3
store i32 %61, i32* %62
%63 = load i32, i32* @AI_PASSIVE
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 5
store i32 %63, i32* %64
%65 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%66 = load i32, i32* %9
%67 = call i32 @snprintf(i8* %65, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %66)
%68 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%69 = call i32 @getaddrinfo(i32* null, i8* %68, %struct.addrinfo* %12, %struct.addrinfo** %13)
store i32 %69, i32* %18
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %57
%72 = load i32, i32* @stderr
%73 = load i32, i32* %18
%74 = call i8* @gai_strerror(i32 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %74)
store i32 1, i32* %3
%76 = load i8*, i8** %20
%77 = load i32, i32* %3
ret i32 %77
78: ; preds = %57
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%80 = load %struct.addrinfo*, %struct.addrinfo** %13
%81 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %80, i32 0, i32 4
%82 = load i32, i32* %81
%83 = load %struct.addrinfo*, %struct.addrinfo** %13
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %83, i32 0, i32 3
%85 = load i32, i32* %84
%86 = load %struct.addrinfo*, %struct.addrinfo** %13
%87 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %86, i32 0, i32 2
%88 = load i32, i32* %87
%89 = call i32 @socket(i32 %82, i32 %85, i32 %88)
store i32 %89, i32* %6
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %78
%92 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %78
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%96 = load i32, i32* %6
%97 = load i32, i32* @SOL_SOCKET
%98 = load i32, i32* @SO_REUSEADDR
%99 = call i32 @setsockopt(i32 %96, i32 %97, i32 %98, i32* %19, i32 4)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %104
101: ; preds = %94
%102 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%103 = call i32 @exit(i32 1)
unreachable
104: ; preds = %94
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
%106 = load i32, i32* %6
%107 = load %struct.addrinfo*, %struct.addrinfo** %13
%108 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %107, i32 0, i32 1
%109 = load i32, i32* %108
%110 = load %struct.addrinfo*, %struct.addrinfo** %13
%111 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %110, i32 0, i32 0
%112 = load i32, i32* %111
%113 = call i32 @bind(i32 %106, i32 %109, i32 %112)
%114 = icmp eq i32 %113, -1
br i1 %114, label %115, label %120
115: ; preds = %104
%116 = load i32, i32* %6
%117 = call i32 @close(i32 %116)
%118 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
%119 = call i32 @exit(i32 1)
unreachable
120: ; preds = %104
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
%122 = load i32, i32* %6
%123 = load i32, i32* %11
%124 = call i32 @listen(i32 %122, i32 %123)
%125 = icmp eq i32 %124, -1
br i1 %125, label %126, label %129
126: ; preds = %120
%127 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%128 = call i32 @exit(i32 1)
unreachable
129: ; preds = %120
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0))
br label %131
131: ; preds = %222, %129
br label %132
132: ; preds = %131
store i32 4, i32* %15
%133 = load i32, i32* %6
%134 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%135 = call i32 @accept(i32 %133, %struct.sockaddr* %134, i32* %15)
store i32 %135, i32* %7
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %140
137: ; preds = %132
%138 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%139 = call i32 @exit(i32 1)
unreachable
140: ; preds = %132
%141 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %14, i32 0, i32 0
%142 = load i32, i32* %141
%143 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%144 = call i32 @get_in_addr(%struct.sockaddr* %143)
%145 = trunc i64 %33 to i32
%146 = call i32 @inet_ntop(i32 %142, i32 %144, i8* %35, i32 %145)
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0), i8* %35)
%148 = load i8*, i8** %22
%149 = load i32, i32* @O_RDONLY
%150 = call i32 @open(i8* %148, i32 %149)
store i32 %150, i32* %25
%151 = load i32, i32* %25
%152 = icmp eq i32 %151, -1
br i1 %152, label %153, label %159
153: ; preds = %140
%154 = load i32, i32* @stderr
%155 = load i32, i32* @errno
%156 = call i8* @strerror(i32 %155)
%157 = call i32 (i32, i8*, ...) @fprintf(i32 %154, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.17, i64 0, i64 0), i8* %156)
%158 = call i32 @exit(i32 1)
unreachable
159: ; preds = %140
%160 = load i32, i32* %25
%161 = call i64 @fstat(i32 %160, %struct.stat* %26)
%162 = icmp slt i64 %161, 0
br i1 %162, label %163, label %169
163: ; preds = %159
%164 = load i32, i32* @stderr
%165 = load i32, i32* @errno
%166 = call i8* @strerror(i32 %165)
%167 = call i32 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.18, i64 0, i64 0), i8* %166)
%168 = call i32 @exit(i32 1)
unreachable
169: ; preds = %159
%170 = load i32, i32* @stdout
%171 = getelementptr inbounds %struct.stat, %struct.stat* %26, i32 0, i32 0
%172 = load i32, i32* %171
%173 = call i32 (i32, i8*, ...) @fprintf(i32 %170, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0), i32 %172)
%174 = getelementptr inbounds [4 x i8], [4 x i8]* %29, i64 0, i64 0
%175 = getelementptr inbounds %struct.stat, %struct.stat* %26, i32 0, i32 0
%176 = load i32, i32* %175
%177 = call i32 @sprintf(i8* %174, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %176)
%178 = load i32, i32* %7
%179 = getelementptr inbounds [4 x i8], [4 x i8]* %29, i64 0, i64 0
%180 = call i64 @send(i32 %178, i8* %179, i32 4, i32 0)
store i64 %180, i64* %30
%181 = load i64, i64* %30
%182 = icmp slt i64 %181, 0
br i1 %182, label %183, label %189
183: ; preds = %169
%184 = load i32, i32* @stderr
%185 = load i32, i32* @errno
%186 = call i8* @strerror(i32 %185)
%187 = call i32 (i32, i8*, ...) @fprintf(i32 %184, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.20, i64 0, i64 0), i8* %186)
%188 = call i32 @exit(i32 1)
unreachable
189: ; preds = %169
%190 = load i32, i32* @stdout
%191 = load i64, i64* %30
%192 = trunc i64 %191 to i32
%193 = call i32 (i32, i8*, ...) @fprintf(i32 %190, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.21, i64 0, i64 0), i32 %192)
store i64 0, i64* %27
%194 = getelementptr inbounds %struct.stat, %struct.stat* %26, i32 0, i32 0
%195 = load i32, i32* %194
store i32 %195, i32* %28
br label %196
196: ; preds = %206, %189
%197 = load i32, i32* %7
%198 = load i32, i32* %25
%199 = call i32 @sendfile(i32 %197, i32 %198, i64* %27, i32 256)
store i32 %199, i32* %31
%200 = icmp sgt i32 %199, 0
br i1 %200, label %201, label %204
201: ; preds = %196
%202 = load i32, i32* %28
%203 = icmp sgt i32 %202, 0
br label %204
204: ; preds = %201, %196
%205 = phi i1 [ false, %196 ], [ %203, %201 ]
br i1 %205, label %206, label %222
206: ; preds = %204
%207 = load i32, i32* @stdout
%208 = load i32, i32* %31
%209 = load i64, i64* %27
%210 = trunc i64 %209 to i32
%211 = load i32, i32* %28
%212 = call i32 (i32, i8*, ...) @fprintf(i32 %207, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.22, i64 0, i64 0), i32 %208, i32 %210, i32 %211)
%213 = load i32, i32* %31
%214 = load i32, i32* %28
%215 = sub nsw i32 %214, %213
store i32 %215, i32* %28
%216 = load i32, i32* @stdout
%217 = load i32, i32* %31
%218 = load i64, i64* %27
%219 = trunc i64 %218 to i32
%220 = load i32, i32* %28
%221 = call i32 (i32, i8*, ...) @fprintf(i32 %216, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.23, i64 0, i64 0), i32 %217, i32 %219, i32 %220)
br label %196
222: ; preds = %204
%223 = load i32, i32* %6
%224 = call i32 @close(i32 %223)
%225 = load i32, i32* %7
%226 = call i32 @close(i32 %225)
br label %131
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [8 x i8] c"bar.txt\00"
@.str.1 = [6 x i8] c"p:f:h\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [182 x i8] c"usage:\0A transferserver [options]\0Aoptions:\0A -p Port (Default: 8888)\0A -f Filename (Default: bar.txt)\0A -h Show this help message\0A\00"
@stderr = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.7 = [15 x i8] c"server: socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.9 = [11 x i8] c"setsockopt\00"
@.str.11 = [12 x i8] c"server:bind\00"
@.str.13 = [7 x i8] c"listen\00"
@.str.15 = [7 x i8] c"accept\00"
@.str.16 = [32 x i8] c"server: got connection from %s\0A\00"
@O_RDONLY = global i32 0
@.str.17 = [27 x i8] c"Error opening file --> %s\0A\00"
@errno = global i32 0
@.str.18 = [20 x i8] c"Error fstat --> %s\0A\00"
@.str.19 = [23 x i8] c"File Size: \0A%d bytes \0A\00"
@.str.20 = [34 x i8] c"Error on sending greetings --> %s\00"
@.str.21 = [36 x i8] c"server: sent %d bytes for the size\0A\00"
@.str.22 = [85 x i8] c"1. Server sent %d bytes from file's data, offset is now: %d and remaining data = %d\0A\00"
@.str.23 = [85 x i8] c"2. Server sent %d bytes from file's data, offset is now: %d and remaining data = %d\0A\00"
@str = [24 x i8] c"getaddrinfo is executed\00"
@str.24 = [18 x i8] c"socket is created\00"
@str.25 = [19 x i8] c"zombies are killed\00"
@str.26 = [15 x i8] c"bind to socket\00"
@str.27 = [35 x i8] c"server: waiting for connections...\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [15 x i8]
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.stat
%10 = alloca i64
%11 = alloca [4 x i8]
%12 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%13 = bitcast %struct.addrinfo* %4 to i8*
%14 = bitcast %struct.addrinfo** %5 to i8*
%15 = bitcast %struct.sockaddr_storage* %6 to i8*
%16 = bitcast i32* %7 to i8*
%17 = bitcast i32* %8 to i8*
%18 = load i32, i32* @INET6_ADDRSTRLEN
%19 = zext i32 %18 to i64
%20 = tail call i8* @llvm.stacksave()
%21 = alloca i8, i64 %19
%22 = bitcast %struct.stat* %9 to i8*
%23 = bitcast i64* %10 to i8*
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
br label %25
25: ; preds = %34, %2
%26 = phi i8* [ %35, %34 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %2 ]
%27 = phi i32 [ %29, %34 ], [ 8888, %2 ]
br label %28
28: ; preds = %25, %31
%29 = phi i32 [ %33, %31 ], [ %27, %25 ]
%30 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
switch i32 %30, label %40 [
i32 -1, label %44
i32 112, label %31
i32 102, label %34
i32 104, label %36
]
31: ; preds = %28
%32 = load i8*, i8** @optarg
%33 = tail call i32 @atoi(i8* %32)
br label %28
34: ; preds = %28
%35 = load i8*, i8** @optarg
br label %25
36: ; preds = %28
%37 = load i32, i32* @stdout
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.3, i64 0, i64 0))
%39 = tail call i32 @exit(i32 0)
unreachable
40: ; preds = %28
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.3, i64 0, i64 0))
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %28
%45 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 24)
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %46, i32* %47
%48 = load i32, i32* @SOCK_STREAM
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %48, i32* %49
%50 = load i32, i32* @AI_PASSIVE
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 5
store i32 %50, i32* %51
%52 = call i32 @snprintf(i8* %12, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%53 = call i32 @getaddrinfo(i32* null, i8* %12, %struct.addrinfo* %4, %struct.addrinfo** %5)
%54 = icmp eq i32 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %44
%56 = load i32, i32* @stderr
%57 = call i8* @gai_strerror(i32 %53)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %57)
ret i32 1
59: ; preds = %44
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%61 = load %struct.addrinfo*, %struct.addrinfo** %5
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i64 0, i32 4
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i64 0, i32 3
%65 = load i32, i32* %64
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i64 0, i32 2
%67 = load i32, i32* %66
%68 = call i32 @socket(i32 %63, i32 %65, i32 %67)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %59
%71 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %59
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.24, i64 0, i64 0))
%75 = load i32, i32* @SOL_SOCKET
%76 = load i32, i32* @SO_REUSEADDR
%77 = call i32 @setsockopt(i32 %68, i32 %75, i32 %76, i32* %8, i32 4)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %82
79: ; preds = %73
%80 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %73
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.25, i64 0, i64 0))
%84 = load %struct.addrinfo*, %struct.addrinfo** %5
%85 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %84, i64 0, i32 1
%86 = load i32, i32* %85
%87 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %84, i64 0, i32 0
%88 = load i32, i32* %87
%89 = call i32 @bind(i32 %68, i32 %86, i32 %88)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %95
91: ; preds = %82
%92 = call i32 @close(i32 %68)
%93 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %82
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.26, i64 0, i64 0))
%97 = call i32 @listen(i32 %68, i32 5)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %102
99: ; preds = %95
%100 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %95
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.27, i64 0, i64 0))
%104 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
store i32 4, i32* %7
%105 = call i32 @accept(i32 %68, %struct.sockaddr* %104, i32* %7)
%106 = icmp eq i32 %105, -1
br i1 %106, label %110, label %107
107: ; preds = %102
%108 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %6, i64 0, i32 0
%109 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 0
br label %113
110: ; preds = %174, %102
%111 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %107, %174
%114 = phi i32 [ %105, %107 ], [ %177, %174 ]
%115 = load i32, i32* %108
%116 = call i32 @get_in_addr(%struct.sockaddr* %104)
%117 = call i32 @inet_ntop(i32 %115, i32 %116, i8* %21, i32 %18)
%118 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0), i8* %21)
%119 = load i32, i32* @O_RDONLY
%120 = call i32 @open(i8* %26, i32 %119)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %128
122: ; preds = %113
%123 = load i32, i32* @stderr
%124 = load i32, i32* @errno
%125 = call i8* @strerror(i32 %124)
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.17, i64 0, i64 0), i8* %125)
%127 = call i32 @exit(i32 1)
unreachable
128: ; preds = %113
%129 = call i64 @fstat(i32 %120, %struct.stat* %9)
%130 = icmp slt i64 %129, 0
br i1 %130, label %131, label %137
131: ; preds = %128
%132 = load i32, i32* @stderr
%133 = load i32, i32* @errno
%134 = call i8* @strerror(i32 %133)
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.18, i64 0, i64 0), i8* %134)
%136 = call i32 @exit(i32 1)
unreachable
137: ; preds = %128
%138 = load i32, i32* @stdout
%139 = load i32, i32* %109
%140 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0), i32 %139)
%141 = call i32 @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %139)
%142 = call i64 @send(i32 %114, i8* %24, i32 4, i32 0)
%143 = icmp slt i64 %142, 0
br i1 %143, label %144, label %150
144: ; preds = %137
%145 = load i32, i32* @stderr
%146 = load i32, i32* @errno
%147 = call i8* @strerror(i32 %146)
%148 = call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.20, i64 0, i64 0), i8* %147)
%149 = call i32 @exit(i32 1)
unreachable
150: ; preds = %137
%151 = load i32, i32* @stdout
%152 = trunc i64 %142 to i32
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.21, i64 0, i64 0), i32 %152)
store i64 0, i64* %10
%154 = call i32 @sendfile(i32 %114, i32 %120, i64* %10, i32 256)
%155 = icmp sgt i32 %154, 0
%156 = icmp sgt i32 %139, 0
%157 = and i1 %156, %155
br i1 %157, label %158, label %174
158: ; preds = %150, %158
%159 = phi i32 [ %170, %158 ], [ %154, %150 ]
%160 = phi i32 [ %165, %158 ], [ %139, %150 ]
%161 = load i32, i32* @stdout
%162 = load i64, i64* %10
%163 = trunc i64 %162 to i32
%164 = call i32 (i32, i8*, ...) @fprintf(i32 %161, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.22, i64 0, i64 0), i32 %159, i32 %163, i32 %160)
%165 = sub nsw i32 %160, %159
%166 = load i32, i32* @stdout
%167 = load i64, i64* %10
%168 = trunc i64 %167 to i32
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %166, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.23, i64 0, i64 0), i32 %159, i32 %168, i32 %165)
%170 = call i32 @sendfile(i32 %114, i32 %120, i64* %10, i32 256)
%171 = icmp sgt i32 %170, 0
%172 = icmp sgt i32 %165, 0
%173 = and i1 %172, %171
br i1 %173, label %158, label %174
174: ; preds = %158, %150
%175 = call i32 @close(i32 %68)
%176 = call i32 @close(i32 %114)
store i32 4, i32* %7
%177 = call i32 @accept(i32 %68, %struct.sockaddr* %104, i32* %7)
%178 = icmp eq i32 %177, -1
br i1 %178, label %110, label %113
}