#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 katcp_dispatch {
  int dummy;
};
struct katcl_line {
  int dummy;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EX_OK;
int /*<<< orphan*/ EX_UNAVAILABLE;
int /*<<< orphan*/ FD_CLOEXEC;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ arg_inform_katcl(struct katcl_line *);
int /*<<< orphan*/ arg_reply_katcl(struct katcl_line *);
scalar_t__ arg_request_katcl(struct katcl_line *);
int /*<<< orphan*/ close(int);
struct katcl_line *create_katcl(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ have_katcl(struct katcl_line *);
int open(char *, int /*<<< orphan*/);
int read_katcl(struct katcl_line *);
int relay_katcl(struct katcl_line *, struct katcl_line *);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int /*<<< orphan*/ write_katcl(struct katcl_line *);
int pipe_from_file_katcp(struct katcp_dispatch *dl, char *file) {
  int fds[2], fd;
  pid_t pid;
  struct katcl_line *pl, *fl;
  int done;
  int state, rsvp;
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
    return -1;
  }
  pid = fork();
  if (pid < 0) {
    close(fds[0]);
    close(fds[1]);
    return -1;
  }
  if (pid > 0) {
    close(fds[0]);
    fcntl(fds[1], F_SETFD, FD_CLOEXEC);
    return fds[1];
  }
  close(fds[1]);
  fd = open(file, O_RDONLY);
  if (fd < 0) {
    exit(EX_UNAVAILABLE);
  }
  pl = create_katcl(fds[0]);
  fl = create_katcl(fd);
  if ((pl == NULL) || (fl == NULL)) {
    exit(EX_UNAVAILABLE);
  }
  for (done = 0; done == 0;) {
    done = read_katcl(fl);
    if (done < 0) {
      exit(EX_UNAVAILABLE);
    }
    while (have_katcl(fl)) {
      if (arg_request_katcl(fl)) {
        rsvp = relay_katcl(fl, pl);
        if (rsvp < 0) {
          exit(EX_UNAVAILABLE);
        } else if (!write_katcl(pl)) {
          exit(EX_UNAVAILABLE);
        }
        for (state = 1; state != 3;) {
          switch (state) {
          case 1:
            rsvp = read_katcl(pl);
            if (rsvp == 0)
              state = 2;
            break;
          case 2:
            if (have_katcl(pl)) {
              if (arg_reply_katcl(pl)) {
                state = 3;
              } else if (arg_inform_katcl(pl)) {
                state = 2;
              }
            } else {
              state = 1;
            }
            break;
          }
        }
      }
    }
  }
  exit(EX_OK);
  return -1;
}


x86 assembly (clang, -O0):
<pipe_from_file_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rcx
xor    %edx,%edx
call   10b0 <socketpair@plt>
cmp    $0x0,%rax
jge    1223 <pipe_from_file_katcp+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    1485 <pipe_from_file_katcp+0x2a5>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1255 <pipe_from_file_katcp+0x75>
mov    -0x20(%rbp),%edi
call   10a0 <close@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1485 <pipe_from_file_katcp+0x2a5>
cmpq   $0x0,-0x30(%rbp)
jle    128d <pipe_from_file_katcp+0xad>
mov    -0x20(%rbp),%edi
call   10a0 <close@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
mov    0x2d45(%rip),%rax
mov    (%rax),%edx
call   1050 <fcntl@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1485 <pipe_from_file_katcp+0x2a5>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12c2 <pipe_from_file_katcp+0xe2>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x20(%rbp),%edi
call   10c0 <create_katcl@plt>
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%edi
call   10c0 <create_katcl@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12f0 <pipe_from_file_katcp+0x110>
cmpq   $0x0,-0x40(%rbp)
jne    12fe <pipe_from_file_katcp+0x11e>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    1477 <pipe_from_file_katcp+0x297>
mov    -0x40(%rbp),%rdi
call   1070 <read_katcl@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1333 <pipe_from_file_katcp+0x153>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    1338 <pipe_from_file_katcp+0x158>
mov    -0x40(%rbp),%rdi
call   10f0 <have_katcl@plt>
cmp    $0x0,%rax
je     1472 <pipe_from_file_katcp+0x292>
mov    -0x40(%rbp),%rdi
call   1080 <arg_request_katcl@plt>
cmp    $0x0,%rax
je     146d <pipe_from_file_katcp+0x28d>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <relay_katcl@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    1386 <pipe_from_file_katcp+0x1a6>
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x38(%rbp),%rdi
call   1040 <write_katcl@plt>
cmp    $0x0,%eax
jne    13a6 <pipe_from_file_katcp+0x1c6>
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    13ab <pipe_from_file_katcp+0x1cb>
movl   $0x1,-0x48(%rbp)
cmpl   $0x3,-0x48(%rbp)
je     1468 <pipe_from_file_katcp+0x288>
mov    -0x48(%rbp),%eax
mov    %eax,-0x50(%rbp)
sub    $0x1,%eax
je     13e1 <pipe_from_file_katcp+0x201>
jmp    13d0 <pipe_from_file_katcp+0x1f0>
mov    -0x50(%rbp),%eax
sub    $0x2,%eax
je     1403 <pipe_from_file_katcp+0x223>
jmp    1463 <pipe_from_file_katcp+0x283>
mov    -0x38(%rbp),%rdi
call   1070 <read_katcl@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    13fe <pipe_from_file_katcp+0x21e>
movl   $0x2,-0x48(%rbp)
jmp    1463 <pipe_from_file_katcp+0x283>
mov    -0x38(%rbp),%rdi
call   10f0 <have_katcl@plt>
cmp    $0x0,%rax
je     1457 <pipe_from_file_katcp+0x277>
mov    -0x38(%rbp),%rdi
call   1090 <arg_reply_katcl@plt>
cmp    $0x0,%eax
je     1434 <pipe_from_file_katcp+0x254>
movl   $0x3,-0x48(%rbp)
jmp    1452 <pipe_from_file_katcp+0x272>
mov    -0x38(%rbp),%rdi
call   1030 <arg_inform_katcl@plt>
cmp    $0x0,%eax
je     144d <pipe_from_file_katcp+0x26d>
movl   $0x2,-0x48(%rbp)
jmp    1452 <pipe_from_file_katcp+0x272>
jmp    145e <pipe_from_file_katcp+0x27e>
movl   $0x1,-0x48(%rbp)
jmp    1463 <pipe_from_file_katcp+0x283>
jmp    13b2 <pipe_from_file_katcp+0x1d2>
jmp    146d <pipe_from_file_katcp+0x28d>
jmp    1338 <pipe_from_file_katcp+0x158>
jmp    1305 <pipe_from_file_katcp+0x125>
mov    0x2b3a(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe_from_file_katcp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   10b0 <socketpair@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     125d <pipe_from_file_katcp+0x7d>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     124b <pipe_from_file_katcp+0x6b>
je     1268 <pipe_from_file_katcp+0x88>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
mov    0xc(%rsp),%edi
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
call   1050 <fcntl@plt>
mov    0xc(%rsp),%ebp
jmp    125d <pipe_from_file_katcp+0x7d>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
mov    0xc(%rsp),%edi
call   10a0 <close@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0xc(%rsp),%edi
call   10a0 <close@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10d0 <open@plt>
test   %eax,%eax
jns    1294 <pipe_from_file_katcp+0xb4>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%edi
call   10c0 <create_katcl@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   10c0 <create_katcl@plt>
test   %rbx,%rbx
je     1286 <pipe_from_file_katcp+0xa6>
mov    %rax,%r14
test   %rax,%rax
jne    12c0 <pipe_from_file_katcp+0xe0>
jmp    1286 <pipe_from_file_katcp+0xa6>
test   %ebp,%ebp
jne    1366 <pipe_from_file_katcp+0x186>
mov    %r14,%rdi
call   1070 <read_katcl@plt>
test   %eax,%eax
js     1286 <pipe_from_file_katcp+0xa6>
mov    %eax,%ebp
mov    %r14,%rdi
call   10f0 <have_katcl@plt>
test   %rax,%rax
je     12b8 <pipe_from_file_katcp+0xd8>
mov    %r14,%rdi
call   1080 <arg_request_katcl@plt>
test   %rax,%rax
je     12ce <pipe_from_file_katcp+0xee>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <relay_katcl@plt>
test   %eax,%eax
js     1286 <pipe_from_file_katcp+0xa6>
mov    %rbx,%rdi
call   1040 <write_katcl@plt>
test   %eax,%eax
je     1286 <pipe_from_file_katcp+0xa6>
mov    $0x1,%ecx
nopl   0x0(%rax,%rax,1)
cmp    $0x3,%ecx
je     12ce <pipe_from_file_katcp+0xee>
cmp    $0x2,%ecx
je     1334 <pipe_from_file_katcp+0x154>
cmp    $0x1,%ecx
jne    1310 <pipe_from_file_katcp+0x130>
mov    %rbx,%rdi
call   1070 <read_katcl@plt>
cmp    $0x1,%eax
mov    $0x1,%ecx
adc    $0x0,%ecx
jmp    1310 <pipe_from_file_katcp+0x130>
mov    %rbx,%rdi
call   10f0 <have_katcl@plt>
mov    $0x1,%ecx
test   %rax,%rax
je     1310 <pipe_from_file_katcp+0x130>
mov    %rbx,%rdi
call   1090 <arg_reply_katcl@plt>
mov    $0x3,%ecx
test   %eax,%eax
jne    1310 <pipe_from_file_katcp+0x130>
mov    %rbx,%rdi
call   1030 <arg_inform_katcl@plt>
mov    $0x2,%ecx
jmp    1310 <pipe_from_file_katcp+0x130>
mov    0x2c4b(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
%struct.katcl_line = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@O_RDONLY = global i32 0
@EX_UNAVAILABLE = global i32 0
@EX_OK = global i32 0
define i32 @pipe_from_file_katcp(%struct.katcp_dispatch* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.katcp_dispatch*
%5 = alloca i8*
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i64
%9 = alloca %struct.katcl_line*
%10 = alloca %struct.katcl_line*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %4
store i8* %1, i8** %5
%14 = load i32, i32* @AF_UNIX
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = call i64 @socketpair(i32 %14, i32 %15, i32 0, i32* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 -1, i32* %3
br label %147
20: ; preds = %2
%21 = call i64 (...) @fork()
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
store i32 -1, i32* %3
br label %147
31: ; preds = %20
%32 = load i64, i64* %8
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%39 = load i32, i32* %38
%40 = load i32, i32* @F_SETFD
%41 = load i32, i32* @FD_CLOEXEC
%42 = call i32 @fcntl(i32 %39, i32 %40, i32 %41)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%44 = load i32, i32* %43
store i32 %44, i32* %3
br label %147
45: ; preds = %31
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
%49 = load i8*, i8** %5
%50 = load i32, i32* @O_RDONLY
%51 = call i32 @open(i8* %49, i32 %50)
store i32 %51, i32* %7
%52 = load i32, i32* %7
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %45
%55 = load i32, i32* @EX_UNAVAILABLE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %45
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%59 = load i32, i32* %58
%60 = call %struct.katcl_line* @create_katcl(i32 %59)
store %struct.katcl_line* %60, %struct.katcl_line** %9
%61 = load i32, i32* %7
%62 = call %struct.katcl_line* @create_katcl(i32 %61)
store %struct.katcl_line* %62, %struct.katcl_line** %10
%63 = load %struct.katcl_line*, %struct.katcl_line** %9
%64 = icmp eq %struct.katcl_line* %63, null
br i1 %64, label %68, label %65
65: ; preds = %57
%66 = load %struct.katcl_line*, %struct.katcl_line** %10
%67 = icmp eq %struct.katcl_line* %66, null
br i1 %67, label %68, label %71
68: ; preds = %65, %57
%69 = load i32, i32* @EX_UNAVAILABLE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %65
store i32 0, i32* %11
br label %72
72: ; preds = %143, %71
%73 = load i32, i32* %11
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %144
75: ; preds = %72
%76 = load %struct.katcl_line*, %struct.katcl_line** %10
%77 = call i32 @read_katcl(%struct.katcl_line* %76)
store i32 %77, i32* %11
%78 = load i32, i32* %11
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %75
%81 = load i32, i32* @EX_UNAVAILABLE
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %75
br label %84
84: ; preds = %142, %83
%85 = load %struct.katcl_line*, %struct.katcl_line** %10
%86 = call i64 @have_katcl(%struct.katcl_line* %85)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %143
88: ; preds = %84
%89 = load %struct.katcl_line*, %struct.katcl_line** %10
%90 = call i64 @arg_request_katcl(%struct.katcl_line* %89)
%91 = icmp ne i64 %90, 0
br i1 %91, label %92, label %142
92: ; preds = %88
%93 = load %struct.katcl_line*, %struct.katcl_line** %10
%94 = load %struct.katcl_line*, %struct.katcl_line** %9
%95 = call i32 @relay_katcl(%struct.katcl_line* %93, %struct.katcl_line* %94)
store i32 %95, i32* %13
%96 = load i32, i32* %13
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %92
%99 = load i32, i32* @EX_UNAVAILABLE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %92
%102 = load %struct.katcl_line*, %struct.katcl_line** %9
%103 = call i32 @write_katcl(%struct.katcl_line* %102)
%104 = icmp ne i32 %103, 0
br i1 %104, label %108, label %105
105: ; preds = %101
%106 = load i32, i32* @EX_UNAVAILABLE
%107 = call i32 @exit(i32 %106)
unreachable
108: ; preds = %101
br label %109
109: ; preds = %108
store i32 1, i32* %12
br label %110
110: ; preds = %140, %109
%111 = load i32, i32* %12
%112 = icmp ne i32 %111, 3
br i1 %112, label %113, label %141
113: ; preds = %110
%114 = load i32, i32* %12
switch i32 %114, label %140 [
i32 1, label %115
i32 2, label %122
]
115: ; preds = %113
%116 = load %struct.katcl_line*, %struct.katcl_line** %9
%117 = call i32 @read_katcl(%struct.katcl_line* %116)
store i32 %117, i32* %13
%118 = load i32, i32* %13
%119 = icmp eq i32 %118, 0
br i1 %119, label %120, label %121
120: ; preds = %115
store i32 2, i32* %12
br label %121
121: ; preds = %120, %115
br label %140
122: ; preds = %113
%123 = load %struct.katcl_line*, %struct.katcl_line** %9
%124 = call i64 @have_katcl(%struct.katcl_line* %123)
%125 = icmp ne i64 %124, 0
br i1 %125, label %126, label %138
126: ; preds = %122
%127 = load %struct.katcl_line*, %struct.katcl_line** %9
%128 = call i32 @arg_reply_katcl(%struct.katcl_line* %127)
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %131
130: ; preds = %126
store i32 3, i32* %12
br label %137
131: ; preds = %126
%132 = load %struct.katcl_line*, %struct.katcl_line** %9
%133 = call i32 @arg_inform_katcl(%struct.katcl_line* %132)
%134 = icmp ne i32 %133, 0
br i1 %134, label %135, label %136
135: ; preds = %131
store i32 2, i32* %12
br label %136
136: ; preds = %135, %131
br label %137
137: ; preds = %136, %130
br label %139
138: ; preds = %122
store i32 1, i32* %12
br label %139
139: ; preds = %138, %137
br label %140
140: ; preds = %113, %139, %121
br label %110
141: ; preds = %110
br label %142
142: ; preds = %141, %88
br label %84
143: ; preds = %84
br label %72
144: ; preds = %72
%145 = load i32, i32* @EX_OK
%146 = call i32 @exit(i32 %145)
unreachable
147: ; preds = %34, %24, %19
%148 = load i32, i32* %3
ret i32 %148
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
%struct.katcl_line = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@O_RDONLY = global i32 0
@EX_UNAVAILABLE = global i32 0
@EX_OK = global i32 0
define i32 @pipe_from_file_katcp(%struct.katcp_dispatch* nocapture readnone %0, i8* nocapture %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i64 @socketpair(i32 %5, i32 %6, i32 0, i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %99, label %10
10: ; preds = %2
%11 = call i64 (...) @fork()
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* %7
%15 = call i32 @close(i32 %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
br label %99
19: ; preds = %10
%20 = icmp eq i64 %11, 0
br i1 %20, label %30, label %21
21: ; preds = %19
%22 = load i32, i32* %7
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%25 = load i32, i32* %24
%26 = load i32, i32* @F_SETFD
%27 = load i32, i32* @FD_CLOEXEC
%28 = call i32 @fcntl(i32 %25, i32 %26, i32 %27)
%29 = load i32, i32* %24
br label %99
30: ; preds = %19
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* @O_RDONLY
%35 = call i32 @open(i8* %1, i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i32, i32* @EX_UNAVAILABLE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %30
%41 = load i32, i32* %7
%42 = call %struct.katcl_line* @create_katcl(i32 %41)
%43 = call %struct.katcl_line* @create_katcl(i32 %35)
%44 = icmp eq %struct.katcl_line* %42, null
%45 = icmp eq %struct.katcl_line* %43, null
%46 = select i1 %44, i1 true, i1 %45
br i1 %46, label %47, label %52
47: ; preds = %40
%48 = load i32, i32* @EX_UNAVAILABLE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %93, %55
%51 = icmp eq i32 %53, 0
br i1 %51, label %52, label %96
52: ; preds = %40, %50
%53 = call i32 @read_katcl(%struct.katcl_line* %43)
%54 = icmp slt i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %52
%56 = call i64 @have_katcl(%struct.katcl_line* %43)
%57 = icmp eq i64 %56, 0
br i1 %57, label %50, label %61
58: ; preds = %52
%59 = load i32, i32* @EX_UNAVAILABLE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %55, %93
%62 = call i64 @arg_request_katcl(%struct.katcl_line* %43)
%63 = icmp eq i64 %62, 0
br i1 %63, label %93, label %64
64: ; preds = %61
%65 = call i32 @relay_katcl(%struct.katcl_line* %43, %struct.katcl_line* %42)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i32, i32* @EX_UNAVAILABLE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %64
%71 = call i32 @write_katcl(%struct.katcl_line* %42)
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %83
73: ; preds = %70
%74 = load i32, i32* @EX_UNAVAILABLE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %83, %76
switch i32 %84, label %76 [
i32 3, label %93
i32 1, label %77
i32 2, label %85
]
77: ; preds = %76
%78 = call i32 @read_katcl(%struct.katcl_line* %42)
%79 = icmp eq i32 %78, 0
%80 = select i1 %79, i32 2, i32 1
br label %81
81: ; preds = %77, %88, %91, %85
%82 = phi i32 [ 1, %85 ], [ 2, %91 ], [ 3, %88 ], [ %80, %77 ]
br label %83
83: ; preds = %70, %81
%84 = phi i32 [ %82, %81 ], [ 1, %70 ]
br label %76
85: ; preds = %76
%86 = call i64 @have_katcl(%struct.katcl_line* %42)
%87 = icmp eq i64 %86, 0
br i1 %87, label %81, label %88
88: ; preds = %85
%89 = call i32 @arg_reply_katcl(%struct.katcl_line* %42)
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %81
91: ; preds = %88
%92 = call i32 @arg_inform_katcl(%struct.katcl_line* %42)
br label %81
93: ; preds = %76, %61
%94 = call i64 @have_katcl(%struct.katcl_line* %43)
%95 = icmp eq i64 %94, 0
br i1 %95, label %50, label %61
96: ; preds = %50
%97 = load i32, i32* @EX_OK
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %2, %21, %13
%100 = phi i32 [ -1, %13 ], [ %29, %21 ], [ -1, %2 ]
ret i32 %100
}