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

/* Forward declarations */

/* Type definitions */
struct pptcapi_connection {
  int dummy;
};

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ handle_error(char *, char *);
int open(char *, int, int);
int pptcapi_close_connection(struct pptcapi_connection *, char **);
int /*<<< orphan*/ pptcapi_free_connection_struct(struct pptcapi_connection *);
int pptcapi_initialize_connect(struct pptcapi_connection *, char **);
int pptcapi_send_exit(struct pptcapi_connection *, char **);
struct pptcapi_connection *pptcapi_tcp_connect(char *, int, int, int, int,
                                               char **);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ read_commands(struct pptcapi_connection *, int, int);
char *strerror(int);
int main(int argc, char **argv) {
  if (argc < 2 || argc > 4) {
    printf("usage: %s <input_file>\n", argv[0]);
    return 1;
  }
  int ifd = open(argv[1], O_RDONLY, 0);
  int my_errno = errno;
  if (!ifd) {
    char *err_info = strerror(my_errno);
    if (err_info) {
      printf("unable to open the input file %s: %s\n", argv[1], err_info);
    } else {
      printf("unable to open the input file %s: %s\n", argv[1],
             "unknown error");
    }
    return 1;
  }
  int ofd = 1;
  if (argc == 3) {
    ofd = open(argv[2], O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
    my_errno = errno;
    if (!ofd) {
      close(ifd);
      char *err_info = strerror(my_errno);
      if (err_info) {
        printf("unable to open the input file %s: %s\n", argv[1], err_info);
      } else {
        printf("unable to open the input file %s: %s\n", argv[1],
               "unknown error");
      }
      return 1;
    }
  }
  char *error = 0;
  int tcp_rcv_buffer_size = 70000;
  int tcp_send_buffer_size = 70000;
  int timeout = 5;
  struct pptcapi_connection *connection =
      pptcapi_tcp_connect("localhost", 10022, timeout, tcp_rcv_buffer_size,
                          tcp_send_buffer_size, &error);
  if (!connection) {
    handle_error("failed to connect", error);
    close(ifd);
    if (ofd != 1)
      close(ofd);
    return 1;
  }
  int result = pptcapi_initialize_connect(connection, &error);
  if (result != 1) {
    handle_error("failed to initialize connection", error);
    close(ifd);
    if (ofd != 1)
      close(ofd);
    pptcapi_free_connection_struct(connection);
    return 1;
  }
  if (read_commands(connection, ifd, ofd)) {
    pptcapi_free_connection_struct(connection);
    return 1;
  }
  result = pptcapi_send_exit(connection, &error);
  if (result != 1) {
    handle_error("failed to send exit", error);
    pptcapi_free_connection_struct(connection);
    return 1;
  }
  result = pptcapi_close_connection(connection, &error);
  if (result != 1) {
    handle_error("failed to close connection", error);
    pptcapi_free_connection_struct(connection);
    return 1;
  }
  pptcapi_free_connection_struct(connection);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11da <main+0x2a>
cmpl   $0x4,-0x8(%rbp)
jle    11fb <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e8 <main+0x338>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    128b <main+0xdb>
mov    -0x18(%rbp),%edi
call   10c0 <strerror@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1262 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127f <main+0xcf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xda7(%rip),%rdi
lea    0xdc6(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e8 <main+0x338>
movl   $0x1,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1352 <main+0x1a2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
mov    0x2cfc(%rip),%rax
or     (%rax),%esi
mov    0x2d03(%rip),%rax
mov    (%rax),%edx
mov    0x2d12(%rip),%rax
or     (%rax),%edx
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
mov    0x2cf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    134d <main+0x19d>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   10c0 <strerror@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1324 <main+0x174>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x30(%rbp),%rdx
lea    0xd00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1341 <main+0x191>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xce5(%rip),%rdi
lea    0xd04(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e8 <main+0x338>
jmp    1352 <main+0x1a2>
movq   $0x0,-0x38(%rbp)
movl   $0x11170,-0x3c(%rbp)
movl   $0x11170,-0x40(%rbp)
movl   $0x5,-0x44(%rbp)
mov    -0x44(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
lea    0xccc(%rip),%rdi
mov    $0x2726,%esi
lea    -0x38(%rbp),%r9
call   1030 <pptcapi_tcp_connect@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    13d3 <main+0x223>
mov    -0x38(%rbp),%rsi
lea    0xcae(%rip),%rdi
call   10d0 <handle_error@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x1,-0x24(%rbp)
je     13c7 <main+0x217>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e8 <main+0x338>
mov    -0x50(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1090 <pptcapi_initialize_connect@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x1,-0x54(%rbp)
je     142c <main+0x27c>
mov    -0x38(%rbp),%rsi
lea    0xc70(%rip),%rdi
call   10d0 <handle_error@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x1,-0x24(%rbp)
je     1417 <main+0x267>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x50(%rbp),%rdi
call   1080 <pptcapi_free_connection_struct@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e8 <main+0x338>
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
call   10b0 <read_commands@plt>
cmp    $0x0,%rax
je     145a <main+0x2aa>
mov    -0x50(%rbp),%rdi
call   1080 <pptcapi_free_connection_struct@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e8 <main+0x338>
mov    -0x50(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1060 <pptcapi_send_exit@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x1,-0x54(%rbp)
je     1499 <main+0x2e9>
mov    -0x38(%rbp),%rsi
lea    0xc09(%rip),%rdi
call   10d0 <handle_error@plt>
mov    -0x50(%rbp),%rdi
call   1080 <pptcapi_free_connection_struct@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e8 <main+0x338>
mov    -0x50(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <pptcapi_close_connection@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x1,-0x54(%rbp)
je     14d8 <main+0x328>
mov    -0x38(%rbp),%rsi
lea    0xbde(%rip),%rdi
call   10d0 <handle_error@plt>
mov    -0x50(%rbp),%rdi
call   1080 <pptcapi_free_connection_struct@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e8 <main+0x338>
mov    -0x50(%rbp),%rdi
call   1080 <pptcapi_free_connection_struct@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    -0x5(%rbp),%eax
cmp    $0xfffffffc,%eax
ja     11df <main+0x2f>
mov    (%rbx),%rsi
lea    0xe2d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    13ad <main+0x1fd>
mov    0x8(%rbx),%rdi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <open@plt>
test   %eax,%eax
je     12e0 <main+0x130>
mov    %eax,%r12d
mov    $0x1,%r15d
cmp    $0x3,%ebp
jne    1241 <main+0x91>
mov    0x10(%rbx),%rdi
mov    0x2de4(%rip),%rax
mov    0x2d95(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d9a(%rip),%rax
mov    0x2dab(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   10a0 <open@plt>
mov    %eax,%r15d
test   %eax,%eax
je     1349 <main+0x199>
movq   $0x0,0x8(%rsp)
lea    0xdfb(%rip),%rdi
lea    0x8(%rsp),%r9
mov    $0x2726,%esi
mov    $0x5,%edx
mov    $0x11170,%ecx
mov    $0x11170,%r8d
call   1030 <pptcapi_tcp_connect@plt>
test   %rax,%rax
je     12eb <main+0x13b>
mov    %rax,%r14
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1090 <pptcapi_initialize_connect@plt>
cmp    $0x1,%eax
jne    1320 <main+0x170>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   10b0 <read_commands@plt>
test   %rax,%rax
jne    13a5 <main+0x1f5>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1060 <pptcapi_send_exit@plt>
cmp    $0x1,%eax
jne    1386 <main+0x1d6>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1070 <pptcapi_close_connection@plt>
cmp    $0x1,%eax
jne    1394 <main+0x1e4>
mov    %r14,%rdi
call   1080 <pptcapi_free_connection_struct@plt>
xor    %ebx,%ebx
jmp    13b2 <main+0x202>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
jmp    135c <main+0x1ac>
mov    0x8(%rsp),%rsi
lea    0xd5f(%rip),%rdi
call   10d0 <handle_error@plt>
mov    %r12d,%edi
call   1050 <close@plt>
mov    $0x1,%ebx
cmp    $0x1,%r15d
je     13b2 <main+0x202>
mov    %r15d,%edi
call   1050 <close@plt>
jmp    13b2 <main+0x202>
mov    0x8(%rsp),%rsi
lea    0xd3c(%rip),%rdi
call   10d0 <handle_error@plt>
mov    %r12d,%edi
call   1050 <close@plt>
cmp    $0x1,%r15d
je     13a5 <main+0x1f5>
mov    %r15d,%edi
call   1050 <close@plt>
jmp    13a5 <main+0x1f5>
mov    0x2c78(%rip),%rax
mov    (%rax),%ebp
mov    %r12d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   10c0 <strerror@plt>
mov    0x8(%rbx),%rsi
lea    0xcac(%rip),%rdi
test   %rax,%rax
je     1376 <main+0x1c6>
mov    %rax,%rdx
jmp    137d <main+0x1cd>
lea    0xcc1(%rip),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    13ad <main+0x1fd>
mov    0x8(%rsp),%rsi
lea    0xcf6(%rip),%rdi
jmp    13a0 <main+0x1f0>
mov    0x8(%rsp),%rsi
lea    0xcfc(%rip),%rdi
call   10d0 <handle_error@plt>
mov    %r14,%rdi
call   1080 <pptcapi_free_connection_struct@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pptcapi_connection = type { i32 }
@.str = [24 x i8] c"usage: %s <input_file>\0A\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.1 = [38 x i8] c"unable to open the input file %s: %s\0A\00"
@.str.2 = [14 x i8] c"unknown error\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.3 = [10 x i8] c"localhost\00"
@.str.4 = [18 x i8] c"failed to connect\00"
@.str.5 = [32 x i8] c"failed to initialize connection\00"
@.str.6 = [20 x i8] c"failed to send exit\00"
@.str.7 = [27 x i8] c"failed to close connection\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.pptcapi_connection*
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
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 %27
22: ; preds = %19, %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 1, i32* %3
br label %158
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* %30, i32 %31, i32 0)
store i32 %32, i32* %6
%33 = load i32, i32* @errno
store i32 %33, i32* %7
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %53, label %36
36: ; preds = %27
%37 = load i32, i32* %7
%38 = call i8* @strerror(i32 %37)
store i8* %38, i8** %8
%39 = load i8*, i8** %8
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %47
41: ; preds = %36
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = load i8*, i8** %8
%46 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %44, i8* %45)
br label %52
47: ; preds = %36
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %50, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %47, %41
store i32 1, i32* %3
br label %158
53: ; preds = %27
store i32 1, i32* %9
%54 = load i32, i32* %4
%55 = icmp eq i32 %54, 3
br i1 %55, label %56, label %90
56: ; preds = %53
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = load i32, i32* @O_CREAT
%61 = load i32, i32* @O_WRONLY
%62 = or i32 %60, %61
%63 = load i32, i32* @S_IRUSR
%64 = load i32, i32* @S_IWUSR
%65 = or i32 %63, %64
%66 = call i32 @open(i8* %59, i32 %62, i32 %65)
store i32 %66, i32* %9
%67 = load i32, i32* @errno
store i32 %67, i32* %7
%68 = load i32, i32* %9
%69 = icmp ne i32 %68, 0
br i1 %69, label %89, label %70
70: ; preds = %56
%71 = load i32, i32* %6
%72 = call i32 @close(i32 %71)
%73 = load i32, i32* %7
%74 = call i8* @strerror(i32 %73)
store i8* %74, i8** %10
%75 = load i8*, i8** %10
%76 = icmp ne i8* %75, null
br i1 %76, label %77, label %83
77: ; preds = %70
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = load i8*, i8** %10
%82 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %80, i8* %81)
br label %88
83: ; preds = %70
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 1
%86 = load i8*, i8** %85
%87 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %86, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %88
88: ; preds = %83, %77
store i32 1, i32* %3
br label %158
89: ; preds = %56
br label %90
90: ; preds = %89, %53
store i8* null, i8** %11
store i32 70000, i32* %12
store i32 70000, i32* %13
store i32 5, i32* %14
%91 = load i32, i32* %14
%92 = load i32, i32* %12
%93 = load i32, i32* %13
%94 = call %struct.pptcapi_connection* @pptcapi_tcp_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 10022, i32 %91, i32 %92, i32 %93, i8** %11)
store %struct.pptcapi_connection* %94, %struct.pptcapi_connection** %15
%95 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%96 = icmp ne %struct.pptcapi_connection* %95, null
br i1 %96, label %108, label %97
97: ; preds = %90
%98 = load i8*, i8** %11
%99 = call i32 @handle_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %98)
%100 = load i32, i32* %6
%101 = call i32 @close(i32 %100)
%102 = load i32, i32* %9
%103 = icmp ne i32 %102, 1
br i1 %103, label %104, label %107
104: ; preds = %97
%105 = load i32, i32* %9
%106 = call i32 @close(i32 %105)
br label %107
107: ; preds = %104, %97
store i32 1, i32* %3
br label %158
108: ; preds = %90
%109 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%110 = call i32 @pptcapi_initialize_connect(%struct.pptcapi_connection* %109, i8** %11)
store i32 %110, i32* %16
%111 = load i32, i32* %16
%112 = icmp ne i32 %111, 1
br i1 %112, label %113, label %126
113: ; preds = %108
%114 = load i8*, i8** %11
%115 = call i32 @handle_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %114)
%116 = load i32, i32* %6
%117 = call i32 @close(i32 %116)
%118 = load i32, i32* %9
%119 = icmp ne i32 %118, 1
br i1 %119, label %120, label %123
120: ; preds = %113
%121 = load i32, i32* %9
%122 = call i32 @close(i32 %121)
br label %123
123: ; preds = %120, %113
%124 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%125 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %124)
store i32 1, i32* %3
br label %158
126: ; preds = %108
%127 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%128 = load i32, i32* %6
%129 = load i32, i32* %9
%130 = call i64 @read_commands(%struct.pptcapi_connection* %127, i32 %128, i32 %129)
%131 = icmp ne i64 %130, 0
br i1 %131, label %132, label %135
132: ; preds = %126
%133 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%134 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %133)
store i32 1, i32* %3
br label %158
135: ; preds = %126
%136 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%137 = call i32 @pptcapi_send_exit(%struct.pptcapi_connection* %136, i8** %11)
store i32 %137, i32* %16
%138 = load i32, i32* %16
%139 = icmp ne i32 %138, 1
br i1 %139, label %140, label %145
140: ; preds = %135
%141 = load i8*, i8** %11
%142 = call i32 @handle_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %141)
%143 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%144 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %143)
store i32 1, i32* %3
br label %158
145: ; preds = %135
%146 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%147 = call i32 @pptcapi_close_connection(%struct.pptcapi_connection* %146, i8** %11)
store i32 %147, i32* %16
%148 = load i32, i32* %16
%149 = icmp ne i32 %148, 1
br i1 %149, label %150, label %155
150: ; preds = %145
%151 = load i8*, i8** %11
%152 = call i32 @handle_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %151)
%153 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%154 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %153)
store i32 1, i32* %3
br label %158
155: ; preds = %145
%156 = load %struct.pptcapi_connection*, %struct.pptcapi_connection** %15
%157 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %156)
store i32 0, i32* %3
br label %158
158: ; preds = %155, %150, %140, %132, %123, %107, %88, %52, %22
%159 = load i32, i32* %3
ret i32 %159
}

LLVM IR (-O2):
%struct.pptcapi_connection = type { i32 }
@.str = [24 x i8] c"usage: %s <input_file>\0A\00"
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.1 = [38 x i8] c"unable to open the input file %s: %s\0A\00"
@.str.2 = [14 x i8] c"unknown error\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.3 = [10 x i8] c"localhost\00"
@.str.4 = [18 x i8] c"failed to connect\00"
@.str.5 = [32 x i8] c"failed to initialize connection\00"
@.str.6 = [20 x i8] c"failed to send exit\00"
@.str.7 = [27 x i8] c"failed to close connection\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = add i32 %0, -5
%5 = icmp ult i32 %4, -3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %94
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %9
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = icmp eq i8* %17, null
%19 = load i8*, i8** %10
br i1 %18, label %22, label %20
20: ; preds = %15
%21 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %17)
br label %94
22: ; preds = %15
%23 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %94
24: ; preds = %9
%25 = icmp eq i32 %0, 3
br i1 %25, label %26, label %47
26: ; preds = %24
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_CREAT
%30 = load i32, i32* @O_WRONLY
%31 = or i32 %30, %29
%32 = load i32, i32* @S_IRUSR
%33 = load i32, i32* @S_IWUSR
%34 = or i32 %33, %32
%35 = tail call i32 @open(i8* %28, i32 %31, i32 %34)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %26
%38 = load i32, i32* @errno
%39 = tail call i32 @close(i32 %13)
%40 = tail call i8* @strerror(i32 %38)
%41 = icmp eq i8* %40, null
%42 = load i8*, i8** %10
br i1 %41, label %45, label %43
43: ; preds = %37
%44 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %40)
br label %94
45: ; preds = %37
%46 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %94
47: ; preds = %26, %24
%48 = phi i32 [ %35, %26 ], [ 1, %24 ]
%49 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%50 = call %struct.pptcapi_connection* @pptcapi_tcp_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 10022, i32 5, i32 70000, i32 70000, i8** %3)
%51 = icmp eq %struct.pptcapi_connection* %50, null
br i1 %51, label %52, label %59
52: ; preds = %47
%53 = load i8*, i8** %3
%54 = call i32 @handle_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = call i32 @close(i32 %13)
%56 = icmp eq i32 %48, 1
br i1 %56, label %92, label %57
57: ; preds = %52
%58 = call i32 @close(i32 %48)
br label %92
59: ; preds = %47
%60 = call i32 @pptcapi_initialize_connect(%struct.pptcapi_connection* %50, i8** %3)
%61 = icmp eq i32 %60, 1
br i1 %61, label %71, label %62
62: ; preds = %59
%63 = load i8*, i8** %3
%64 = call i32 @handle_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %63)
%65 = call i32 @close(i32 %13)
%66 = icmp eq i32 %48, 1
br i1 %66, label %69, label %67
67: ; preds = %62
%68 = call i32 @close(i32 %48)
br label %69
69: ; preds = %67, %62
%70 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %50)
br label %92
71: ; preds = %59
%72 = call i64 @read_commands(%struct.pptcapi_connection* %50, i32 %13, i32 %48)
%73 = icmp eq i64 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %71
%75 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %50)
br label %92
76: ; preds = %71
%77 = call i32 @pptcapi_send_exit(%struct.pptcapi_connection* %50, i8** %3)
%78 = icmp eq i32 %77, 1
br i1 %78, label %83, label %79
79: ; preds = %76
%80 = load i8*, i8** %3
%81 = call i32 @handle_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %80)
%82 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %50)
br label %92
83: ; preds = %76
%84 = call i32 @pptcapi_close_connection(%struct.pptcapi_connection* %50, i8** %3)
%85 = icmp eq i32 %84, 1
br i1 %85, label %90, label %86
86: ; preds = %83
%87 = load i8*, i8** %3
%88 = call i32 @handle_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %87)
%89 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %50)
br label %92
90: ; preds = %83
%91 = call i32 @pptcapi_free_connection_struct(%struct.pptcapi_connection* %50)
br label %92
92: ; preds = %69, %74, %79, %86, %90, %52, %57
%93 = phi i32 [ 1, %57 ], [ 1, %52 ], [ 1, %69 ], [ 1, %74 ], [ 1, %79 ], [ 1, %86 ], [ 0, %90 ]
br label %94
94: ; preds = %22, %20, %43, %45, %92, %6
%95 = phi i32 [ 1, %6 ], [ 1, %22 ], [ 1, %20 ], [ %93, %92 ], [ 1, %45 ], [ 1, %43 ]
ret i32 %95
}