#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 sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ server_address;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int send(int, char const *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd;
  int connfd;
  int port_number;
  char filename[256];
  char buffer[10];
  struct sockaddr_in server_address;
  struct hostent *server;
  if (argc < 4) {
    fprintf(
        stderr,
        "Not enough arguments provided.\nUsage: sftp_client <input_filename> "
        "<output_filename> <server_ip_address> <server_port#>\n");
    exit(1);
  }
  port_number = atoi(argv[4]);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    error("Error creating socket");
  }
  server = gethostbyname(argv[3]);
  if (server == NULL) {
    error("Server not found.");
  }
  memset((char *)&server_address, 0, sizeof(server_address));
  server_address.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&server_address.sin_addr.s_addr,
        server->h_length);
  server_address.sin_port = htons(port_number);
  if (connect(sockfd, (struct sockaddr *)&server_address,
              sizeof(server_address)) < 0) {
    error("Error connecting socket");
  }
  FILE *f = fopen(argv[1], "rb");
  if (f == NULL) {
    error("Error opening/reading file");
  }
  while (1) {
    memset(buffer, 0, sizeof(buffer));
    int bytesRead = fread(buffer, sizeof(char), 10, f);
    printf("Bytes read %d\n", bytesRead);
    if (bytesRead > 0) {
      int length = strlen(buffer);
      int bytes_sent = 0;
      const char *bp = buffer;
      while (length > 0) {
        bytes_sent = send(sockfd, bp, strlen(buffer), 0);
        if (bytes_sent <= 0)
          break;
        if (bytes_sent != 10) {
          printf("BYTES SENT OUT: %d !\n", bytes_sent);
        }
        bp += bytes_sent;
        length -= bytes_sent;
      }
    }
    if (bytesRead < 10) {
      if (feof(f))
        puts("EOF");
      if (ferror(f))
        puts("There was an error reading from file.");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    1262 <main+0x42>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12a4 <main+0x84>
lea    0xdda(%rip),%rdi
call   10f0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x140(%rbp)
cmpq   $0x0,-0x140(%rbp)
jne    12d2 <main+0xb2>
lea    0xdc2(%rip),%rdi
call   10f0 <error@plt>
lea    -0x138(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x130(%rbp)
mov    -0x140(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x138(%rbp),%rsi
add    $0x4,%rsi
mov    -0x140(%rbp),%rax
mov    (%rax),%edx
call   10e0 <bcopy@plt>
mov    -0x1c(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x138(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x138(%rbp),%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
jge    1350 <main+0x130>
lea    0xd56(%rip),%rdi
call   10f0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd5a(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    1385 <main+0x165>
lea    0xd3c(%rip),%rdi
call   10f0 <error@plt>
jmp    138a <main+0x16a>
lea    -0x12a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <memset@plt>
lea    -0x12a(%rbp),%rdi
mov    -0x148(%rbp),%rcx
mov    $0x1,%esi
mov    $0xa,%edx
call   1050 <fread@plt>
mov    %eax,-0x14c(%rbp)
mov    -0x14c(%rbp),%esi
lea    0xd0a(%rip),%rdi
call   1090 <printf@plt>
cmpl   $0x0,-0x14c(%rbp)
jle    14be <main+0x29e>
lea    -0x12a(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x150(%rbp)
movl   $0x0,-0x154(%rbp)
lea    -0x12a(%rbp),%rax
mov    %rax,-0x160(%rbp)
cmpl   $0x0,-0x150(%rbp)
jle    14b9 <main+0x299>
mov    -0x14(%rbp),%eax
mov    %eax,-0x16c(%rbp)
mov    -0x160(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    -0x12a(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x16c(%rbp),%edi
mov    -0x168(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %eax,-0x154(%rbp)
cmpl   $0x0,-0x154(%rbp)
jg     1467 <main+0x247>
jmp    14b9 <main+0x299>
cmpl   $0xa,-0x154(%rbp)
je     1486 <main+0x266>
mov    -0x154(%rbp),%esi
lea    0xc65(%rip),%rdi
call   1090 <printf@plt>
mov    -0x154(%rbp),%ecx
mov    -0x160(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x160(%rbp)
mov    -0x154(%rbp),%ecx
mov    -0x150(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x150(%rbp)
jmp    1409 <main+0x1e9>
jmp    14be <main+0x29e>
cmpl   $0xa,-0x14c(%rbp)
jge    1514 <main+0x2f4>
mov    -0x148(%rbp),%rdi
call   10d0 <feof@plt>
cmp    $0x0,%rax
je     14ed <main+0x2cd>
lea    0xc14(%rip),%rdi
call   1030 <puts@plt>
mov    -0x148(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     150f <main+0x2ef>
lea    0xbf6(%rip),%rdi
call   1030 <puts@plt>
jmp    1519 <main+0x2f9>
jmp    138a <main+0x16a>
xor    %eax,%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x3,%edi
jle    140a <main+0x1ea>
mov    %rsi,%r14
mov    0x20(%rsi),%rdi
call   1110 <atoi@plt>
mov    %eax,%r15d
mov    0x2d9b(%rip),%r12
mov    (%r12),%edi
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    1274 <main+0x54>
lea    0xe0a(%rip),%rdi
call   10f0 <error@plt>
mov    0x18(%r14),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1291 <main+0x71>
lea    0xe03(%rip),%rdi
call   10f0 <error@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbp),%rsi
lea    0x14(%rsp),%rdi
mov    0x0(%rbp),%edx
call   10e0 <memmove@plt>
mov    %r15d,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
test   %rax,%rax
jns    12eb <main+0xcb>
lea    0xdbb(%rip),%rdi
call   10f0 <error@plt>
mov    0x8(%r14),%rdi
lea    0xdc3(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
jne    1311 <main+0xf1>
lea    0xdb0(%rip),%rdi
call   10f0 <error@plt>
lea    0x1e(%rsp),%r14
jmp    1329 <main+0x109>
nopl   0x0(%rax,%rax,1)
cmp    $0x9,%ebp
jle    13c3 <main+0x1a3>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    0x8(%rsp),%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
lea    0xd7f(%rip),%rdi
mov    %eax,%esi
call   1090 <printf@plt>
test   %ebp,%ebp
jle    13c3 <main+0x1a3>
mov    %r14,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    1320 <main+0x100>
mov    %eax,%r15d
mov    %r14,%rbx
jmp    138b <main+0x16b>
nopw   0x0(%rax,%rax,1)
mov    %r12d,%eax
add    %rax,%rbx
sub    %r12d,%r15d
jle    1320 <main+0x100>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
test   %eax,%eax
jle    1320 <main+0x100>
mov    %eax,%r12d
cmp    $0xa,%eax
je     1380 <main+0x160>
lea    0xd2d(%rip),%rdi
mov    %r12d,%esi
call   1090 <printf@plt>
jmp    1380 <main+0x160>
mov    0x8(%rsp),%rdi
call   10d0 <feof@plt>
test   %rax,%rax
je     13de <main+0x1be>
lea    0xd23(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     13f9 <main+0x1d9>
lea    0xd0c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
lea    0xbe6(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [121 x i8] c"Not enough arguments provided.\0AUsage: sftp_client <input_filename> <output_filename> <server_ip_address> <server_port#>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"Error creating socket\00"
@.str.2 = [18 x i8] c"Server not found.\00"
@.str.3 = [24 x i8] c"Error connecting socket\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [27 x i8] c"Error opening/reading file\00"
@.str.6 = [15 x i8] c"Bytes read %d\0A\00"
@.str.7 = [22 x i8] c"BYTES SENT OUT: %d !\0A\00"
@.str.8 = [4 x i8] c"EOF\00"
@.str.9 = [38 x i8] c"There was an error reading from file.\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 [256 x i8]
%10 = alloca [10 x i8]
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.hostent*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 4
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 4
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %8
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %24
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call %struct.hostent* @gethostbyname(i8* %39)
store %struct.hostent* %40, %struct.hostent** %12
%41 = load %struct.hostent*, %struct.hostent** %12
%42 = icmp eq %struct.hostent* %41, null
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %36
%46 = bitcast %struct.sockaddr_in* %11 to i8*
%47 = call i32 @memset(i8* %46, i32 0, i32 12)
%48 = load i32, i32* @AF_INET
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %48, i32* %49
%50 = load %struct.hostent*, %struct.hostent** %12
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 1
%52 = load i64, i64* %51
%53 = inttoptr i64 %52 to i8*
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
%56 = bitcast i32* %55 to i8*
%57 = load %struct.hostent*, %struct.hostent** %12
%58 = getelementptr inbounds %struct.hostent, %struct.hostent* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = call i32 @bcopy(i8* %53, i8* %56, i32 %59)
%61 = load i32, i32* %8
%62 = call i32 @htons(i32 %61)
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %62, i32* %63
%64 = load i32, i32* %6
%65 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%66 = call i64 @connect(i32 %64, %struct.sockaddr* %65, i32 12)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %45
%69 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %70
70: ; preds = %68, %45
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i32* @fopen(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %74, i32** %13
%75 = load i32*, i32** %13
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %79
77: ; preds = %70
%78 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %79
79: ; preds = %77, %70
br label %80
80: ; preds = %79, %137
%81 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%82 = call i32 @memset(i8* %81, i32 0, i32 10)
%83 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%84 = load i32*, i32** %13
%85 = call i32 @fread(i8* %83, i32 1, i32 10, i32* %84)
store i32 %85, i32* %14
%86 = load i32, i32* %14
%87 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %86)
%88 = load i32, i32* %14
%89 = icmp sgt i32 %88, 0
br i1 %89, label %90, label %121
90: ; preds = %80
%91 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%92 = call i32 @strlen(i8* %91)
store i32 %92, i32* %15
store i32 0, i32* %16
%93 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
store i8* %93, i8** %17
br label %94
94: ; preds = %112, %90
%95 = load i32, i32* %15
%96 = icmp sgt i32 %95, 0
br i1 %96, label %97, label %120
97: ; preds = %94
%98 = load i32, i32* %6
%99 = load i8*, i8** %17
%100 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%101 = call i32 @strlen(i8* %100)
%102 = call i32 @send(i32 %98, i8* %99, i32 %101, i32 0)
store i32 %102, i32* %16
%103 = load i32, i32* %16
%104 = icmp sle i32 %103, 0
br i1 %104, label %105, label %106
105: ; preds = %97
br label %120
106: ; preds = %97
%107 = load i32, i32* %16
%108 = icmp ne i32 %107, 10
br i1 %108, label %109, label %112
109: ; preds = %106
%110 = load i32, i32* %16
%111 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %110)
br label %112
112: ; preds = %109, %106
%113 = load i32, i32* %16
%114 = load i8*, i8** %17
%115 = sext i32 %113 to i64
%116 = getelementptr inbounds i8, i8* %114, i64 %115
store i8* %116, i8** %17
%117 = load i32, i32* %16
%118 = load i32, i32* %15
%119 = sub nsw i32 %118, %117
store i32 %119, i32* %15
br label %94
120: ; preds = %105, %94
br label %121
121: ; preds = %120, %80
%122 = load i32, i32* %14
%123 = icmp slt i32 %122, 10
br i1 %123, label %124, label %137
124: ; preds = %121
%125 = load i32*, i32** %13
%126 = call i64 @feof(i32* %125)
%127 = icmp ne i64 %126, 0
br i1 %127, label %128, label %130
128: ; preds = %124
%129 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %130
130: ; preds = %128, %124
%131 = load i32*, i32** %13
%132 = call i64 @ferror(i32* %131)
%133 = icmp ne i64 %132, 0
br i1 %133, label %134, label %136
134: ; preds = %130
%135 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0))
br label %136
136: ; preds = %134, %130
br label %138
137: ; preds = %121
br label %80
138: ; preds = %136
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [121 x i8] c"Not enough arguments provided.\0AUsage: sftp_client <input_filename> <output_filename> <server_ip_address> <server_port#>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"Error creating socket\00"
@.str.2 = [18 x i8] c"Server not found.\00"
@.str.3 = [24 x i8] c"Error connecting socket\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [27 x i8] c"Error opening/reading file\00"
@.str.6 = [15 x i8] c"Bytes read %d\0A\00"
@.str.7 = [22 x i8] c"BYTES SENT OUT: %d !\0A\00"
@.str.8 = [4 x i8] c"EOF\00"
@.str.9 = [38 x i8] c"There was an error reading from file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp slt i32 %0, 4
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 4
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = tail call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %12
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call %struct.hostent* @gethostbyname(i8* %24)
%26 = icmp eq %struct.hostent* %25, null
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = call i32 @memset(i8* %6, i32 0, i32 12)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i64 0, i32 1
%34 = load i64, i64* %33
%35 = inttoptr i64 %34 to i8*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%37 = bitcast i32* %36 to i8*
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i64 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @htons(i32 %15)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %40, i32* %41
%42 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%43 = call i64 @connect(i32 %18, %struct.sockaddr* %42, i32 12)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %29
%46 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %29
%48 = getelementptr inbounds i8*, i8** %1, i64 1
%49 = load i8*, i8** %48
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %47
br label %55
55: ; preds = %54, %78
%56 = call i32 @memset(i8* %5, i32 0, i32 10)
%57 = call i32 @fread(i8* %5, i32 1, i32 10, i32* %50)
%58 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %57)
%59 = icmp sgt i32 %57, 0
br i1 %59, label %60, label %80
60: ; preds = %55
%61 = call i32 @strlen(i8* %5)
%62 = icmp sgt i32 %61, 0
br i1 %62, label %63, label %78
63: ; preds = %60, %73
%64 = phi i8* [ %75, %73 ], [ %5, %60 ]
%65 = phi i32 [ %76, %73 ], [ %61, %60 ]
%66 = call i32 @strlen(i8* %5)
%67 = call i32 @send(i32 %18, i8* %64, i32 %66, i32 0)
%68 = icmp slt i32 %67, 1
br i1 %68, label %78, label %69
69: ; preds = %63
%70 = icmp eq i32 %67, 10
br i1 %70, label %73, label %71
71: ; preds = %69
%72 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %67)
br label %73
73: ; preds = %71, %69
%74 = zext i32 %67 to i64
%75 = getelementptr inbounds i8, i8* %64, i64 %74
%76 = sub nsw i32 %65, %67
%77 = icmp sgt i32 %76, 0
br i1 %77, label %63, label %78
78: ; preds = %63, %73, %60
%79 = icmp slt i32 %57, 10
br i1 %79, label %80, label %55
80: ; preds = %55, %78
%81 = call i64 @feof(i32* %50)
%82 = icmp eq i64 %81, 0
br i1 %82, label %85, label %83
83: ; preds = %80
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %85
85: ; preds = %83, %80
%86 = call i64 @ferror(i32* %50)
%87 = icmp eq i64 %86, 0
br i1 %87, label %90, label %88
88: ; preds = %85
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0))
br label %90
90: ; preds = %88, %85
ret i32 0
}