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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
void *atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fwrite(char *, int, scalar_t__, int /*<<< orphan*/ *);
char *gai_strerror(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int getopt(int, char **, char *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned short);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sockfd;
  int option_char = 0;
  char *hostname = "localhost";
  unsigned short portno = 8888;
  char port_char[15];
  char *message = "Hello World!";
  char message_buff[256];
  int num_bytes_received;
  char ip_info[INET6_ADDRSTRLEN];
  struct addrinfo hints, *servinfo;
  int res;
  char *filename = "foo.txt";
  char buffer[256];
  ssize_t len;
  int file_size;
  FILE *received_file;
  int remain_data = 0;
  while ((option_char = getopt(argc, argv, "s:p:o:h")) != -1) {
    switch (option_char) {
    case 's':
      hostname = optarg;
      break;
    case 'p':
      portno = atoi(optarg);
      break;
    case 'o':
      filename = optarg;
      break;
    case 'h':
      fprintf(stdout, "%s",
              "usage:\n"
              "  transferclient [options]\n"
              "options:\n"
              "  -s                  Server (Default: localhost)\n"
              "  -p                  Port (Default: 8888)\n"
              "  -o                  Output file (Default foo.txt)\n"
              "  -h                  Show this help message\n");
      exit(0);
      break;
    default:
      fprintf(stderr, "%s",
              "usage:\n"
              "  transferclient [options]\n"
              "options:\n"
              "  -s                  Server (Default: localhost)\n"
              "  -p                  Port (Default: 8888)\n"
              "  -o                  Output file (Default foo.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;
  snprintf(port_char, sizeof port_char, "%d", portno);
  if ((res = getaddrinfo(hostname, 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("client: socket");
    exit(1);
  }
  printf("socket is created\n");
  if (connect(sockfd, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
    close(sockfd);
    perror("client: connect");
    exit(1);
  }
  inet_ntop(servinfo->ai_family,
            get_in_addr((struct sockaddr *)servinfo->ai_addr), ip_info,
            sizeof ip_info);
  printf("client: connecting to %s\n", ip_info);
  recv(sockfd, buffer, 256, 0);
  file_size = atoi(buffer);
  fprintf(stdout, "\nFile size: %d\n", file_size);
  received_file = fopen(filename, "w");
  if (received_file == NULL) {
    fprintf(stderr, "Failed to open file foo --> %s\n", strerror(errno));
    exit(1);
  }
  remain_data = file_size;
  while (((len = recv(sockfd, buffer, 256, 0)) > 0) && (remain_data > 0)) {
    fwrite(buffer, sizeof(char), len, received_file);
    remain_data -= len;
    fprintf(stdout, "Received %d bytes and we hope: - %d bytes\n", (int)len,
            remain_data);
  }
  fclose(received_file);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xdc9(%rip),%rax
mov    %rax,-0x20(%rbp)
movw   $0x22b8,-0x22(%rbp)
lea    0xdc2(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x2c0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x150(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x2b8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x158(%rbp)
lea    0xd88(%rip),%rax
mov    %rax,-0x188(%rbp)
movl   $0x0,-0x2ac(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd71(%rip),%rdx
call   10f0 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     13b1 <main+0x171>
mov    -0x18(%rbp),%eax
add    $0xffffff98,%eax
mov    %eax,%ecx
mov    %rcx,-0x2c8(%rbp)
sub    $0xb,%eax
ja     1384 <main+0x144>
mov    -0x2c8(%rbp),%rax
lea    0xceb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2cd3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    13ac <main+0x16c>
mov    0x2cc0(%rip),%rax
mov    (%rax),%rdi
call   1100 <atoi@plt>
mov    %ax,-0x22(%rbp)
jmp    13ac <main+0x16c>
mov    0x2ca8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x188(%rbp)
jmp    13ac <main+0x16c>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
lea    0xce8(%rip),%rsi
lea    0xce4(%rip),%rdx
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
lea    0xcc3(%rip),%rsi
lea    0xcbf(%rip),%rdx
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
jmp    12d0 <main+0x90>
lea    -0x170(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10a0 <memset@plt>
mov    0x2c0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x168(%rbp)
mov    0x2be6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x15c(%rbp)
lea    -0x31(%rbp),%rdi
mov    $0xf,%esi
lea    0xd52(%rip),%rdx
movzwl -0x22(%rbp),%ecx
call   1080 <snprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x31(%rbp),%rsi
lea    -0x170(%rbp),%rdx
lea    -0x178(%rbp),%rcx
call   1140 <getaddrinfo@plt>
mov    %eax,-0x17c(%rbp)
cmp    $0x0,%eax
je     146c <main+0x22c>
mov    0x2b9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2cc(%rbp)
mov    -0x17c(%rbp),%edi
call   1090 <gai_strerror@plt>
mov    -0x2cc(%rbp),%edi
mov    %rax,%rdx
lea    0xcf8(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2b0(%rbp)
jmp    16f3 <main+0x4b3>
lea    0xce5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x178(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x178(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x178(%rbp),%rax
mov    0x10(%rax),%edx
call   1160 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    14bf <main+0x27f>
lea    0xcc1(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x178(%rbp),%rax
mov    (%rax),%rsi
mov    -0x178(%rbp),%rax
mov    0xc(%rax),%edx
call   1120 <connect@plt>
cmp    $0xffffffff,%eax
jne    1510 <main+0x2d0>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
lea    0xc92(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x178(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x2d0(%rbp)
mov    -0x178(%rbp),%rax
mov    (%rax),%rdi
call   1050 <get_in_addr@plt>
mov    -0x2d0(%rbp),%edi
mov    -0x2b8(%rbp),%rdx
mov    %eax,%esi
mov    -0x2c0(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x2b8(%rbp),%rsi
lea    0xc49(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x290(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
lea    -0x290(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x29c(%rbp)
mov    0x2a20(%rip),%rax
mov    (%rax),%edi
mov    -0x29c(%rbp),%edx
lea    0xc1e(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x188(%rbp),%rdi
lea    0xc19(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x2a8(%rbp)
cmpq   $0x0,-0x2a8(%rbp)
jne    160c <main+0x3cc>
mov    0x29f3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2d4(%rbp)
mov    0x29d4(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x2d4(%rbp),%edi
mov    %rax,%rdx
lea    0xbd4(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x29c(%rbp),%eax
mov    %eax,-0x2ac(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x290(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %rax,%rcx
mov    %rcx,-0x298(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2d5(%rbp)
jle    165a <main+0x41a>
cmpl   $0x0,-0x2ac(%rbp)
setg   %al
mov    %al,-0x2d5(%rbp)
mov    -0x2d5(%rbp),%al
test   $0x1,%al
jne    166d <main+0x42d>
jmp    16ce <main+0x48e>
lea    -0x290(%rbp),%rdi
mov    -0x298(%rbp),%rdx
mov    -0x2a8(%rbp),%rcx
mov    $0x1,%esi
call   1130 <fwrite@plt>
mov    -0x298(%rbp),%rcx
movslq -0x2ac(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x2ac(%rbp)
mov    0x2906(%rip),%rax
mov    (%rax),%edi
mov    -0x298(%rbp),%rax
mov    %eax,%edx
mov    -0x2ac(%rbp),%ecx
lea    0xb2d(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1618 <main+0x3d8>
mov    -0x2a8(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2b0(%rbp)
mov    -0x150(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsp,-0x38(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x50(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
lea    0xd69(%rip),%r13
lea    0xd6c(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    $0x22b8,%ax
mov    %rax,-0x48(%rbp)
lea    0xd61(%rip),%r12
mov    0x2d40(%rip),%r15
jmp    12c3 <main+0x73>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%r13
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1100 <getopt@plt>
cmp    $0x73,%eax
je     12c0 <main+0x70>
cmp    $0x6e,%eax
jle    1300 <main+0xb0>
cmp    $0x6f,%eax
je     12f7 <main+0xa7>
cmp    $0x70,%eax
jne    1542 <main+0x2f2>
mov    (%r15),%rdi
call   1110 <atoi@plt>
mov    %rax,-0x48(%rbp)
jmp    12c3 <main+0x73>
mov    (%r15),%rax
mov    %rax,-0x40(%rbp)
jmp    12c3 <main+0x73>
cmp    $0xffffffff,%eax
jne    1518 <main+0x2c8>
lea    -0x70(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10b0 <memset@plt>
mov    0x2cb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2c91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
movzwl -0x48(%rbp),%ecx
lea    0xdc8(%rip),%rdx
lea    -0x7f(%rbp),%rbx
mov    %rbx,%rdi
mov    $0xf,%esi
call   1090 <snprintf@plt>
lea    -0x30(%rbp),%rcx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1150 <getaddrinfo@plt>
test   %eax,%eax
je     1397 <main+0x147>
mov    0x2c5b(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   10a0 <gai_strerror@plt>
lea    0xd8d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%eax
mov    -0x38(%rbp),%rcx
jmp    1506 <main+0x2b6>
lea    0xe13(%rip),%rdi
call   1060 <puts@plt>
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%esi
mov    0x8(%rax),%edi
mov    0x10(%rax),%edx
call   1170 <socket@plt>
cmp    $0xffffffff,%eax
je     156a <main+0x31a>
mov    %eax,%r13d
lea    0xe01(%rip),%rdi
call   1060 <puts@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
mov    0xc(%rax),%edx
mov    %r13d,%edi
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
je     1573 <main+0x323>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%ebx
mov    (%rax),%rdi
call   1050 <get_in_addr@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    -0x58(%rbp),%rbx
mov    %rbx,%rdx
mov    -0x50(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xd28(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    -0x180(%rbp),%rbx
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %rbx,%rdi
call   1110 <atoi@plt>
mov    %rax,%rbx
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
lea    0xd04(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
lea    0xd04(%rip),%rsi
mov    -0x40(%rbp),%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1591 <main+0x341>
mov    %rax,%r15
lea    -0x180(%rbp),%rsi
mov    %r13d,%edi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %ebx,%ebx
jle    14f0 <main+0x2a0>
mov    %rax,%r14
test   %rax,%rax
jle    14f0 <main+0x2a0>
lea    -0x180(%rbp),%r12
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1140 <fwrite@plt>
sub    %r14d,%ebx
mov    0x2af3(%rip),%rax
mov    (%rax),%edi
lea    0xcc0(%rip),%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %ebx,%ebx
jle    14f0 <main+0x2a0>
mov    %rax,%r14
test   %rax,%rax
jg     14a0 <main+0x250>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    %r13d,%edi
call   10c0 <close@plt>
mov    -0x38(%rbp),%rcx
xor    %eax,%eax
mov    %rcx,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x68,%eax
jne    1542 <main+0x2f2>
mov    0x2a8c(%rip),%rax
mov    (%rax),%edi
lea    0xaed(%rip),%rsi
lea    0xae9(%rip),%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    0x2a7f(%rip),%rax
mov    (%rax),%edi
lea    0xac8(%rip),%rsi
lea    0xac4(%rip),%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xbaa(%rip),%rdi
jmp    1582 <main+0x332>
mov    %r13d,%edi
call   10c0 <close@plt>
lea    0xba8(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2a30(%rip),%rax
mov    (%rax),%ebx
mov    0x2a17(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
lea    0xbb7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    1559 <main+0x309>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"localhost\00"
@.str.1 = [13 x i8] c"Hello World!\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.2 = [8 x i8] c"foo.txt\00"
@.str.3 = [8 x i8] c"s:p:o:h\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [234 x i8] c"usage:\0A transferclient [options]\0Aoptions:\0A -s Server (Default: localhost)\0A -p Port (Default: 8888)\0A -o Output file (Default foo.txt)\0A -h Show this help message\0A\00"
@stderr = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.8 = [25 x i8] c"getaddrinfo is executed\0A\00"
@.str.9 = [15 x i8] c"client: socket\00"
@.str.10 = [19 x i8] c"socket is created\0A\00"
@.str.11 = [16 x i8] c"client: connect\00"
@.str.12 = [26 x i8] c"client: connecting to %s\0A\00"
@.str.13 = [16 x i8] c"\0AFile size: %d\0A\00"
@.str.14 = [2 x i8] c"w\00"
@.str.15 = [32 x i8] c"Failed to open file foo --> %s\0A\00"
@errno = global i32 0
@.str.16 = [43 x i8] c"Received %d bytes and we hope: - %d bytes\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 i8*
%9 = alloca i16
%10 = alloca [15 x i8]
%11 = alloca i8*
%12 = alloca [256 x i8]
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca %struct.addrinfo
%17 = alloca %struct.addrinfo*
%18 = alloca i32
%19 = alloca i8*
%20 = alloca [256 x i8]
%21 = alloca i64
%22 = alloca i32
%23 = alloca i32*
%24 = alloca i32
%25 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %8
store i16 8888, i16* %9
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %11
%26 = load i32, i32* @INET6_ADDRSTRLEN
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %14
%29 = alloca i8, i64 %27
store i64 %27, i64* %15
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %19
store i32 0, i32* %24
br label %30
30: ; preds = %53, %2
%31 = load i32, i32* %4
%32 = load i8**, i8*** %5
%33 = call i32 @getopt(i32 %31, i8** %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 %33, i32* %7
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %54
35: ; preds = %30
%36 = load i32, i32* %7
switch i32 %36, label %49 [
i32 115, label %37
i32 112, label %39
i32 111, label %43
i32 104, label %45
]
37: ; preds = %35
%38 = load i8*, i8** @optarg
store i8* %38, i8** %8
br label %53
39: ; preds = %35
%40 = load i8*, i8** @optarg
%41 = call i8* @atoi(i8* %40)
%42 = ptrtoint i8* %41 to i16
store i16 %42, i16* %9
br label %53
43: ; preds = %35
%44 = load i8*, i8** @optarg
store i8* %44, i8** %19
br label %53
45: ; preds = %35
%46 = load i32, i32* @stdout
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([234 x i8], [234 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %35
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([234 x i8], [234 x i8]* @.str.5, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %43, %39, %37
br label %30
54: ; preds = %30
%55 = call i32 @memset(%struct.addrinfo* %16, i32 0, i32 24)
%56 = load i32, i32* @AF_INET
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %16, i32 0, i32 1
store i32 %56, i32* %57
%58 = load i32, i32* @SOCK_STREAM
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %16, i32 0, i32 4
store i32 %58, i32* %59
%60 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%61 = load i16, i16* %9
%62 = call i32 @snprintf(i8* %60, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i16 zeroext %61)
%63 = load i8*, i8** %8
%64 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%65 = call i32 @getaddrinfo(i8* %63, i8* %64, %struct.addrinfo* %16, %struct.addrinfo** %17)
store i32 %65, i32* %18
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %54
%68 = load i32, i32* @stderr
%69 = load i32, i32* %18
%70 = call i8* @gai_strerror(i32 %69)
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %70)
store i32 1, i32* %3
store i32 1, i32* %25
br label %167
72: ; preds = %54
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%74 = load %struct.addrinfo*, %struct.addrinfo** %17
%75 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i32 0, i32 1
%76 = load i32, i32* %75
%77 = load %struct.addrinfo*, %struct.addrinfo** %17
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %77, i32 0, i32 4
%79 = load i32, i32* %78
%80 = load %struct.addrinfo*, %struct.addrinfo** %17
%81 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %80, i32 0, i32 3
%82 = load i32, i32* %81
%83 = call i32 @socket(i32 %76, i32 %79, i32 %82)
store i32 %83, i32* %6
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %88
85: ; preds = %72
%86 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %72
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%90 = load i32, i32* %6
%91 = load %struct.addrinfo*, %struct.addrinfo** %17
%92 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %91, i32 0, i32 0
%93 = load i64, i64* %92
%94 = load %struct.addrinfo*, %struct.addrinfo** %17
%95 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %94, i32 0, i32 2
%96 = load i32, i32* %95
%97 = call i32 @connect(i32 %90, i64 %93, i32 %96)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %104
99: ; preds = %88
%100 = load i32, i32* %6
%101 = call i32 @close(i32 %100)
%102 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%103 = call i32 @exit(i32 1)
unreachable
104: ; preds = %88
%105 = load %struct.addrinfo*, %struct.addrinfo** %17
%106 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %105, i32 0, i32 1
%107 = load i32, i32* %106
%108 = load %struct.addrinfo*, %struct.addrinfo** %17
%109 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %108, i32 0, i32 0
%110 = load i64, i64* %109
%111 = inttoptr i64 %110 to %struct.sockaddr*
%112 = call i32 @get_in_addr(%struct.sockaddr* %111)
%113 = trunc i64 %27 to i32
%114 = call i32 @inet_ntop(i32 %107, i32 %112, i8* %29, i32 %113)
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i8* %29)
%116 = load i32, i32* %6
%117 = getelementptr inbounds [256 x i8], [256 x i8]* %20, i64 0, i64 0
%118 = call i64 @recv(i32 %116, i8* %117, i32 256, i32 0)
%119 = getelementptr inbounds [256 x i8], [256 x i8]* %20, i64 0, i64 0
%120 = call i8* @atoi(i8* %119)
%121 = ptrtoint i8* %120 to i32
store i32 %121, i32* %22
%122 = load i32, i32* @stdout
%123 = load i32, i32* %22
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %123)
%125 = load i8*, i8** %19
%126 = call i32* @fopen(i8* %125, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
store i32* %126, i32** %23
%127 = load i32*, i32** %23
%128 = icmp eq i32* %127, null
br i1 %128, label %129, label %135
129: ; preds = %104
%130 = load i32, i32* @stderr
%131 = load i32, i32* @errno
%132 = call i8* @strerror(i32 %131)
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i8* %132)
%134 = call i32 @exit(i32 1)
unreachable
135: ; preds = %104
%136 = load i32, i32* %22
store i32 %136, i32* %24
br label %137
137: ; preds = %147, %135
%138 = load i32, i32* %6
%139 = getelementptr inbounds [256 x i8], [256 x i8]* %20, i64 0, i64 0
%140 = call i64 @recv(i32 %138, i8* %139, i32 256, i32 0)
store i64 %140, i64* %21
%141 = icmp sgt i64 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %137
%143 = load i32, i32* %24
%144 = icmp sgt i32 %143, 0
br label %145
145: ; preds = %142, %137
%146 = phi i1 [ false, %137 ], [ %144, %142 ]
br i1 %146, label %147, label %162
147: ; preds = %145
%148 = getelementptr inbounds [256 x i8], [256 x i8]* %20, i64 0, i64 0
%149 = load i64, i64* %21
%150 = load i32*, i32** %23
%151 = call i32 @fwrite(i8* %148, i32 1, i64 %149, i32* %150)
%152 = load i64, i64* %21
%153 = load i32, i32* %24
%154 = sext i32 %153 to i64
%155 = sub nsw i64 %154, %152
%156 = trunc i64 %155 to i32
store i32 %156, i32* %24
%157 = load i32, i32* @stdout
%158 = load i64, i64* %21
%159 = trunc i64 %158 to i32
%160 = load i32, i32* %24
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %157, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.16, i64 0, i64 0), i32 %159, i32 %160)
br label %137
162: ; preds = %145
%163 = load i32*, i32** %23
%164 = call i32 @fclose(i32* %163)
%165 = load i32, i32* %6
%166 = call i32 @close(i32 %165)
store i32 0, i32* %3
store i32 1, i32* %25
br label %167
167: ; preds = %162, %67
%168 = load i8*, i8** %14
%169 = load i32, i32* %3
ret i32 %169
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"localhost\00"
@INET6_ADDRSTRLEN = global i32 0
@.str.2 = [8 x i8] c"foo.txt\00"
@.str.3 = [8 x i8] c"s:p:o:h\00"
@optarg = global i8* null
@stdout = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [234 x i8] c"usage:\0A transferclient [options]\0Aoptions:\0A -s Server (Default: localhost)\0A -p Port (Default: 8888)\0A -o Output file (Default foo.txt)\0A -h Show this help message\0A\00"
@stderr = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.9 = [15 x i8] c"client: socket\00"
@.str.11 = [16 x i8] c"client: connect\00"
@.str.12 = [26 x i8] c"client: connecting to %s\0A\00"
@.str.13 = [16 x i8] c"\0AFile size: %d\0A\00"
@.str.14 = [2 x i8] c"w\00"
@.str.15 = [32 x i8] c"Failed to open file foo --> %s\0A\00"
@errno = global i32 0
@.str.16 = [43 x i8] c"Received %d bytes and we hope: - %d bytes\0A\00"
@str = [24 x i8] c"getaddrinfo is executed\00"
@str.17 = [18 x i8] c"socket is created\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [15 x i8]
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @INET6_ADDRSTRLEN
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = bitcast %struct.addrinfo* %4 to i8*
%13 = bitcast %struct.addrinfo** %5 to i8*
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
br label %15
15: ; preds = %27, %2
%16 = phi i16 [ %31, %27 ], [ 8888, %2 ]
%17 = phi i8* [ %20, %27 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %2 ]
%18 = phi i8* [ %23, %27 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
br label %19
19: ; preds = %15, %32
%20 = phi i8* [ %17, %15 ], [ %33, %32 ]
%21 = phi i8* [ %18, %15 ], [ %23, %32 ]
br label %22
22: ; preds = %19, %25
%23 = phi i8* [ %26, %25 ], [ %21, %19 ]
%24 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
switch i32 %24, label %38 [
i32 -1, label %42
i32 115, label %25
i32 112, label %27
i32 111, label %32
i32 104, label %34
]
25: ; preds = %22
%26 = load i8*, i8** @optarg
br label %22
27: ; preds = %22
%28 = load i8*, i8** @optarg
%29 = tail call i8* @atoi(i8* %28)
%30 = ptrtoint i8* %29 to i64
%31 = trunc i64 %30 to i16
br label %15
32: ; preds = %22
%33 = load i8*, i8** @optarg
br label %19
34: ; preds = %22
%35 = load i32, i32* @stdout
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([234 x i8], [234 x i8]* @.str.5, i64 0, i64 0))
%37 = tail call i32 @exit(i32 0)
unreachable
38: ; preds = %22
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([234 x i8], [234 x i8]* @.str.5, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %22
%43 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 24)
%44 = load i32, i32* @AF_INET
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
store i32 %44, i32* %45
%46 = load i32, i32* @SOCK_STREAM
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %46, i32* %47
%48 = call i32 @snprintf(i8* %7, i32 15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i16 zeroext %16)
%49 = call i32 @getaddrinfo(i8* %23, i8* %7, %struct.addrinfo* %4, %struct.addrinfo** %5)
%50 = icmp eq i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %42
%52 = load i32, i32* @stderr
%53 = call i8* @gai_strerror(i32 %49)
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %53)
br label %126
55: ; preds = %42
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%57 = load %struct.addrinfo*, %struct.addrinfo** %5
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 1
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 4
%61 = load i32, i32* %60
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 3
%63 = load i32, i32* %62
%64 = call i32 @socket(i32 %59, i32 %61, i32 %63)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %69
66: ; preds = %55
%67 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %55
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.17, i64 0, i64 0))
%71 = load %struct.addrinfo*, %struct.addrinfo** %5
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %71, i64 0, i32 0
%73 = load i64, i64* %72
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %71, i64 0, i32 2
%75 = load i32, i32* %74
%76 = call i32 @connect(i32 %64, i64 %73, i32 %75)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %82
78: ; preds = %69
%79 = call i32 @close(i32 %64)
%80 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %69
%83 = load %struct.addrinfo*, %struct.addrinfo** %5
%84 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %83, i64 0, i32 1
%85 = load i32, i32* %84
%86 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %83, i64 0, i32 0
%87 = load i64, i64* %86
%88 = inttoptr i64 %87 to %struct.sockaddr*
%89 = call i32 @get_in_addr(%struct.sockaddr* %88)
%90 = call i32 @inet_ntop(i32 %85, i32 %89, i8* %11, i32 %8)
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i8* %11)
%92 = call i64 @recv(i32 %64, i8* %14, i32 256, i32 0)
%93 = call i8* @atoi(i8* %14)
%94 = ptrtoint i8* %93 to i64
%95 = trunc i64 %94 to i32
%96 = load i32, i32* @stdout
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %95)
%98 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
%99 = icmp eq i32* %98, null
br i1 %99, label %105, label %100
100: ; preds = %82
%101 = call i64 @recv(i32 %64, i8* %14, i32 256, i32 0)
%102 = icmp sgt i64 %101, 0
%103 = icmp sgt i32 %95, 0
%104 = and i1 %103, %102
br i1 %104, label %111, label %123
105: ; preds = %82
%106 = load i32, i32* @stderr
%107 = load i32, i32* @errno
%108 = call i8* @strerror(i32 %107)
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i8* %108)
%110 = call i32 @exit(i32 1)
unreachable
111: ; preds = %100, %111
%112 = phi i64 [ %119, %111 ], [ %101, %100 ]
%113 = phi i32 [ %116, %111 ], [ %95, %100 ]
%114 = call i32 @fwrite(i8* %14, i32 1, i64 %112, i32* %98)
%115 = trunc i64 %112 to i32
%116 = sub i32 %113, %115
%117 = load i32, i32* @stdout
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.16, i64 0, i64 0), i32 %115, i32 %116)
%119 = call i64 @recv(i32 %64, i8* %14, i32 256, i32 0)
%120 = icmp sgt i64 %119, 0
%121 = icmp sgt i32 %116, 0
%122 = and i1 %121, %120
br i1 %122, label %111, label %123
123: ; preds = %111, %100
%124 = call i32 @fclose(i32* %98)
%125 = call i32 @close(i32 %64)
br label %126
126: ; preds = %123, %51
%127 = phi i32 [ 1, %51 ], [ 0, %123 ]
ret i32 %127
}