#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 */
typedef char uint32_t;
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;
  struct addrinfo *ai_next;
};
typedef int /*<<< orphan*/ filename_size;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
char *basename(char *);
int /*<<< orphan*/ close(int);
int connect(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
char htonl(char);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
void client(char *ip, int *port, char *path) {
  int sockfd;
  char buf[1024];
  struct addrinfo hints, *servinfo, *p;
  int rv;
  char s[INET6_ADDRSTRLEN];
  int size;
  FILE *ft;
  uint32_t filename_size;
  size_t total;
  char port_s[100];
  char *filename;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  snprintf(port_s, 100, "%d", *port);
  if ((rv = getaddrinfo(ip, port_s, &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
    exit(1);
  }
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      perror("client: socket");
      continue;
    }
    if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
      close(sockfd);
      perror("client: connect");
      continue;
    }
    break;
  }
  if (p == NULL) {
    fprintf(stderr, "client: failed to connect\n");
    exit(2);
  }
  inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s,
            sizeof s);
  freeaddrinfo(servinfo);
  ft = fopen(path, "rb");
  if (ft == NULL) {
    perror("Cannot open file");
    exit(1);
  }
  filename = basename(path);
  filename_size = strlen(filename);
  filename_size = htonl(filename_size);
  memcpy(buf, &filename_size, sizeof(filename_size));
  memcpy(&buf[sizeof(filename_size)], filename, strlen(filename));
  if (send(sockfd, buf, sizeof(int) + strlen(filename), 0) == -1)
    perror("send");
  total = 0;
  while (!feof(ft)) {
    size = fread(&buf, 1, 1024, ft);
    total += size;
    printf("\rSent: %zu", total);
    if (send(sockfd, buf, size, 0) == -1)
      perror("send");
  }
  printf("\nFile sent.\n");
  close(sockfd);
  fclose(ft);
}


x86 assembly (clang, -O0):
<client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x508(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x460(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x500(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x468(%rbp)
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10d0 <memset@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x438(%rbp)
mov    0x2cdc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x4f0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    $0x64,%esi
lea    0xcf3(%rip),%rdx
call   10a0 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x4f0(%rbp),%rsi
lea    -0x440(%rbp),%rdx
lea    -0x448(%rbp),%rcx
call   1170 <getaddrinfo@plt>
mov    %eax,-0x454(%rbp)
cmp    $0x0,%eax
je     137a <client+0x10a>
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50c(%rbp)
mov    -0x454(%rbp),%edi
call   10b0 <gai_strerror@plt>
mov    -0x50c(%rbp),%edi
mov    %rax,%rdx
lea    0xc9a(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x448(%rbp),%rax
mov    %rax,-0x450(%rbp)
cmpq   $0x0,-0x450(%rbp)
je     1430 <client+0x1c0>
mov    -0x450(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x450(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x450(%rbp),%rax
mov    0x10(%rax),%edx
call   1190 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    13d6 <client+0x166>
lea    0xc48(%rip),%rdi
call   1140 <perror@plt>
jmp    1419 <client+0x1a9>
mov    -0x1c(%rbp),%edi
mov    -0x450(%rbp),%rax
mov    (%rax),%rsi
mov    -0x450(%rbp),%rax
mov    0xc(%rax),%edx
call   1160 <connect@plt>
cmp    $0xffffffff,%eax
jne    1414 <client+0x1a4>
mov    -0x1c(%rbp),%edi
call   10e0 <close@plt>
lea    0xc19(%rip),%rdi
call   1140 <perror@plt>
jmp    1419 <client+0x1a9>
jmp    1430 <client+0x1c0>
mov    -0x450(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x450(%rbp)
jmp    1388 <client+0x118>
cmpq   $0x0,-0x450(%rbp)
jne    145f <client+0x1ef>
mov    0x2b8b(%rip),%rax
mov    (%rax),%edi
lea    0xbe5(%rip),%rsi
mov    $0x0,%al
call   10f0 <fprintf@plt>
mov    $0x2,%edi
call   1150 <exit@plt>
mov    -0x450(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x510(%rbp)
mov    -0x450(%rbp),%rax
mov    (%rax),%rdi
call   1040 <get_in_addr@plt>
mov    -0x510(%rbp),%edi
mov    -0x500(%rbp),%rdx
mov    %eax,%esi
mov    -0x508(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x448(%rbp),%rdi
call   1180 <freeaddrinfo@plt>
mov    -0x18(%rbp),%rdi
lea    0xb9c(%rip),%rsi
call   1130 <fopen@plt>
mov    %rax,-0x478(%rbp)
cmpq   $0x0,-0x478(%rbp)
jne    14e2 <client+0x272>
lea    0xb7e(%rip),%rdi
call   1140 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1100 <basename@plt>
mov    %rax,-0x4f8(%rbp)
mov    -0x4f8(%rbp),%rdi
call   1070 <strlen@plt>
mov    %al,-0x479(%rbp)
movsbl -0x479(%rbp),%edi
call   10c0 <htonl@plt>
mov    %al,-0x479(%rbp)
lea    -0x420(%rbp),%rdi
lea    -0x479(%rbp),%rsi
mov    $0x1,%edx
call   1120 <memcpy@plt>
lea    -0x420(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x530(%rbp)
mov    -0x4f8(%rbp),%rax
mov    %rax,-0x528(%rbp)
mov    -0x4f8(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x530(%rbp),%rdi
mov    -0x528(%rbp),%rsi
mov    %eax,%edx
call   1120 <memcpy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x51c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x518(%rbp)
mov    -0x4f8(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x51c(%rbp),%edi
mov    -0x518(%rbp),%rsi
cltq
add    $0x4,%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0xffffffff,%eax
jne    15c3 <client+0x353>
lea    0xaa4(%rip),%rdi
call   1140 <perror@plt>
movq   $0x0,-0x488(%rbp)
mov    -0x478(%rbp),%rdi
call   1110 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    15ef <client+0x37f>
jmp    166d <client+0x3fd>
lea    -0x420(%rbp),%rdi
mov    -0x478(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1050 <fread@plt>
mov    %eax,-0x46c(%rbp)
movslq -0x46c(%rbp),%rax
add    -0x488(%rbp),%rax
mov    %rax,-0x488(%rbp)
mov    -0x488(%rbp),%rsi
lea    0xa32(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x46c(%rbp),%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0xffffffff,%eax
jne    1668 <client+0x3f8>
lea    0x9ff(%rip),%rdi
call   1140 <perror@plt>
jmp    15ce <client+0x35e>
lea    0x9fe(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x1c(%rbp),%edi
call   10e0 <close@plt>
mov    -0x478(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x460(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4b8,%rsp
mov    %rdx,-0x50(%rbp)
mov    %rsi,%r13
mov    %rdi,%r14
mov    %rsp,-0x40(%rbp)
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x70(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   10e0 <memset@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x0(%r13),%ecx
lea    0xd0a(%rip),%rdx
lea    -0xe0(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   10b0 <snprintf@plt>
lea    -0x38(%rbp),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1180 <getaddrinfo@plt>
test   %eax,%eax
jne    150c <client+0x28c>
mov    -0x38(%rbp),%rbx
test   %rbx,%rbx
je     137f <client+0xff>
lea    0xce0(%rip),%r15
lea    0xce8(%rip),%r13
mov    0x14(%rbx),%esi
mov    0x8(%rbx),%edi
mov    0x10(%rbx),%edx
call   11a0 <socket@plt>
mov    %r15,%rdi
cmp    $0xffffffff,%eax
je     1371 <client+0xf1>
mov    %eax,%r14d
mov    (%rbx),%rsi
mov    0xc(%rbx),%edx
mov    %eax,%edi
call   1170 <connect@plt>
cmp    $0xffffffff,%eax
jne    13a0 <client+0x120>
mov    %r14d,%edi
call   10f0 <close@plt>
mov    %r13,%rdi
call   1150 <perror@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
jne    133b <client+0xbb>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
lea    0xca4(%rip),%rsi
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    $0x2,%edi
call   1160 <exit@plt>
mov    0x8(%rbx),%r15d
mov    (%rbx),%rdi
call   1040 <get_in_addr@plt>
mov    %r15d,%edi
mov    %eax,%esi
mov    %r12,%rdx
mov    -0x48(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    -0x38(%rbp),%rdi
call   1190 <freeaddrinfo@plt>
lea    0xc81(%rip),%rsi
mov    -0x50(%rbp),%r15
mov    %r15,%rdi
call   1140 <fopen@plt>
test   %rax,%rax
je     1539 <client+0x2b9>
mov    %rax,%rbx
mov    %r15,%rdi
call   1110 <basename@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <strlen@plt>
movsbl %al,%edi
call   10d0 <htonl@plt>
mov    %al,-0x29(%rbp)
lea    -0x4e0(%rbp),%r12
lea    -0x29(%rbp),%rsi
mov    %r12,%rdi
mov    $0x1,%edx
call   1130 <memcpy@plt>
lea    -0x4df(%rbp),%r13
mov    %r15,%rdi
call   1080 <strlen@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1130 <memcpy@plt>
mov    %r15,%rdi
call   1080 <strlen@plt>
lea    0x4(%rax),%edx
mov    %r14d,%edi
mov    %r12,%rsi
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
je     14fb <client+0x27b>
mov    %rbx,%rdi
call   1120 <feof@plt>
test   %eax,%eax
je     1493 <client+0x213>
lea    0xc07(%rip),%rdi
call   1050 <puts@plt>
mov    %r14d,%edi
call   10f0 <close@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    -0x40(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    -0x4e0(%rbp),%r15
xor    %r13d,%r13d
jmp    14ac <client+0x22c>
nop
mov    %rbx,%rdi
call   1120 <feof@plt>
test   %eax,%eax
jne    1464 <client+0x1e4>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1060 <fread@plt>
movslq %eax,%r12
add    %r12,%r13
lea    0xb99(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
jne    14a0 <client+0x220>
lea    0xb6e(%rip),%rdi
call   1150 <perror@plt>
jmp    14a0 <client+0x220>
lea    0xb60(%rip),%rdi
call   1150 <perror@plt>
jmp    1458 <client+0x1d8>
mov    0x2abd(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   10c0 <gai_strerror@plt>
lea    0xae0(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0xb11(%rip),%rdi
call   1150 <perror@plt>
mov    $0x1,%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo* }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [15 x i8] c"client: socket\00"
@.str.3 = [16 x i8] c"client: connect\00"
@.str.4 = [27 x i8] c"client: failed to connect\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [17 x i8] c"Cannot open file\00"
@.str.7 = [5 x i8] c"send\00"
@.str.8 = [11 x i8] c"\0DSent: %zu\00"
@.str.9 = [13 x i8] c"\0AFile sent.\0A\00"
define void @client(i8* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca %struct.addrinfo
%10 = alloca %struct.addrinfo*
%11 = alloca %struct.addrinfo*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32*
%17 = alloca i8
%18 = alloca i64
%19 = alloca [100 x i8]
%20 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%21 = load i32, i32* @INET6_ADDRSTRLEN
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %13
%24 = alloca i8, i64 %22
store i64 %22, i64* %14
%25 = call i32 @memset(%struct.addrinfo* %9, i32 0, i32 32)
%26 = load i32, i32* @AF_UNSPEC
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @SOCK_STREAM
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 4
store i32 %28, i32* %29
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 0
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = call i32 @snprintf(i8* %30, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = load i8*, i8** %4
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %19, i64 0, i64 0
%36 = call i32 @getaddrinfo(i8* %34, i8* %35, %struct.addrinfo* %9, %struct.addrinfo** %10)
store i32 %36, i32* %12
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %3
%39 = load i32, i32* @stderr
%40 = load i32, i32* %12
%41 = call i8* @gai_strerror(i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %3
%45 = load %struct.addrinfo*, %struct.addrinfo** %10
store %struct.addrinfo* %45, %struct.addrinfo** %11
br label %46
46: ; preds = %78, %44
%47 = load %struct.addrinfo*, %struct.addrinfo** %11
%48 = icmp ne %struct.addrinfo* %47, null
br i1 %48, label %49, label %82
49: ; preds = %46
%50 = load %struct.addrinfo*, %struct.addrinfo** %11
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = load %struct.addrinfo*, %struct.addrinfo** %11
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 4
%55 = load i32, i32* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %11
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 3
%58 = load i32, i32* %57
%59 = call i32 @socket(i32 %52, i32 %55, i32 %58)
store i32 %59, i32* %7
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %49
%62 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %78
63: ; preds = %49
%64 = load i32, i32* %7
%65 = load %struct.addrinfo*, %struct.addrinfo** %11
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 0
%67 = load i64, i64* %66
%68 = load %struct.addrinfo*, %struct.addrinfo** %11
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 2
%70 = load i32, i32* %69
%71 = call i32 @connect(i32 %64, i64 %67, i32 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %77
73: ; preds = %63
%74 = load i32, i32* %7
%75 = call i32 @close(i32 %74)
%76 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %78
77: ; preds = %63
br label %82
78: ; preds = %73, %61
%79 = load %struct.addrinfo*, %struct.addrinfo** %11
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %79, i32 0, i32 5
%81 = load %struct.addrinfo*, %struct.addrinfo** %80
store %struct.addrinfo* %81, %struct.addrinfo** %11
br label %46
82: ; preds = %77, %46
%83 = load %struct.addrinfo*, %struct.addrinfo** %11
%84 = icmp eq %struct.addrinfo* %83, null
br i1 %84, label %85, label %89
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%88 = call i32 @exit(i32 2)
unreachable
89: ; preds = %82
%90 = load %struct.addrinfo*, %struct.addrinfo** %11
%91 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %90, i32 0, i32 1
%92 = load i32, i32* %91
%93 = load %struct.addrinfo*, %struct.addrinfo** %11
%94 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %93, i32 0, i32 0
%95 = load i64, i64* %94
%96 = inttoptr i64 %95 to %struct.sockaddr*
%97 = call i32 @get_in_addr(%struct.sockaddr* %96)
%98 = trunc i64 %22 to i32
%99 = call i32 @inet_ntop(i32 %92, i32 %97, i8* %24, i32 %98)
%100 = load %struct.addrinfo*, %struct.addrinfo** %10
%101 = call i32 @freeaddrinfo(%struct.addrinfo* %100)
%102 = load i8*, i8** %6
%103 = call i32* @fopen(i8* %102, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %103, i32** %16
%104 = load i32*, i32** %16
%105 = icmp eq i32* %104, null
br i1 %105, label %106, label %109
106: ; preds = %89
%107 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %89
%110 = load i8*, i8** %6
%111 = call i8* @basename(i8* %110)
store i8* %111, i8** %20
%112 = load i8*, i8** %20
%113 = call i32 @strlen(i8* %112)
%114 = trunc i32 %113 to i8
store i8 %114, i8* %17
%115 = load i8, i8* %17
%116 = call signext i8 @htonl(i8 signext %115)
store i8 %116, i8* %17
%117 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%118 = call i32 @memcpy(i8* %117, i8* %17, i32 1)
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 1
%120 = load i8*, i8** %20
%121 = load i8*, i8** %20
%122 = call i32 @strlen(i8* %121)
%123 = call i32 @memcpy(i8* %119, i8* %120, i32 %122)
%124 = load i32, i32* %7
%125 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%126 = load i8*, i8** %20
%127 = call i32 @strlen(i8* %126)
%128 = sext i32 %127 to i64
%129 = add i64 4, %128
%130 = trunc i64 %129 to i32
%131 = call i32 @send(i32 %124, i8* %125, i32 %130, i32 0)
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %135
133: ; preds = %109
%134 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %135
135: ; preds = %133, %109
store i64 0, i64* %18
br label %136
136: ; preds = %158, %135
%137 = load i32*, i32** %16
%138 = call i32 @feof(i32* %137)
%139 = icmp ne i32 %138, 0
%140 = xor i1 %139, true
br i1 %140, label %141, label %159
141: ; preds = %136
%142 = bitcast [1024 x i8]* %8 to i8**
%143 = load i32*, i32** %16
%144 = call i32 @fread(i8** %142, i32 1, i32 1024, i32* %143)
store i32 %144, i32* %15
%145 = load i32, i32* %15
%146 = sext i32 %145 to i64
%147 = load i64, i64* %18
%148 = add i64 %147, %146
store i64 %148, i64* %18
%149 = load i64, i64* %18
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i64 %149)
%151 = load i32, i32* %7
%152 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%153 = load i32, i32* %15
%154 = call i32 @send(i32 %151, i8* %152, i32 %153, i32 0)
%155 = icmp eq i32 %154, -1
br i1 %155, label %156, label %158
156: ; preds = %141
%157 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %158
158: ; preds = %156, %141
br label %136
159: ; preds = %136
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%161 = load i32, i32* %7
%162 = call i32 @close(i32 %161)
%163 = load i32*, i32** %16
%164 = call i32 @fclose(i32* %163)
%165 = load i8*, i8** %13
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo* }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [15 x i8] c"client: socket\00"
@.str.3 = [16 x i8] c"client: connect\00"
@.str.4 = [27 x i8] c"client: failed to connect\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [17 x i8] c"Cannot open file\00"
@.str.7 = [5 x i8] c"send\00"
@.str.8 = [11 x i8] c"\0DSent: %zu\00"
@str = [12 x i8] c"\0AFile sent.\00"
define void @client(i8* %0, i32* nocapture %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca i8
%8 = alloca [100 x i8]
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = bitcast %struct.addrinfo* %5 to i8*
%11 = bitcast %struct.addrinfo** %6 to i8*
%12 = load i32, i32* @INET6_ADDRSTRLEN
%13 = zext i32 %12 to i64
%14 = tail call i8* @llvm.stacksave()
%15 = alloca i8, i64 %13
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%17 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 32)
%18 = load i32, i32* @AF_UNSPEC
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @SOCK_STREAM
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %20, i32* %21
%22 = load i32, i32* %1
%23 = call i32 @snprintf(i8* %16, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 @getaddrinfo(i8* %0, i8* %16, %struct.addrinfo* %5, %struct.addrinfo** %6)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %3
%27 = load %struct.addrinfo*, %struct.addrinfo** %6
%28 = icmp eq %struct.addrinfo* %27, null
br i1 %28, label %59, label %34
29: ; preds = %3
%30 = load i32, i32* @stderr
%31 = call i8* @gai_strerror(i32 %24)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %26, %53
%35 = phi %struct.addrinfo* [ %57, %53 ], [ %27, %26 ]
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 1
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 4
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 3
%41 = load i32, i32* %40
%42 = call i32 @socket(i32 %37, i32 %39, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %53, label %44
44: ; preds = %34
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 0
%46 = load i64, i64* %45
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 2
%48 = load i32, i32* %47
%49 = call i32 @connect(i32 %42, i64 %46, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %63
51: ; preds = %44
%52 = call i32 @close(i32 %42)
br label %53
53: ; preds = %34, %51
%54 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), %51 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), %34 ]
%55 = call i32 @perror(i8* %54)
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 5
%57 = load %struct.addrinfo*, %struct.addrinfo** %56
%58 = icmp eq %struct.addrinfo* %57, null
br i1 %58, label %59, label %34
59: ; preds = %53, %26
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @exit(i32 2)
unreachable
63: ; preds = %44
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 1
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 0
%66 = load i32, i32* %64
%67 = load i64, i64* %65
%68 = inttoptr i64 %67 to %struct.sockaddr*
%69 = call i32 @get_in_addr(%struct.sockaddr* %68)
%70 = call i32 @inet_ntop(i32 %66, i32 %69, i8* %15, i32 %12)
%71 = load %struct.addrinfo*, %struct.addrinfo** %6
%72 = call i32 @freeaddrinfo(%struct.addrinfo* %71)
%73 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%74 = icmp eq i32* %73, null
br i1 %74, label %75, label %78
75: ; preds = %63
%76 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %63
%79 = call i8* @basename(i8* %2)
%80 = call i32 @strlen(i8* %79)
%81 = trunc i32 %80 to i8
%82 = call signext i8 @htonl(i8 signext %81)
store i8 %82, i8* %7
%83 = call i32 @memcpy(i8* %9, i8* %7, i32 1)
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1
%85 = call i32 @strlen(i8* %79)
%86 = call i32 @memcpy(i8* %84, i8* %79, i32 %85)
%87 = call i32 @strlen(i8* %79)
%88 = add i32 %87, 4
%89 = call i32 @send(i32 %42, i8* %9, i32 %88, i32 0)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %93
91: ; preds = %78
%92 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %93
93: ; preds = %91, %78
%94 = call i32 @feof(i32* %73)
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %111
96: ; preds = %93
%97 = bitcast [1024 x i8]* %4 to i8**
br label %98
98: ; preds = %96, %108
%99 = phi i64 [ 0, %96 ], [ %102, %108 ]
%100 = call i32 @fread(i8** %97, i32 1, i32 1024, i32* %73)
%101 = sext i32 %100 to i64
%102 = add i64 %99, %101
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i64 %102)
%104 = call i32 @send(i32 %42, i8* %9, i32 %100, i32 0)
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %108
106: ; preds = %98
%107 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %108
108: ; preds = %106, %98
%109 = call i32 @feof(i32* %73)
%110 = icmp eq i32 %109, 0
br i1 %110, label %98, label %111
111: ; preds = %108, %93
%112 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%113 = call i32 @close(i32 %42)
%114 = call i32 @fclose(i32* %73)
ret void
}