#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 {
  void *sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
  int /*<<< orphan*/ h_addrtype;
};
typedef int /*<<< orphan*/ servAddr;
typedef int /*<<< orphan*/ localAddr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, unsigned char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stdout;
int strlen(unsigned char *);
scalar_t__ system(char *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  FILE *pFile;
  int comOK = 1, n = 0;
  char ping[48];
  unsigned char str[512];
  int sd, rc;
  struct sockaddr_in localAddr, servAddr;
  struct hostent *h;
  if (argc < 4) {
    printf("\n\n---  usage: %s <Server Address> <Port Number> <File Path>\n--- "
           "Example ./file_tcp 192.168.0.85 9100 "
           "/var/www/pcl/cycle_1234.pcl\n\n\n",
           argv[0]);
    exit(0);
  }
  sprintf(ping, "ping -c1 -w1 %s >/dev/null 2>&1", argv[1]);
  pFile = fopen(argv[3], "r");
  if (pFile == NULL) {
    perror("Error opening file");
    return (-1);
    comOK = 0;
    exit(0);
  } else {
    if (system(ping) != 0) {
      comOK = 0;
      printf("\nPrinter Disconnected\n\nETHERNET PRINTING FAILED\n");
    } else {
      h = gethostbyname(argv[1]);
      if (h == NULL) {
        printf("\n%s: unknown host '%s'\n\nETHERNET PRINTING FAILED\n", argv[0],
               argv[1]);
        comOK = 0;
        exit(0);
      }
      servAddr.sin_family = h->h_addrtype;
      memcpy((char *)&servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
      servAddr.sin_port = htons(atoi(argv[2]));
      sd = socket(AF_INET, SOCK_STREAM, 0);
      if (sd < 0) {
        perror("\nPrinter Disconnected (1)\n\nETHERNET PRINTING FAILED\n");
        comOK = 0;
        exit(0);
      }
      localAddr.sin_family = AF_INET;
      localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
      localAddr.sin_port = htons(0);
      rc = bind(sd, (struct sockaddr *)&localAddr, sizeof(localAddr));
      if (rc < 0) {
        printf("%s: cannot bind port TCP %u\n\nETHERNET PRINTING FAILED\n",
               argv[0], atoi(argv[2]));
        perror("error ");
        comOK = 0;
        exit(0);
      }
      rc = connect(sd, (struct sockaddr *)&servAddr, sizeof(servAddr));
      if (rc < 0) {
        perror("\nPrinter Disconnected (2)\n\nETHERNET PRINTING FAILED\n");
        comOK = 0;
        exit(0);
      }
      while (fgets(str, 512, pFile) != NULL) {
        n = strlen(str);
        str[n] = '\0';
        if (comOK == 1) {
          rc = send(sd, str, n, 0);
          if (rc < 0) {
            printf("\ncannot send data to printer/server\n\nETHERNET PRINTING "
                   "FAILED\n");
            close(sd);
            comOK = 0;
            exit(0);
          }
        }
        usleep(100000);
      }
    }
    fclose(pFile);
  }
  if (comOK == 1)
    printf("ETHERNET PRINTING COMPLETED\n");
  fflush(stdout);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    129d <main+0x4d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %edi,%edi
call   1140 <exit@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdd4(%rip),%rsi
call   1130 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xde0(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12f0 <main+0xa0>
lea    0xdc7(%rip),%rdi
call   1110 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d5 <main+0x385>
lea    -0x50(%rbp),%rdi
call   1050 <system@plt>
cmp    $0x0,%rax
je     131d <main+0xcd>
movl   $0x0,-0x1c(%rbp)
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    159f <main+0x34f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x280(%rbp)
cmpq   $0x0,-0x280(%rbp)
jne    136a <main+0x11a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x1c(%rbp)
xor    %edi,%edi
call   1140 <exit@plt>
mov    -0x280(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x26c(%rbp)
lea    -0x278(%rbp),%rdi
add    $0x8,%rdi
mov    -0x280(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x280(%rbp),%rax
mov    (%rax),%edx
call   10d0 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %rax,-0x278(%rbp)
mov    0x2c26(%rip),%rax
mov    (%rax),%edi
mov    0x2c05(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x254(%rbp)
cmpl   $0x0,-0x254(%rbp)
jge    1401 <main+0x1b1>
lea    0xd2e(%rip),%rdi
call   1110 <perror@plt>
movl   $0x0,-0x1c(%rbp)
xor    %edi,%edi
call   1140 <exit@plt>
mov    0x2be0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x25c(%rbp)
mov    0x2bc9(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x260(%rbp)
xor    %edi,%edi
call   1060 <htons@plt>
mov    %rax,-0x268(%rbp)
mov    -0x254(%rbp),%edi
lea    -0x268(%rbp),%rsi
mov    $0x10,%edx
call   10f0 <bind@plt>
mov    %eax,-0x258(%rbp)
cmpl   $0x0,-0x258(%rbp)
jge    14a8 <main+0x258>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x288(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    -0x288(%rbp),%rsi
mov    %eax,%edx
lea    0xcca(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xcf3(%rip),%rdi
call   1110 <perror@plt>
movl   $0x0,-0x1c(%rbp)
xor    %edi,%edi
call   1140 <exit@plt>
mov    -0x254(%rbp),%edi
lea    -0x278(%rbp),%rsi
mov    $0x10,%edx
call   1150 <connect@plt>
mov    %eax,-0x258(%rbp)
cmpl   $0x0,-0x258(%rbp)
jge    14ec <main+0x29c>
lea    0xcb6(%rip),%rdi
call   1110 <perror@plt>
movl   $0x0,-0x1c(%rbp)
xor    %edi,%edi
call   1140 <exit@plt>
jmp    14f1 <main+0x2a1>
lea    -0x250(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   10b0 <fgets@plt>
cmp    $0x0,%rax
je     159a <main+0x34a>
lea    -0x250(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
movb   $0x0,-0x250(%rbp,%rax,1)
cmpl   $0x1,-0x1c(%rbp)
jne    158b <main+0x33b>
mov    -0x254(%rbp),%edi
lea    -0x250(%rbp),%rsi
mov    -0x20(%rbp),%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %eax,-0x258(%rbp)
cmpl   $0x0,-0x258(%rbp)
jge    1586 <main+0x336>
lea    0xc5e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x254(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x1c(%rbp)
xor    %edi,%edi
call   1140 <exit@plt>
jmp    158b <main+0x33b>
mov    $0x186a0,%edi
call   1160 <usleep@plt>
jmp    14f1 <main+0x2a1>
jmp    159f <main+0x34f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x1c(%rbp)
jne    15c0 <main+0x370>
lea    0xc4a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2a01(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x290,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x258,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jle    144e <main+0x1ee>
mov    0x8(%r14),%rdx
lea    0xe00(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1140 <sprintf@plt>
mov    0x18(%r14),%rdi
lea    0xe0b(%rip),%rsi
call   1110 <fopen@plt>
test   %rax,%rax
je     1421 <main+0x1c1>
mov    %rax,%r15
lea    0x20(%rsp),%rdi
call   1060 <system@plt>
test   %rax,%rax
je     12d2 <main+0x72>
lea    0xf2d(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    1403 <main+0x1a3>
mov    0x8(%r14),%rdi
call   10d0 <gethostbyname@plt>
test   %rax,%rax
je     1466 <main+0x206>
mov    0x10(%rax),%ecx
mov    %ecx,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    0x8(%rax),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
call   10e0 <memcpy@plt>
mov    0x10(%r14),%rdi
call   1130 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %rax,(%rsp)
mov    0x2cd0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2caf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
test   %eax,%eax
js     1482 <main+0x222>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x1c(%rsp)
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,0x18(%rsp)
xor    %edi,%edi
call   1070 <htons@plt>
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   1100 <bind@plt>
test   %eax,%eax
js     148b <main+0x22b>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   1160 <connect@plt>
test   %eax,%eax
js     14b3 <main+0x253>
lea    0x50(%rsp),%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   10c0 <fgets@plt>
test   %rax,%rax
je     13ef <main+0x18f>
lea    0x50(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdx
movb   $0x0,0x50(%rsp,%rdx,1)
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1080 <send@plt>
test   %eax,%eax
js     1434 <main+0x1d4>
mov    $0x186a0,%edi
call   1170 <usleep@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   10c0 <fgets@plt>
test   %rax,%rax
jne    13b0 <main+0x150>
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0xd95(%rip),%rdi
call   1030 <puts@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
call   10f0 <fflush@plt>
xor    %eax,%eax
add    $0x258,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc7e(%rip),%rdi
call   1120 <perror@plt>
mov    $0xffffffff,%eax
jmp    1413 <main+0x1b3>
lea    0xd74(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1150 <exit@plt>
mov    (%r14),%rsi
lea    0xba8(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
mov    (%r14),%rsi
mov    0x8(%r14),%rdx
lea    0xc45(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
lea    0xc62(%rip),%rdi
jmp    14ba <main+0x25a>
mov    (%r14),%rbx
mov    0x10(%r14),%rdi
call   1130 <atoi@plt>
lea    0xc82(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xca6(%rip),%rdi
jmp    14ba <main+0x25a>
lea    0xca4(%rip),%rdi
call   1120 <perror@plt>
xor    %edi,%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32*, i32 }
%struct.sockaddr = type { i32 }
@.str = [132 x i8] c"\0A\0A--- usage: %s <Server Address> <Port Number> <File Path>\0A--- Example ./file_tcp 192.168.0.85 9100 /var/www/pcl/cycle_1234.pcl\0A\0A\0A\00"
@.str.1 = [32 x i8] c"ping -c1 -w1 %s >/dev/null 2>&1\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"Error opening file\00"
@.str.4 = [49 x i8] c"\0APrinter Disconnected\0A\0AETHERNET PRINTING FAILED\0A\00"
@.str.5 = [50 x i8] c"\0A%s: unknown host '%s'\0A\0AETHERNET PRINTING FAILED\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [53 x i8] c"\0APrinter Disconnected (1)\0A\0AETHERNET PRINTING FAILED\0A\00"
@INADDR_ANY = global i32 0
@.str.7 = [55 x i8] c"%s: cannot bind port TCP %u\0A\0AETHERNET PRINTING FAILED\0A\00"
@.str.8 = [7 x i8] c"error \00"
@.str.9 = [53 x i8] c"\0APrinter Disconnected (2)\0A\0AETHERNET PRINTING FAILED\0A\00"
@.str.10 = [63 x i8] c"\0Acannot send data to printer/server\0A\0AETHERNET PRINTING FAILED\0A\00"
@.str.11 = [29 x i8] c"ETHERNET PRINTING COMPLETED\0A\00"
@stdout = global i32 0
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 [48 x i8]
%10 = alloca [512 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.sockaddr_in
%14 = alloca %struct.sockaddr_in
%15 = alloca %struct.hostent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 0, i32* %8
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %2
%25 = getelementptr inbounds [48 x i8], [48 x i8]* %9, i64 0, i64 0
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %24
%37 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %166
38: ; preds = %24
%39 = getelementptr inbounds [48 x i8], [48 x i8]* %9, i64 0, i64 0
%40 = call i64 @system(i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
store i32 0, i32* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
br label %155
44: ; preds = %38
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call %struct.hostent* @gethostbyname(i8* %47)
store %struct.hostent* %48, %struct.hostent** %15
%49 = load %struct.hostent*, %struct.hostent** %15
%50 = icmp eq %struct.hostent* %49, null
br i1 %50, label %51, label %60
51: ; preds = %44
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %54, i8* %57)
store i32 0, i32* %7
%59 = call i32 @exit(i32 0)
unreachable
60: ; preds = %44
%61 = load %struct.hostent*, %struct.hostent** %15
%62 = getelementptr inbounds %struct.hostent, %struct.hostent* %61, i32 0, i32 2
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %63, i32* %64
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%66 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %65, i32 0, i32 0
%67 = bitcast i32* %66 to i8*
%68 = load %struct.hostent*, %struct.hostent** %15
%69 = getelementptr inbounds %struct.hostent, %struct.hostent* %68, i32 0, i32 1
%70 = load i32*, i32** %69
%71 = getelementptr inbounds i32, i32* %70, i64 0
%72 = load i32, i32* %71
%73 = load %struct.hostent*, %struct.hostent** %15
%74 = getelementptr inbounds %struct.hostent, %struct.hostent* %73, i32 0, i32 0
%75 = load i32, i32* %74
%76 = call i32 @memcpy(i8* %67, i32 %72, i32 %75)
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 2
%79 = load i8*, i8** %78
%80 = call i32 @atoi(i8* %79)
%81 = call i8* @htons(i32 %80)
%82 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
store i8* %81, i8** %82
%83 = load i32, i32* @AF_INET
%84 = load i32, i32* @SOCK_STREAM
%85 = call i32 @socket(i32 %83, i32 %84, i32 0)
store i32 %85, i32* %11
%86 = load i32, i32* %11
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %60
%89 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %7
%90 = call i32 @exit(i32 0)
unreachable
91: ; preds = %60
%92 = load i32, i32* @AF_INET
%93 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %92, i32* %93
%94 = load i32, i32* @INADDR_ANY
%95 = call i32 @htonl(i32 %94)
%96 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%97 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %96, i32 0, i32 0
store i32 %95, i32* %97
%98 = call i8* @htons(i32 0)
%99 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
store i8* %98, i8** %99
%100 = load i32, i32* %11
%101 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%102 = call i32 @bind(i32 %100, %struct.sockaddr* %101, i32 16)
store i32 %102, i32* %12
%103 = load i32, i32* %12
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %116
105: ; preds = %91
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 0
%108 = load i8*, i8** %107
%109 = load i8**, i8*** %5
%110 = getelementptr inbounds i8*, i8** %109, i64 2
%111 = load i8*, i8** %110
%112 = call i32 @atoi(i8* %111)
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0), i8* %108, i32 %112)
%114 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %7
%115 = call i32 @exit(i32 0)
unreachable
116: ; preds = %91
%117 = load i32, i32* %11
%118 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%119 = call i32 @connect(i32 %117, %struct.sockaddr* %118, i32 16)
store i32 %119, i32* %12
%120 = load i32, i32* %12
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %125
122: ; preds = %116
%123 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %7
%124 = call i32 @exit(i32 0)
unreachable
125: ; preds = %116
br label %126
126: ; preds = %152, %125
%127 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%128 = load i32*, i32** %6
%129 = call i32* @fgets(i8* %127, i32 512, i32* %128)
%130 = icmp ne i32* %129, null
br i1 %130, label %131, label %154
131: ; preds = %126
%132 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%133 = call i32 @strlen(i8* %132)
store i32 %133, i32* %8
%134 = load i32, i32* %8
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 %135
store i8 0, i8* %136
%137 = load i32, i32* %7
%138 = icmp eq i32 %137, 1
br i1 %138, label %139, label %152
139: ; preds = %131
%140 = load i32, i32* %11
%141 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%142 = load i32, i32* %8
%143 = call i32 @send(i32 %140, i8* %141, i32 %142, i32 0)
store i32 %143, i32* %12
%144 = load i32, i32* %12
%145 = icmp slt i32 %144, 0
br i1 %145, label %146, label %151
146: ; preds = %139
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.10, i64 0, i64 0))
%148 = load i32, i32* %11
%149 = call i32 @close(i32 %148)
store i32 0, i32* %7
%150 = call i32 @exit(i32 0)
unreachable
151: ; preds = %139
br label %152
152: ; preds = %151, %131
%153 = call i32 @usleep(i32 100000)
br label %126
154: ; preds = %126
br label %155
155: ; preds = %154, %42
%156 = load i32*, i32** %6
%157 = call i32 @fclose(i32* %156)
br label %158
158: ; preds = %155
%159 = load i32, i32* %7
%160 = icmp eq i32 %159, 1
br i1 %160, label %161, label %163
161: ; preds = %158
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
br label %163
163: ; preds = %161, %158
%164 = load i32, i32* @stdout
%165 = call i32 @fflush(i32 %164)
store i32 0, i32* %3
br label %166
166: ; preds = %163, %36
%167 = load i32, i32* %3
ret i32 %167
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32*, i32 }
%struct.sockaddr = type { i32 }
@.str = [132 x i8] c"\0A\0A--- usage: %s <Server Address> <Port Number> <File Path>\0A--- Example ./file_tcp 192.168.0.85 9100 /var/www/pcl/cycle_1234.pcl\0A\0A\0A\00"
@.str.1 = [32 x i8] c"ping -c1 -w1 %s >/dev/null 2>&1\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"Error opening file\00"
@.str.5 = [50 x i8] c"\0A%s: unknown host '%s'\0A\0AETHERNET PRINTING FAILED\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [53 x i8] c"\0APrinter Disconnected (1)\0A\0AETHERNET PRINTING FAILED\0A\00"
@INADDR_ANY = global i32 0
@.str.7 = [55 x i8] c"%s: cannot bind port TCP %u\0A\0AETHERNET PRINTING FAILED\0A\00"
@.str.8 = [7 x i8] c"error \00"
@.str.9 = [53 x i8] c"\0APrinter Disconnected (2)\0A\0AETHERNET PRINTING FAILED\0A\00"
@stdout = global i32 0
@str = [28 x i8] c"ETHERNET PRINTING COMPLETED\00"
@str.12 = [62 x i8] c"\0Acannot send data to printer/server\0A\0AETHERNET PRINTING FAILED\00"
@str.13 = [48 x i8] c"\0APrinter Disconnected\0A\0AETHERNET PRINTING FAILED\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [48 x i8]
%4 = alloca [512 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = icmp slt i32 %0, 4
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %113
26: ; preds = %16
%27 = call i64 @system(i8* %7)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.13, i64 0, i64 0))
%31 = tail call i32 @fclose(i32* %22)
br label %110
32: ; preds = %26
%33 = load i8*, i8** %17
%34 = tail call %struct.hostent* @gethostbyname(i8* %33)
%35 = icmp eq %struct.hostent* %34, null
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i8*, i8** %1
%38 = load i8*, i8** %17
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i8* %37, i8* %38)
%40 = tail call i32 @exit(i32 0)
unreachable
41: ; preds = %32
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i64 0, i32 2
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %43, i32* %44
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
%46 = bitcast i32* %45 to i8*
%47 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i64 0, i32 1
%48 = load i32*, i32** %47
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i64 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @memcpy(i8* %46, i32 %49, i32 %51)
%53 = getelementptr inbounds i8*, i8** %1, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
%56 = call i8* @htons(i32 %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i8* %56, i8** %57
%58 = load i32, i32* @AF_INET
%59 = load i32, i32* @SOCK_STREAM
%60 = call i32 @socket(i32 %58, i32 %59, i32 0)
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %41
%63 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0))
%64 = call i32 @exit(i32 0)
unreachable
65: ; preds = %41
%66 = load i32, i32* @AF_INET
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %66, i32* %67
%68 = load i32, i32* @INADDR_ANY
%69 = call i32 @htonl(i32 %68)
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %69, i32* %70
%71 = call i8* @htons(i32 0)
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i8* %71, i8** %72
%73 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%74 = call i32 @bind(i32 %60, %struct.sockaddr* %73, i32 16)
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %83
76: ; preds = %65
%77 = load i8*, i8** %1
%78 = load i8*, i8** %53
%79 = call i32 @atoi(i8* %78)
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0), i8* %77, i32 %79)
%81 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%82 = call i32 @exit(i32 0)
unreachable
83: ; preds = %65
%84 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%85 = call i32 @connect(i32 %60, %struct.sockaddr* %84, i32 16)
%86 = icmp slt i32 %85, 0
br i1 %86, label %90, label %87
87: ; preds = %83
%88 = call i32* @fgets(i8* %8, i32 512, i32* %22)
%89 = icmp eq i32* %88, null
br i1 %89, label %107, label %93
90: ; preds = %83
%91 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0))
%92 = call i32 @exit(i32 0)
unreachable
93: ; preds = %87, %103
%94 = call i32 @strlen(i8* %8)
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %95
store i8 0, i8* %96
%97 = call i32 @send(i32 %60, i8* %8, i32 %94, i32 0)
%98 = icmp slt i32 %97, 0
br i1 %98, label %99, label %103
99: ; preds = %93
%100 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.12, i64 0, i64 0))
%101 = call i32 @close(i32 %60)
%102 = call i32 @exit(i32 0)
unreachable
103: ; preds = %93
%104 = call i32 @usleep(i32 100000)
%105 = call i32* @fgets(i8* %8, i32 512, i32* %22)
%106 = icmp eq i32* %105, null
br i1 %106, label %107, label %93
107: ; preds = %103, %87
%108 = call i32 @fclose(i32* %22)
%109 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %110
110: ; preds = %29, %107
%111 = load i32, i32* @stdout
%112 = call i32 @fflush(i32 %111)
br label %113
113: ; preds = %110, %24
%114 = phi i32 [ -1, %24 ], [ 0, %110 ]
ret i32 %114
}