#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct stat {
  unsigned int st_size;
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr_in {
  unsigned int st_size;
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ printServAddr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ DieWithError(char *);
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
unsigned short atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
unsigned int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
unsigned int send(int, char *, unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int, unsigned int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int sock;
  struct sockaddr_in printServAddr;
  unsigned short printServPort = 9100;
  char *servIP;
  FILE *fp;
  char buffer[4096];
  unsigned int bufsize;
  unsigned int totalSent = 0;
  char *printFile;
  struct stat buf;
  if ((argc < 3) || (argc > 4)) {
    fprintf(stderr, "Usage: %s <Server IP> <File> [<Port>]\n", argv[0]);
    exit(1);
  }
  servIP = argv[1];
  printFile = argv[2];
  if (argc == 4) {
    printServPort = atoi(argv[3]);
  }
  memset(&buf, 0, sizeof(struct stat));
  if (stat(printFile, &buf)) {
    DieWithError("Failed to stat input file.");
  }
  fp = fopen(printFile, "r");
  if (fp == NULL) {
    DieWithError("Failed to open input file.");
  }
  if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    fclose(fp);
    DieWithError("socket() failed");
  }
  memset(&printServAddr, 0, sizeof(printServAddr));
  printServAddr.sin_family = AF_INET;
  printServAddr.sin_addr.s_addr = inet_addr(servIP);
  printServAddr.sin_port = htons(printServPort);
  if (connect(sock, (struct sockaddr *)&printServAddr, sizeof(printServAddr)) <
      0) {
    fclose(fp);
    DieWithError("connect() failed");
  }
  while ((bufsize = fread(buffer, sizeof(char), 4096, fp))) {
    if (send(sock, buffer, bufsize, 0) != bufsize) {
      fclose(fp);
      close(sock);
      DieWithError("send() sent a different number of bytes than expected");
    }
    totalSent += bufsize;
  }
  if (totalSent != buf.st_size) {
    char err[128];
    snprintf(err, 128,
             "Sent a different number of bytes (%d) than expected from file "
             "size (%ld)",
             totalSent, buf.st_size);
    DieWithError(err);
  }
  fprintf(stdout, "%s sent to %s, port %d successfully!\n", printFile, servIP,
          printServPort);
  fclose(fp);
  close(sock);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x238c,-0x2a(%rbp)
movl   $0x0,-0x1048(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     123d <main+0x3d>
cmpl   $0x4,-0x8(%rbp)
jle    1265 <main+0x65>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x1050(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    129b <main+0x9b>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <atoi@plt>
mov    %ax,-0x2a(%rbp)
lea    -0x1060(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    -0x1050(%rbp),%rdi
lea    -0x1060(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0x0,%rax
je     12d7 <main+0xd7>
lea    0xd55(%rip),%rdi
call   10d0 <DieWithError@plt>
mov    -0x1050(%rbp),%rdi
lea    0xd5d(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1305 <main+0x105>
lea    0xd44(%rip),%rdi
call   10d0 <DieWithError@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
mov    0x2cb3(%rip),%rax
mov    (%rax),%esi
mov    0x2cc2(%rip),%rax
mov    (%rax),%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1346 <main+0x146>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd1e(%rip),%rdi
call   10d0 <DieWithError@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
movzwl -0x2a(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1110 <connect@plt>
cmp    $0x0,%rax
jge    13aa <main+0x1aa>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xcca(%rip),%rdi
call   10d0 <DieWithError@plt>
jmp    13af <main+0x1af>
lea    -0x1040(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x1044(%rbp)
cmp    $0x0,%eax
je     142f <main+0x22f>
mov    -0x14(%rbp),%edi
lea    -0x1040(%rbp),%rsi
mov    -0x1044(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    -0x1044(%rbp),%eax
je     1418 <main+0x218>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
lea    0xc6d(%rip),%rdi
call   10d0 <DieWithError@plt>
mov    -0x1044(%rbp),%eax
add    -0x1048(%rbp),%eax
mov    %eax,-0x1048(%rbp)
jmp    13af <main+0x1af>
mov    -0x1048(%rbp),%eax
cmp    -0x1060(%rbp),%eax
je     1472 <main+0x272>
lea    -0x10e0(%rbp),%rdi
mov    -0x1048(%rbp),%ecx
mov    -0x1060(%rbp),%r8d
mov    $0x80,%esi
lea    0xc55(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x10e0(%rbp),%rdi
call   10d0 <DieWithError@plt>
mov    0x2b3f(%rip),%rax
mov    (%rax),%edi
mov    -0x1050(%rbp),%rdx
mov    -0x38(%rbp),%rcx
movzwl -0x2a(%rbp),%r8d
lea    0xc6d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %edi,%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10c8,%rsp
lea    -0x5(%rdi),%eax
cmp    $0xfffffffd,%eax
ja     123d <main+0x3d>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdd4(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x8(%rsi),%r15
mov    0x10(%rsi),%rbp
mov    $0x238c,%r12w
cmp    $0x4,%edi
jne    125b <main+0x5b>
mov    0x18(%rsi),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r12d
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10c0 <stat@plt>
test   %rax,%rax
je     128b <main+0x8b>
lea    0xda1(%rip),%rdi
call   10d0 <DieWithError@plt>
lea    0xdb0(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    12ae <main+0xae>
lea    0xd9b(%rip),%rdi
call   10d0 <DieWithError@plt>
mov    %rbp,0x10(%rsp)
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
mov    0x2d14(%rip),%rax
mov    (%rax),%edx
call   1120 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12ed <main+0xed>
mov    %r13,%rdi
call   1040 <fclose@plt>
lea    0xd77(%rip),%rdi
call   10d0 <DieWithError@plt>
lea    0x20(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    %r15,0x18(%rsp)
mov    %r15,%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x28(%rsp)
movzwl %r12w,%edi
mov    %edi,0xc(%rsp)
call   1050 <htons@plt>
mov    %eax,0x24(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1110 <connect@plt>
test   %rax,%rax
jns    135a <main+0x15a>
mov    %r13,%rdi
call   1040 <fclose@plt>
lea    0xd1a(%rip),%rdi
call   10d0 <DieWithError@plt>
lea    0xc0(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jne    13e1 <main+0x1e1>
mov    0x30(%rsp),%r8d
cmp    %r8d,%ebx
je     13a5 <main+0x1a5>
lea    0xd2d(%rip),%rdx
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    $0x80,%esi
mov    %ebx,%ecx
call   1070 <snprintf@plt>
mov    %r14,%rdi
call   10d0 <DieWithError@plt>
mov    0x2c0c(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rcx
mov    0xc(%rsp),%r8d
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    %eax,%r15d
xor    %ebx,%ebx
lea    0xc0(%rsp),%r14
lea    0xc8b(%rip),%r12
jmp    1423 <main+0x223>
nopw   0x0(%rax,%rax,1)
add    %r15d,%ebx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
mov    %eax,%r15d
test   %eax,%eax
je     1378 <main+0x178>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    %r15d,%eax
je     1400 <main+0x200>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r12,%rdi
call   10d0 <DieWithError@plt>
jmp    1400 <main+0x200>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.stat = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Usage: %s <Server IP> <File> [<Port>]\0A\00"
@.str.1 = [27 x i8] c"Failed to stat input file.\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [27 x i8] c"Failed to open input file.\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.4 = [16 x i8] c"socket() failed\00"
@AF_INET = global i32 0
@.str.5 = [17 x i8] c"connect() failed\00"
@.str.6 = [54 x i8] c"send() sent a different number of bytes than expected\00"
@.str.7 = [73 x i8] c"Sent a different number of bytes (%d) than expected from file size (%ld)\00"
@stdout = global i32 0
@.str.8 = [38 x i8] c"%s sent to %s, port %d successfully!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i16
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca [4096 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca %struct.stat
%16 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i16 9100, i16* %8
store i32 0, i32* %13
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 3
br i1 %18, label %22, label %19
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 4
br i1 %21, label %22, label %29
22: ; preds = %19, %2
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %19
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
store i8* %32, i8** %9
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
store i8* %35, i8** %14
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 4
br i1 %37, label %38, label %43
38: ; preds = %29
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 3
%41 = load i8*, i8** %40
%42 = call zeroext i16 @atoi(i8* %41)
store i16 %42, i16* %8
br label %43
43: ; preds = %38, %29
%44 = call i32 @memset(%struct.stat* %15, i32 0, i32 16)
%45 = load i8*, i8** %14
%46 = call i64 @stat(i8* %45, %struct.stat* %15)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = call i32 @DieWithError(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %48, %43
%51 = load i8*, i8** %14
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %52, i32** %10
%53 = load i32*, i32** %10
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = call i32 @DieWithError(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %55, %50
%58 = load i32, i32* @PF_INET
%59 = load i32, i32* @SOCK_STREAM
%60 = load i32, i32* @IPPROTO_TCP
%61 = call i32 @socket(i32 %58, i32 %59, i32 %60)
store i32 %61, i32* %6
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %57
%64 = load i32*, i32** %10
%65 = call i32 @fclose(i32* %64)
%66 = call i32 @DieWithError(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %67
67: ; preds = %63, %57
%68 = bitcast %struct.sockaddr_in* %7 to %struct.stat*
%69 = call i32 @memset(%struct.stat* %68, i32 0, i32 16)
%70 = load i32, i32* @AF_INET
%71 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 3
store i32 %70, i32* %71
%72 = load i8*, i8** %9
%73 = call i32 @inet_addr(i8* %72)
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%75 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %74, i32 0, i32 0
store i32 %73, i32* %75
%76 = load i16, i16* %8
%77 = call i32 @htons(i16 zeroext %76)
%78 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %77, i32* %78
%79 = load i32, i32* %6
%80 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%81 = call i64 @connect(i32 %79, %struct.sockaddr* %80, i32 16)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %67
%84 = load i32*, i32** %10
%85 = call i32 @fclose(i32* %84)
%86 = call i32 @DieWithError(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %87
87: ; preds = %83, %67
br label %88
88: ; preds = %106, %87
%89 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%90 = load i32*, i32** %10
%91 = call i32 @fread(i8* %89, i32 1, i32 4096, i32* %90)
store i32 %91, i32* %12
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %110
93: ; preds = %88
%94 = load i32, i32* %6
%95 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%96 = load i32, i32* %12
%97 = call i32 @send(i32 %94, i8* %95, i32 %96, i32 0)
%98 = load i32, i32* %12
%99 = icmp ne i32 %97, %98
br i1 %99, label %100, label %106
100: ; preds = %93
%101 = load i32*, i32** %10
%102 = call i32 @fclose(i32* %101)
%103 = load i32, i32* %6
%104 = call i32 @close(i32 %103)
%105 = call i32 @DieWithError(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0))
br label %106
106: ; preds = %100, %93
%107 = load i32, i32* %12
%108 = load i32, i32* %13
%109 = add i32 %108, %107
store i32 %109, i32* %13
br label %88
110: ; preds = %88
%111 = load i32, i32* %13
%112 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
%113 = load i32, i32* %112
%114 = icmp ne i32 %111, %113
br i1 %114, label %115, label %123
115: ; preds = %110
%116 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%117 = load i32, i32* %13
%118 = getelementptr inbounds %struct.stat, %struct.stat* %15, i32 0, i32 0
%119 = load i32, i32* %118
%120 = call i32 @snprintf(i8* %116, i32 128, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.7, i64 0, i64 0), i32 %117, i32 %119)
%121 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%122 = call i32 @DieWithError(i8* %121)
br label %123
123: ; preds = %115, %110
%124 = load i32, i32* @stdout
%125 = load i8*, i8** %14
%126 = load i8*, i8** %9
%127 = load i16, i16* %8
%128 = zext i16 %127 to i32
%129 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %125, i8* %126, i32 %128)
%130 = load i32*, i32** %10
%131 = call i32 @fclose(i32* %130)
%132 = load i32, i32* %6
%133 = call i32 @close(i32 %132)
%134 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.stat = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Usage: %s <Server IP> <File> [<Port>]\0A\00"
@.str.1 = [27 x i8] c"Failed to stat input file.\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [27 x i8] c"Failed to open input file.\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.4 = [16 x i8] c"socket() failed\00"
@AF_INET = global i32 0
@.str.5 = [17 x i8] c"connect() failed\00"
@.str.6 = [54 x i8] c"send() sent a different number of bytes than expected\00"
@.str.7 = [73 x i8] c"Sent a different number of bytes (%d) than expected from file size (%ld)\00"
@stdout = global i32 0
@.str.8 = [38 x i8] c"%s sent to %s, port %d successfully!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [4096 x i8]
%5 = alloca %struct.stat
%6 = alloca [128 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.stat* %5 to i8*
%10 = add i32 %0, -5
%11 = icmp ult i32 %10, -2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = icmp eq i32 %0, 4
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = getelementptr inbounds i8*, i8** %1, i64 3
%25 = load i8*, i8** %24
%26 = tail call zeroext i16 @atoi(i8* %25)
br label %27
27: ; preds = %23, %17
%28 = phi i16 [ %26, %23 ], [ 9100, %17 ]
%29 = call i32 @memset(%struct.stat* %5, i32 0, i32 16)
%30 = call i64 @stat(i8* %21, %struct.stat* %5)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %27
%33 = call i32 @DieWithError(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @DieWithError(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
%40 = load i32, i32* @PF_INET
%41 = load i32, i32* @SOCK_STREAM
%42 = load i32, i32* @IPPROTO_TCP
%43 = call i32 @socket(i32 %40, i32 %41, i32 %42)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = call i32 @fclose(i32* %35)
%47 = call i32 @DieWithError(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %45, %39
%49 = bitcast %struct.sockaddr_in* %3 to %struct.stat*
%50 = call i32 @memset(%struct.stat* %49, i32 0, i32 16)
%51 = load i32, i32* @AF_INET
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %51, i32* %52
%53 = call i32 @inet_addr(i8* %19)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %53, i32* %54
%55 = call i32 @htons(i16 zeroext %28)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %55, i32* %56
%57 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%58 = call i64 @connect(i32 %43, %struct.sockaddr* %57, i32 16)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %48
%61 = call i32 @fclose(i32* %35)
%62 = call i32 @DieWithError(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %63
63: ; preds = %60, %48
%64 = call i32 @fread(i8* %8, i32 1, i32 4096, i32* %35)
%65 = icmp eq i32 %64, 0
br i1 %65, label %79, label %66
66: ; preds = %63, %75
%67 = phi i32 [ %77, %75 ], [ %64, %63 ]
%68 = phi i32 [ %76, %75 ], [ 0, %63 ]
%69 = call i32 @send(i32 %43, i8* %8, i32 %67, i32 0)
%70 = icmp eq i32 %69, %67
br i1 %70, label %75, label %71
71: ; preds = %66
%72 = call i32 @fclose(i32* %35)
%73 = call i32 @close(i32 %43)
%74 = call i32 @DieWithError(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0))
br label %75
75: ; preds = %71, %66
%76 = add i32 %67, %68
%77 = call i32 @fread(i8* %8, i32 1, i32 4096, i32* %35)
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %66
79: ; preds = %75, %63
%80 = phi i32 [ 0, %63 ], [ %76, %75 ]
%81 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%82 = load i32, i32* %81
%83 = icmp eq i32 %80, %82
br i1 %83, label %88, label %84
84: ; preds = %79
%85 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%86 = call i32 @snprintf(i8* %85, i32 128, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.7, i64 0, i64 0), i32 %80, i32 %82)
%87 = call i32 @DieWithError(i8* %85)
br label %88
88: ; preds = %84, %79
%89 = load i32, i32* @stdout
%90 = zext i16 %28 to i32
%91 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %21, i8* %19, i32 %90)
%92 = call i32 @fclose(i32* %35)
%93 = call i32 @close(i32 %43)
%94 = call i32 @exit(i32 0)
unreachable
}