#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 timeval {
  unsigned int tv_sec;
  unsigned int tv_usec;
};
struct katcl_line {
  int dummy;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
#define EAGAIN 129
#define EINTR 128
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
char *arg_string_katcl(struct katcl_line *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error_katcl(struct katcl_line *);
int fileno_katcl(struct katcl_line *);
scalar_t__ flushing_katcl(struct katcl_line *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ have_katcl(struct katcl_line *);
int read_katcl(struct katcl_line *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int write_katcl(struct katcl_line *);
int dispatch_client(struct katcl_line *l, char *msgname, int verbose,
                    unsigned int timeout) {
  fd_set fsr, fsw;
  struct timeval tv;
  int result;
  char *ptr, *match;
  int prefix;
  int fd;
  fd = fileno_katcl(l);
  if (msgname) {
    switch (msgname[0]) {
    case '!':
    case '?':
      prefix = strlen(msgname + 1);
      match = msgname + 1;
      break;
    default:
      prefix = strlen(msgname);
      match = msgname;
      break;
    }
  } else {
    prefix = 0;
    match = NULL;
  }
  for (;;) {
    FD_ZERO(&fsr);
    FD_ZERO(&fsw);
    if (match) {
      FD_SET(fd, &fsr);
    }
    if (flushing_katcl(l)) {
      FD_SET(fd, &fsw);
    }
    tv.tv_sec = timeout / 1000;
    tv.tv_usec = (timeout % 1000) * 1000;
    result = select(fd + 1, &fsr, &fsw, NULL, &tv);
    switch (result) {
    case -1:
      switch (errno) {
      case EAGAIN:
      case EINTR:
        continue;
      default:
        return -1;
      }
      break;
    case 0:
      if (verbose) {
        fprintf(stderr, "dispatch: no io activity within %u ms\n", timeout);
      }
      return -1;
    }
    if (FD_ISSET(fd, &fsw)) {
      result = write_katcl(l);
      if (result < 0) {
        fprintf(stderr, "dispatch: write failed: %s\n",
                strerror(error_katcl(l)));
        return -1;
      }
      if ((result > 0) && (match == NULL)) {
        return 0;
      }
    }
    if (FD_ISSET(fd, &fsr)) {
      result = read_katcl(l);
      if (result) {
        fprintf(stderr, "dispatch: read failed: %s\n",
                (result < 0) ? strerror(error_katcl(l))
                             : "connection terminated");
        return -1;
      }
    }
    while (have_katcl(l) > 0) {
      ptr = arg_string_katcl(l, 0);
      if (ptr) {
        switch (ptr[0]) {
        case '#':
          break;
        case '!':
          if (match) {
            if (strncmp(match, ptr + 1, prefix) ||
                ((ptr[prefix + 1] != '\0') && (ptr[prefix + 1] != ' '))) {
              fprintf(
                  stderr,
                  "dispatch: warning, encountered reply <%s> not match <%s>\n",
                  ptr, match);
            } else {
              ptr = arg_string_katcl(l, 1);
              if (ptr && !strcmp(ptr, "ok")) {
                return 0;
              } else {
                return -1;
              }
            }
          }
          break;
        case '?':
          fprintf(
              stderr,
              "dispatch: warning, encountered an unanswerable request <%s>\n",
              ptr);
          break;
        default:
          fprintf(stderr, "dispatch: read malformed message <%s>\n", ptr);
          break;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<dispatch_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   10d0 <fileno_katcl@plt>
mov    %eax,-0x50(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1290 <dispatch_client+0x90>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x54(%rbp)
sub    $0x21,%eax
je     1256 <dispatch_client+0x56>
jmp    1245 <dispatch_client+0x45>
mov    -0x54(%rbp),%eax
sub    $0x3f,%eax
jne    1277 <dispatch_client+0x77>
jmp    1256 <dispatch_client+0x56>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1070 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    128b <dispatch_client+0x8b>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    129f <dispatch_client+0x9f>
movl   $0x0,-0x4c(%rbp)
movq   $0x0,-0x48(%rbp)
jmp    12a4 <dispatch_client+0xa4>
lea    -0x24(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
lea    -0x28(%rbp),%rdi
call   10b0 <FD_ZERO@plt>
cmpq   $0x0,-0x48(%rbp)
je     12cd <dispatch_client+0xcd>
mov    -0x50(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1120 <FD_SET@plt>
mov    -0x10(%rbp),%rdi
call   1030 <flushing_katcl@plt>
cmp    $0x0,%rax
je     12ec <dispatch_client+0xec>
mov    -0x50(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1120 <FD_SET@plt>
mov    -0x20(%rbp),%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
mov    %ecx,%eax
imul   $0x10624dd3,%rcx,%rcx
shr    $0x26,%rcx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x50(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%r8
call   10c0 <select@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x58(%rbp)
sub    $0xffffffff,%eax
je     1362 <dispatch_client+0x162>
jmp    1352 <dispatch_client+0x152>
mov    -0x58(%rbp),%eax
test   %eax,%eax
je     138d <dispatch_client+0x18d>
jmp    13bd <dispatch_client+0x1bd>
mov    0x2c6f(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     1381 <dispatch_client+0x181>
jmp    137c <dispatch_client+0x17c>
jmp    12a4 <dispatch_client+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    166f <dispatch_client+0x46f>
cmpl   $0x0,-0x1c(%rbp)
je     13b1 <dispatch_client+0x1b1>
mov    0x2c42(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xc56(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    166f <dispatch_client+0x46f>
mov    -0x50(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     144b <dispatch_client+0x24b>
mov    -0x10(%rbp),%rdi
call   1050 <write_katcl@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1425 <dispatch_client+0x225>
mov    0x2bf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <error_katcl@plt>
mov    %eax,%edi
call   1110 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,%rdx
lea    0xc15(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    166f <dispatch_client+0x46f>
cmpl   $0x0,-0x34(%rbp)
jle    1446 <dispatch_client+0x246>
cmpq   $0x0,-0x48(%rbp)
jne    1446 <dispatch_client+0x246>
movl   $0x0,-0x4(%rbp)
jmp    166f <dispatch_client+0x46f>
jmp    144b <dispatch_client+0x24b>
mov    -0x50(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1060 <FD_ISSET@plt>
cmp    $0x0,%rax
je     14dc <dispatch_client+0x2dc>
mov    -0x10(%rbp),%rdi
call   1080 <read_katcl@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     14d7 <dispatch_client+0x2d7>
mov    0x2b62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    14a6 <dispatch_client+0x2a6>
mov    -0x10(%rbp),%rdi
call   10f0 <error_katcl@plt>
mov    %eax,%edi
call   1110 <strerror@plt>
mov    %rax,-0x68(%rbp)
jmp    14b6 <dispatch_client+0x2b6>
lea    0xbb1(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    14b6 <dispatch_client+0x2b6>
mov    -0x60(%rbp),%edi
mov    -0x68(%rbp),%rdx
lea    0xb7f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    166f <dispatch_client+0x46f>
jmp    14dc <dispatch_client+0x2dc>
jmp    14e1 <dispatch_client+0x2e1>
mov    -0x10(%rbp),%rdi
call   1100 <have_katcl@plt>
cmp    $0x0,%rax
jle    166a <dispatch_client+0x46a>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   10e0 <arg_string_katcl@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1665 <dispatch_client+0x465>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x6c(%rbp)
sub    $0x21,%eax
je     154d <dispatch_client+0x34d>
jmp    1526 <dispatch_client+0x326>
mov    -0x6c(%rbp),%eax
sub    $0x23,%eax
je     1548 <dispatch_client+0x348>
jmp    1537 <dispatch_client+0x337>
mov    -0x6c(%rbp),%eax
sub    $0x3f,%eax
je     1625 <dispatch_client+0x425>
jmp    1645 <dispatch_client+0x445>
jmp    1660 <dispatch_client+0x460>
cmpq   $0x0,-0x48(%rbp)
je     1620 <dispatch_client+0x420>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
add    $0x1,%rsi
mov    -0x4c(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    15a9 <dispatch_client+0x3a9>
mov    -0x40(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     15cd <dispatch_client+0x3cd>
mov    -0x40(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     15cd <dispatch_client+0x3cd>
mov    0x2a30(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    0xab3(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    161b <dispatch_client+0x41b>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   10e0 <arg_string_katcl@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     160f <dispatch_client+0x40f>
mov    -0x40(%rbp),%rdi
lea    0xab9(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    160f <dispatch_client+0x40f>
movl   $0x0,-0x4(%rbp)
jmp    166f <dispatch_client+0x46f>
movl   $0xffffffff,-0x4(%rbp)
jmp    166f <dispatch_client+0x46f>
jmp    1620 <dispatch_client+0x420>
jmp    1660 <dispatch_client+0x460>
mov    0x29b4(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xa78(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1660 <dispatch_client+0x460>
mov    0x2994(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xa95(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1665 <dispatch_client+0x465>
jmp    14e1 <dispatch_client+0x2e1>
jmp    12a4 <dispatch_client+0xa4>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dispatch_client>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%r14d
mov    %edx,0x8(%rsp)
mov    %rsi,%r13
mov    %rdi,%rbx
call   10d0 <fileno_katcl@plt>
mov    %eax,%r12d
test   %r13,%r13
je     1245 <dispatch_client+0x45>
movsbl 0x0(%r13),%eax
cmp    $0x3f,%eax
je     1237 <dispatch_client+0x37>
cmp    $0x21,%eax
jne    123b <dispatch_client+0x3b>
add    $0x1,%r13
mov    %r13,%rdi
call   1070 <strlen@plt>
jmp    124a <dispatch_client+0x4a>
xor    %r13d,%r13d
xor    %eax,%eax
mov    %r14d,%ecx
imul   $0x10624dd3,%rcx,%rcx
shr    $0x26,%rcx
mov    %rcx,0x28(%rsp)
imul   $0x3e8,%ecx,%edx
mov    %r14d,0x4(%rsp)
sub    %edx,%r14d
imul   $0x3e8,%r14d,%ecx
mov    %ecx,0x14(%rsp)
mov    %r12d,%ecx
add    $0x1,%ecx
mov    %ecx,0x10(%rsp)
mov    %eax,0xc(%rsp)
cltq
mov    %rax,0x20(%rsp)
mov    0x2d4e(%rip),%r15
jmp    12b7 <dispatch_client+0xb7>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
and    $0xfffffffe,%eax
cmp    $0x80,%eax
jne    14b9 <dispatch_client+0x2b9>
lea    0x34(%rsp),%r14
mov    %r14,%rdi
call   10b0 <FD_ZERO@plt>
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   10b0 <FD_ZERO@plt>
test   %r13,%r13
je     12e1 <dispatch_client+0xe1>
mov    %r12d,%edi
mov    %r14,%rsi
call   1120 <FD_SET@plt>
mov    %rbx,%rdi
call   1030 <flushing_katcl@plt>
test   %rax,%rax
je     12f9 <dispatch_client+0xf9>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1120 <FD_SET@plt>
mov    0x28(%rsp),%rax
mov    %eax,0x18(%rsp)
mov    0x14(%rsp),%eax
mov    %eax,0x1c(%rsp)
mov    0x10(%rsp),%edi
mov    %r14,%rsi
mov    %rbp,%rdx
xor    %ecx,%ecx
lea    0x18(%rsp),%r8
call   10c0 <select@plt>
cmp    $0xffffffff,%eax
je     12a0 <dispatch_client+0xa0>
test   %eax,%eax
je     1446 <dispatch_client+0x246>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     135e <dispatch_client+0x15e>
mov    %rbx,%rdi
call   1050 <write_katcl@plt>
test   %eax,%eax
js     1469 <dispatch_client+0x269>
test   %r13,%r13
jne    135e <dispatch_client+0x15e>
test   %eax,%eax
jne    1442 <dispatch_client+0x242>
mov    %r12d,%edi
mov    %r14,%rsi
call   1060 <FD_ISSET@plt>
test   %rax,%rax
je     1393 <dispatch_client+0x193>
mov    %rbx,%rdi
call   1080 <read_katcl@plt>
test   %eax,%eax
je     1393 <dispatch_client+0x193>
jmp    1489 <dispatch_client+0x289>
mov    (%r15),%edi
lea    0xd65(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1100 <have_katcl@plt>
test   %rax,%rax
jle    12b7 <dispatch_client+0xb7>
mov    %rbx,%rdi
xor    %esi,%esi
call   10e0 <arg_string_katcl@plt>
test   %rax,%rax
je     1393 <dispatch_client+0x193>
mov    %rax,%r14
movsbl (%rax),%eax
cmp    $0x3f,%eax
je     140a <dispatch_client+0x20a>
cmp    $0x23,%eax
je     1393 <dispatch_client+0x193>
cmp    $0x21,%eax
jne    137f <dispatch_client+0x17f>
test   %r13,%r13
je     1393 <dispatch_client+0x193>
mov    %r14,%rsi
add    $0x1,%rsi
mov    %r13,%rdi
mov    0xc(%rsp),%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    13f1 <dispatch_client+0x1f1>
mov    0x20(%rsp),%rax
testb  $0xdf,0x1(%r14,%rax,1)
je     1419 <dispatch_client+0x219>
mov    (%r15),%edi
lea    0xc79(%rip),%rsi
mov    %r14,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1393 <dispatch_client+0x193>
mov    (%r15),%edi
lea    0xc9d(%rip),%rsi
jmp    1389 <dispatch_client+0x189>
mov    %rbx,%rdi
mov    $0x1,%esi
call   10e0 <arg_string_katcl@plt>
test   %rax,%rax
je     14b9 <dispatch_client+0x2b9>
lea    0xc78(%rip),%rsi
mov    %rax,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
jne    14b9 <dispatch_client+0x2b9>
xor    %ebx,%ebx
jmp    14be <dispatch_client+0x2be>
mov    $0xffffffff,%ebx
cmpl   $0x0,0x8(%rsp)
je     14be <dispatch_client+0x2be>
mov    (%r15),%edi
lea    0xba4(%rip),%rsi
mov    0x4(%rsp),%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    14be <dispatch_client+0x2be>
mov    (%r15),%ebp
mov    %rbx,%rdi
call   10f0 <error_katcl@plt>
mov    %eax,%edi
call   1110 <strerror@plt>
lea    0xba5(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
jmp    14b2 <dispatch_client+0x2b2>
mov    (%r15),%ebp
js     1497 <dispatch_client+0x297>
lea    0xbc9(%rip),%rdx
jmp    14a9 <dispatch_client+0x2a9>
mov    %rbx,%rdi
call   10f0 <error_katcl@plt>
mov    %eax,%edi
call   1110 <strerror@plt>
mov    %rax,%rdx
lea    0xb93(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcl_line = type { i32 }
%struct.timeval = type { i32, i32 }
@errno = global i32 0
@stderr = global i32 0
@.str = [39 x i8] c"dispatch: no io activity within %u ms\0A\00"
@.str.1 = [28 x i8] c"dispatch: write failed: %s\0A\00"
@.str.2 = [27 x i8] c"dispatch: read failed: %s\0A\00"
@.str.3 = [22 x i8] c"connection terminated\00"
@.str.4 = [58 x i8] c"dispatch: warning, encountered reply <%s> not match <%s>\0A\00"
@.str.5 = [3 x i8] c"ok\00"
@.str.6 = [61 x i8] c"dispatch: warning, encountered an unanswerable request <%s>\0A\00"
@.str.7 = [39 x i8] c"dispatch: read malformed message <%s>\0A\00"
define i32 @dispatch_client(%struct.katcl_line* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.katcl_line*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
store %struct.katcl_line* %0, %struct.katcl_line** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%18 = load %struct.katcl_line*, %struct.katcl_line** %6
%19 = call i32 @fileno_katcl(%struct.katcl_line* %18)
store i32 %19, i32* %17
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %38
22: ; preds = %4
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
switch i32 %26, label %33 [
i32 33, label %27
i32 63, label %27
]
27: ; preds = %22, %22
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %16
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** %15
br label %37
33: ; preds = %22
%34 = load i8*, i8** %7
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %16
%36 = load i8*, i8** %7
store i8* %36, i8** %15
br label %37
37: ; preds = %33, %27
br label %39
38: ; preds = %4
store i32 0, i32* %16
store i8* null, i8** %15
br label %39
39: ; preds = %38, %37
br label %40
40: ; preds = %196, %69, %39
%41 = call i32 @FD_ZERO(i32* %10)
%42 = call i32 @FD_ZERO(i32* %11)
%43 = load i8*, i8** %15
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* %17
%47 = call i32 @FD_SET(i32 %46, i32* %10)
br label %48
48: ; preds = %45, %40
%49 = load %struct.katcl_line*, %struct.katcl_line** %6
%50 = call i64 @flushing_katcl(%struct.katcl_line* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* %17
%54 = call i32 @FD_SET(i32 %53, i32* %11)
br label %55
55: ; preds = %52, %48
%56 = load i32, i32* %9
%57 = udiv i32 %56, 1000
%58 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i32 %57, i32* %58
%59 = load i32, i32* %9
%60 = urem i32 %59, 1000
%61 = mul i32 %60, 1000
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i32 %61, i32* %62
%63 = load i32, i32* %17
%64 = add nsw i32 %63, 1
%65 = call i32 @select(i32 %64, i32* %10, i32* %11, i32* null, %struct.timeval* %12)
store i32 %65, i32* %13
%66 = load i32, i32* %13
switch i32 %66, label %79 [
i32 -1, label %67
i32 0, label %71
]
67: ; preds = %55
%68 = load i32, i32* @errno
switch i32 %68, label %70 [
i32 129, label %69
i32 128, label %69
]
69: ; preds = %67, %67
br label %40
70: ; preds = %67
store i32 -1, i32* %5
br label %197
71: ; preds = %55
%72 = load i32, i32* %8
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = load i32, i32* @stderr
%76 = load i32, i32* %9
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %74, %71
store i32 -1, i32* %5
br label %197
79: ; preds = %55
%80 = load i32, i32* %17
%81 = call i64 @FD_ISSET(i32 %80, i32* %11)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %102
83: ; preds = %79
%84 = load %struct.katcl_line*, %struct.katcl_line** %6
%85 = call i32 @write_katcl(%struct.katcl_line* %84)
store i32 %85, i32* %13
%86 = load i32, i32* %13
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %94
88: ; preds = %83
%89 = load i32, i32* @stderr
%90 = load %struct.katcl_line*, %struct.katcl_line** %6
%91 = call i32 @error_katcl(%struct.katcl_line* %90)
%92 = call i8* @strerror(i32 %91)
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %92)
store i32 -1, i32* %5
br label %197
94: ; preds = %83
%95 = load i32, i32* %13
%96 = icmp sgt i32 %95, 0
br i1 %96, label %97, label %101
97: ; preds = %94
%98 = load i8*, i8** %15
%99 = icmp eq i8* %98, null
br i1 %99, label %100, label %101
100: ; preds = %97
store i32 0, i32* %5
br label %197
101: ; preds = %97, %94
br label %102
102: ; preds = %101, %79
%103 = load i32, i32* %17
%104 = call i64 @FD_ISSET(i32 %103, i32* %10)
%105 = icmp ne i64 %104, 0
br i1 %105, label %106, label %124
106: ; preds = %102
%107 = load %struct.katcl_line*, %struct.katcl_line** %6
%108 = call i32 @read_katcl(%struct.katcl_line* %107)
store i32 %108, i32* %13
%109 = load i32, i32* %13
%110 = icmp ne i32 %109, 0
br i1 %110, label %111, label %123
111: ; preds = %106
%112 = load i32, i32* @stderr
%113 = load i32, i32* %13
%114 = icmp slt i32 %113, 0
br i1 %114, label %115, label %119
115: ; preds = %111
%116 = load %struct.katcl_line*, %struct.katcl_line** %6
%117 = call i32 @error_katcl(%struct.katcl_line* %116)
%118 = call i8* @strerror(i32 %117)
br label %120
119: ; preds = %111
br label %120
120: ; preds = %119, %115
%121 = phi i8* [ %118, %115 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), %119 ]
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %121)
store i32 -1, i32* %5
br label %197
123: ; preds = %106
br label %124
124: ; preds = %123, %102
br label %125
125: ; preds = %195, %124
%126 = load %struct.katcl_line*, %struct.katcl_line** %6
%127 = call i64 @have_katcl(%struct.katcl_line* %126)
%128 = icmp sgt i64 %127, 0
br i1 %128, label %129, label %196
129: ; preds = %125
%130 = load %struct.katcl_line*, %struct.katcl_line** %6
%131 = call i8* @arg_string_katcl(%struct.katcl_line* %130, i32 0)
store i8* %131, i8** %14
%132 = load i8*, i8** %14
%133 = icmp ne i8* %132, null
br i1 %133, label %134, label %195
134: ; preds = %129
%135 = load i8*, i8** %14
%136 = getelementptr inbounds i8, i8* %135, i64 0
%137 = load i8, i8* %136
%138 = sext i8 %137 to i32
switch i32 %138, label %190 [
i32 35, label %139
i32 33, label %140
i32 63, label %186
]
139: ; preds = %134
br label %194
140: ; preds = %134
%141 = load i8*, i8** %15
%142 = icmp ne i8* %141, null
br i1 %142, label %143, label %185
143: ; preds = %140
%144 = load i8*, i8** %15
%145 = load i8*, i8** %14
%146 = getelementptr inbounds i8, i8* %145, i64 1
%147 = load i32, i32* %16
%148 = call i32 @strncmp(i8* %144, i8* %146, i32 %147)
%149 = icmp ne i32 %148, 0
br i1 %149, label %168, label %150
150: ; preds = %143
%151 = load i8*, i8** %14
%152 = load i32, i32* %16
%153 = add nsw i32 %152, 1
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds i8, i8* %151, i64 %154
%156 = load i8, i8* %155
%157 = sext i8 %156 to i32
%158 = icmp ne i32 %157, 0
br i1 %158, label %159, label %173
159: ; preds = %150
%160 = load i8*, i8** %14
%161 = load i32, i32* %16
%162 = add nsw i32 %161, 1
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds i8, i8* %160, i64 %163
%165 = load i8, i8* %164
%166 = sext i8 %165 to i32
%167 = icmp ne i32 %166, 32
br i1 %167, label %168, label %173
168: ; preds = %159, %143
%169 = load i32, i32* @stderr
%170 = load i8*, i8** %14
%171 = load i8*, i8** %15
%172 = call i32 (i32, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i8* %170, i8* %171)
br label %184
173: ; preds = %159, %150
%174 = load %struct.katcl_line*, %struct.katcl_line** %6
%175 = call i8* @arg_string_katcl(%struct.katcl_line* %174, i32 1)
store i8* %175, i8** %14
%176 = load i8*, i8** %14
%177 = icmp ne i8* %176, null
br i1 %177, label %178, label %183
178: ; preds = %173
%179 = load i8*, i8** %14
%180 = call i32 @strcmp(i8* %179, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%181 = icmp ne i32 %180, 0
br i1 %181, label %183, label %182
182: ; preds = %178
store i32 0, i32* %5
br label %197
183: ; preds = %178, %173
store i32 -1, i32* %5
br label %197
184: ; preds = %168
br label %185
185: ; preds = %184, %140
br label %194
186: ; preds = %134
%187 = load i32, i32* @stderr
%188 = load i8*, i8** %14
%189 = call i32 (i32, i8*, ...) @fprintf(i32 %187, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.6, i64 0, i64 0), i8* %188)
br label %194
190: ; preds = %134
%191 = load i32, i32* @stderr
%192 = load i8*, i8** %14
%193 = call i32 (i32, i8*, ...) @fprintf(i32 %191, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %192)
br label %194
194: ; preds = %190, %186, %185, %139
br label %195
195: ; preds = %194, %129
br label %125
196: ; preds = %125
br label %40
197: ; preds = %183, %182, %120, %100, %88, %78, %70
%198 = load i32, i32* %5
ret i32 %198
}

LLVM IR (-O2):
%struct.katcl_line = type { i32 }
%struct.timeval = type { i32, i32 }
@errno = global i32 0
@stderr = global i32 0
@.str = [39 x i8] c"dispatch: no io activity within %u ms\0A\00"
@.str.1 = [28 x i8] c"dispatch: write failed: %s\0A\00"
@.str.2 = [27 x i8] c"dispatch: read failed: %s\0A\00"
@.str.3 = [22 x i8] c"connection terminated\00"
@.str.4 = [58 x i8] c"dispatch: warning, encountered reply <%s> not match <%s>\0A\00"
@.str.5 = [3 x i8] c"ok\00"
@.str.6 = [61 x i8] c"dispatch: warning, encountered an unanswerable request <%s>\0A\00"
@.str.7 = [39 x i8] c"dispatch: read malformed message <%s>\0A\00"
define i32 @dispatch_client(%struct.katcl_line* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = bitcast %struct.timeval* %7 to i8*
%11 = tail call i32 @fileno_katcl(%struct.katcl_line* %0)
%12 = icmp eq i8* %1, null
br i1 %12, label %21, label %13
13: ; preds = %4
%14 = load i8, i8* %1
%15 = sext i8 %14 to i32
switch i32 %15, label %18 [
i32 33, label %16
i32 63, label %16
]
16: ; preds = %13, %13
%17 = getelementptr inbounds i8, i8* %1, i64 1
br label %18
18: ; preds = %13, %16
%19 = phi i8* [ %17, %16 ], [ %1, %13 ]
%20 = tail call i32 @strlen(i8* %19)
br label %21
21: ; preds = %18, %4
%22 = phi i8* [ null, %4 ], [ %19, %18 ]
%23 = phi i32 [ 0, %4 ], [ %20, %18 ]
%24 = icmp eq i8* %22, null
%25 = udiv i32 %3, 1000
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%27 = urem i32 %3, 1000
%28 = mul nuw nsw i32 %27, 1000
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%30 = add nsw i32 %11, 1
%31 = add nsw i32 %23, 1
%32 = sext i32 %31 to i64
br label %33
33: ; preds = %86, %21
%34 = call i32 @FD_ZERO(i32* %5)
%35 = call i32 @FD_ZERO(i32* %6)
br i1 %24, label %38, label %36
36: ; preds = %33
%37 = call i32 @FD_SET(i32 %11, i32* %5)
br label %38
38: ; preds = %36, %33
%39 = call i64 @flushing_katcl(%struct.katcl_line* %0)
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = call i32 @FD_SET(i32 %11, i32* %6)
br label %43
43: ; preds = %41, %38
store i32 %25, i32* %26
store i32 %28, i32* %29
%44 = call i32 @select(i32 %30, i32* %5, i32* %6, i32* null, %struct.timeval* %7)
switch i32 %44, label %54 [
i32 -1, label %45
i32 0, label %49
]
45: ; preds = %43
%46 = load i32, i32* @errno
%47 = and i32 %46, -2
%48 = icmp eq i32 %47, 128
br i1 %48, label %86, label %120
49: ; preds = %43
%50 = icmp eq i32 %2, 0
br i1 %50, label %120, label %51
51: ; preds = %49
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %120
54: ; preds = %43
%55 = call i64 @FD_ISSET(i32 %11, i32* %6)
%56 = icmp eq i64 %55, 0
br i1 %56, label %68, label %57
57: ; preds = %54
%58 = call i32 @write_katcl(%struct.katcl_line* %0)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 @error_katcl(%struct.katcl_line* %0)
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %63)
br label %120
65: ; preds = %57
%66 = icmp ne i32 %58, 0
%67 = and i1 %24, %66
br i1 %67, label %120, label %68
68: ; preds = %65, %54
%69 = call i64 @FD_ISSET(i32 %11, i32* %5)
%70 = icmp eq i64 %69, 0
br i1 %70, label %83, label %71
71: ; preds = %68
%72 = call i32 @read_katcl(%struct.katcl_line* %0)
%73 = icmp eq i32 %72, 0
br i1 %73, label %83, label %74
74: ; preds = %71
%75 = load i32, i32* @stderr
%76 = icmp slt i32 %72, 0
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = call i32 @error_katcl(%struct.katcl_line* %0)
%79 = call i8* @strerror(i32 %78)
br label %80
80: ; preds = %74, %77
%81 = phi i8* [ %79, %77 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), %74 ]
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %81)
br label %120
83: ; preds = %71, %68
%84 = call i64 @have_katcl(%struct.katcl_line* %0)
%85 = icmp sgt i64 %84, 0
br i1 %85, label %87, label %86
86: ; preds = %117, %83, %45
br label %33
87: ; preds = %83, %117
%88 = call i8* @arg_string_katcl(%struct.katcl_line* %0, i32 0)
%89 = icmp eq i8* %88, null
br i1 %89, label %117, label %90
90: ; preds = %87
%91 = load i8, i8* %88
%92 = sext i8 %91 to i32
switch i32 %92, label %114 [
i32 35, label %117
i32 33, label %93
i32 63, label %111
]
93: ; preds = %90
br i1 %24, label %117, label %94
94: ; preds = %93
%95 = getelementptr inbounds i8, i8* %88, i64 1
%96 = call i32 @strncmp(i8* %22, i8* %95, i32 %23)
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %94
%99 = getelementptr inbounds i8, i8* %88, i64 %32
%100 = load i8, i8* %99
switch i8 %100, label %101 [
i8 0, label %104
i8 32, label %104
]
101: ; preds = %98, %94
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i8* %88, i8* %22)
br label %117
104: ; preds = %98, %98
%105 = call i8* @arg_string_katcl(%struct.katcl_line* %0, i32 1)
%106 = icmp eq i8* %105, null
br i1 %106, label %110, label %107
107: ; preds = %104
%108 = call i32 @strcmp(i8* %105, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%109 = icmp eq i32 %108, 0
br i1 %109, label %120, label %110
110: ; preds = %107, %104
br label %120
111: ; preds = %90
%112 = load i32, i32* @stderr
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.6, i64 0, i64 0), i8* %88)
br label %117
114: ; preds = %90
%115 = load i32, i32* @stderr
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %88)
br label %117
117: ; preds = %90, %111, %114, %101, %93, %87
%118 = call i64 @have_katcl(%struct.katcl_line* %0)
%119 = icmp sgt i64 %118, 0
br i1 %119, label %87, label %86
120: ; preds = %65, %45, %107, %49, %51, %110, %80, %60
%121 = phi i32 [ -1, %60 ], [ -1, %80 ], [ -1, %110 ], [ -1, %51 ], [ -1, %49 ], [ 0, %107 ], [ 0, %65 ], [ -1, %45 ]
ret i32 %121
}