#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 */
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SETSIZE;
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int write(int, char *, int);
int dispatches(int sockclientc, int *sockclient, int socksource, int r,
               char *buffer) {
  static fd_set writefdset;
  static int pending[64];
  static char buffers[64][1024];
  static int i, w, setsize;
  for (i = 0; i < sockclientc; i++) {
    if (i != socksource) {
      memcpy(buffers[i], buffer, r);
      pending[i] = r;
    } else {
      pending[i] = 0;
    }
  }
  while (1) {
    setsize = 0;
    FD_ZERO(&writefdset);
    for (i = 0; i < sockclientc; i++) {
      if (pending[i] > 0) {
        setsize++;
        FD_SET(sockclient[i], &writefdset);
      }
    }
    if (!setsize) {
      return 0;
    }
    if (select(FD_SETSIZE, NULL, &writefdset, NULL, NULL) < 0) {
      if (errno != EINTR) {
        perror("select");
        return -1;
      } else {
        continue;
      }
    }
    for (i = 0; i < sockclientc; i++) {
      if (FD_ISSET(sockclient[i], &writefdset)) {
        if ((w = write(sockclient[i], buffers[i], pending[i])) < 0) {
          perror("write");
          close(sockclient[i]);
          if (i != --sockclientc) {
            sockclient[i] = sockclient[sockclientc];
            memmove(buffers[i], buffers[sockclientc], pending[sockclientc]);
            pending[i] = pending[sockclientc];
          }
          fprintf(stdout, "%i connections [-1]\n", sockclientc);
          fflush(stdout);
        } else {
          memmove(buffers[i], &(buffers[i][w]), pending[i] - w);
          pending[i] -= w;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<dispatches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,0x12fcd(%rip)
mov    0x12fc7(%rip),%eax
cmp    -0x8(%rbp),%eax
jge    1259 <dispatches+0xa9>
mov    0x12fb8(%rip),%eax
cmp    -0x14(%rbp),%eax
je     122b <dispatches+0x7b>
movslq 0x12fa8(%rip),%rax
lea    0x2fa1(%rip),%rdi
shl    $0xa,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%edx
movslq 0x12f84(%rip),%rcx
lea    0x2e7d(%rip),%rax
mov    %edx,(%rax,%rcx,4)
jmp    1240 <dispatches+0x90>
movslq 0x12f6e(%rip),%rcx
lea    0x2e67(%rip),%rax
movl   $0x0,(%rax,%rcx,4)
jmp    1245 <dispatches+0x95>
mov    0x12f55(%rip),%eax
add    $0x1,%eax
mov    %eax,0x12f4c(%rip)
jmp    11d3 <dispatches+0x23>
jmp    125e <dispatches+0xae>
movl   $0x0,0x12f40(%rip)
lea    0x2e21(%rip),%rdi
call   1080 <FD_ZERO@plt>
movl   $0x0,0x12f22(%rip)
mov    0x12f1c(%rip),%eax
cmp    -0x8(%rbp),%eax
jge    12e7 <dispatches+0x137>
movslq 0x12f0c(%rip),%rcx
lea    0x2e05(%rip),%rax
cmpl   $0x0,(%rax,%rcx,4)
jle    12ce <dispatches+0x11e>
mov    0x12efd(%rip),%eax
add    $0x1,%eax
mov    %eax,0x12ef4(%rip)
mov    -0x10(%rbp),%rax
movslq 0x12ee1(%rip),%rcx
mov    (%rax,%rcx,4),%edi
lea    0x2dc7(%rip),%rsi
call   10d0 <FD_SET@plt>
jmp    12d3 <dispatches+0x123>
mov    0x12ec7(%rip),%eax
add    $0x1,%eax
mov    %eax,0x12ebe(%rip)
jmp    127e <dispatches+0xce>
cmpl   $0x0,0x12eba(%rip)
jne    1300 <dispatches+0x150>
movl   $0x0,-0x4(%rbp)
jmp    154f <dispatches+0x39f>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%r8d
lea    0x2d7b(%rip),%rdx
mov    %r8,%rsi
mov    %r8,%rcx
call   1090 <select@plt>
cmp    $0x0,%rax
jge    1361 <dispatches+0x1b1>
mov    0x2ca7(%rip),%rax
mov    (%rax),%rax
mov    0x2c95(%rip),%rcx
cmp    (%rcx),%rax
je     135c <dispatches+0x1ac>
lea    0xcb5(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    154f <dispatches+0x39f>
jmp    125e <dispatches+0xae>
movl   $0x0,0x12e35(%rip)
mov    0x12e2f(%rip),%eax
cmp    -0x8(%rbp),%eax
jge    154a <dispatches+0x39a>
mov    -0x10(%rbp),%rax
movslq 0x12e1b(%rip),%rcx
mov    (%rax,%rcx,4),%edi
lea    0x2d01(%rip),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1531 <dispatches+0x381>
mov    -0x10(%rbp),%rax
movslq 0x12df7(%rip),%rcx
mov    (%rax,%rcx,4),%edi
movslq 0x12ded(%rip),%rax
lea    0x2de6(%rip),%rsi
shl    $0xa,%rax
add    %rax,%rsi
movslq 0x12dd8(%rip),%rcx
lea    0x2cd1(%rip),%rax
mov    (%rax,%rcx,4),%edx
call   1030 <write@plt>
mov    %eax,0x12dc7(%rip)
cmp    $0x0,%eax
jge    14b9 <dispatches+0x309>
lea    0xc1a(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x10(%rbp),%rax
movslq 0x12da3(%rip),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <close@plt>
mov    0x12d95(%rip),%eax
mov    -0x8(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    %ecx,%eax
je     148e <dispatches+0x2de>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq 0x12d6e(%rip),%rcx
mov    %edx,(%rax,%rcx,4)
movslq 0x12d64(%rip),%rax
lea    0x2d5d(%rip),%rdi
shl    $0xa,%rax
add    %rax,%rdi
movslq -0x8(%rbp),%rax
lea    0x2d4b(%rip),%rsi
shl    $0xa,%rax
add    %rax,%rsi
movslq -0x8(%rbp),%rcx
lea    0x2c39(%rip),%rax
mov    (%rax,%rcx,4),%edx
call   10b0 <memmove@plt>
movslq -0x8(%rbp),%rcx
lea    0x2c26(%rip),%rax
mov    (%rax,%rcx,4),%edx
movslq 0x12d1c(%rip),%rcx
lea    0x2c15(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xb6c(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2b1b(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
jmp    152c <dispatches+0x37c>
movslq 0x12ce0(%rip),%rax
lea    0x2cd9(%rip),%rdi
shl    $0xa,%rax
add    %rax,%rdi
movslq 0x12ccb(%rip),%rax
lea    0x2cc4(%rip),%rsi
shl    $0xa,%rax
add    %rax,%rsi
movslq 0x12cba(%rip),%rax
add    %rax,%rsi
movslq 0x12cac(%rip),%rcx
lea    0x2ba5(%rip),%rax
mov    (%rax,%rcx,4),%edx
sub    0x12ca0(%rip),%edx
call   10b0 <memmove@plt>
mov    0x12c95(%rip),%eax
movslq 0x12c8a(%rip),%rcx
lea    0x2b83(%rip),%rdx
mov    (%rdx,%rcx,4),%edx
sub    %eax,%edx
lea    0x2b77(%rip),%rax
mov    %edx,(%rax,%rcx,4)
jmp    1531 <dispatches+0x381>
jmp    1536 <dispatches+0x386>
mov    0x12c64(%rip),%eax
add    $0x1,%eax
mov    %eax,0x12c5b(%rip)
jmp    136b <dispatches+0x1bb>
jmp    125e <dispatches+0xae>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dispatches>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,(%rsp)
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0x12fd2(%rip)
test   %edi,%edi
jle    1237 <dispatches+0x87>
mov    %ecx,%r15d
mov    %edx,%r12d
movslq %edx,%r13
xor    %eax,%eax
lea    0x2ebc(%rip),%r14
jmp    1208 <dispatches+0x58>
cs nopw 0x0(%rax,%rax,1)
movl   $0x0,(%r14,%r13,4)
mov    %r12d,%eax
add    $0x1,%eax
mov    %eax,0x12f9c(%rip)
cmp    %ebp,%eax
jge    1237 <dispatches+0x87>
cmp    %r12d,%eax
je     11f0 <dispatches+0x40>
movslq %eax,%rdi
shl    $0xa,%rdi
lea    0x2f85(%rip),%rax
add    %rax,%rdi
mov    (%rsp),%rsi
mov    %r15d,%edx
call   1070 <memcpy@plt>
movslq 0x12f6f(%rip),%rax
mov    %r15d,(%r14,%rax,4)
jmp    11fb <dispatches+0x4b>
lea    0x2e52(%rip),%r14
lea    0x2e5b(%rip),%r13
mov    0x2d94(%rip),%r15
mov    0x2d7d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x0,0x12f3e(%rip)
mov    %r14,%rdi
call   1080 <FD_ZERO@plt>
movl   $0x0,0x12f24(%rip)
test   %ebp,%ebp
jle    12d0 <dispatches+0x120>
xor    %eax,%eax
jmp    129d <dispatches+0xed>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%eax
mov    %eax,0x12f07(%rip)
cmp    %ebp,%eax
jge    12d0 <dispatches+0x120>
movslq %eax,%rcx
cmpl   $0x0,0x0(%r13,%rcx,4)
jle    1290 <dispatches+0xe0>
addl   $0x1,0x12ef9(%rip)
mov    (%rbx,%rcx,4),%edi
mov    %r14,%rsi
call   10d0 <FD_SET@plt>
mov    0x12ee0(%rip),%eax
jmp    1290 <dispatches+0xe0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpl   $0x0,0x12ed1(%rip)
je     1458 <dispatches+0x2a8>
mov    (%r15),%edi
xor    %esi,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <select@plt>
test   %rax,%rax
jns    130d <dispatches+0x15d>
mov    0x2cdd(%rip),%rax
mov    (%rax),%rax
cmp    (%r12),%rax
je     1260 <dispatches+0xb0>
jmp    1469 <dispatches+0x2b9>
movl   $0x0,0x12e89(%rip)
test   %ebp,%ebp
jle    1260 <dispatches+0xb0>
xor    %eax,%eax
jmp    137f <dispatches+0x1cf>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq 0x12e69(%rip),%rdi
mov    0x0(%r13,%rdi,4),%edx
shl    $0xa,%rdi
lea    0x2e59(%rip),%rcx
add    %rcx,%rdi
mov    %eax,%esi
add    %rdi,%rsi
sub    %eax,%edx
call   10b0 <memmove@plt>
mov    0x12e48(%rip),%eax
movslq 0x12e3d(%rip),%rcx
sub    %eax,0x0(%r13,%rcx,4)
mov    0x12e32(%rip),%eax
add    $0x1,%eax
mov    %eax,0x12e29(%rip)
cmp    %ebp,%eax
jge    1260 <dispatches+0xb0>
cltq
mov    (%rbx,%rax,4),%edi
mov    %r14,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     1368 <dispatches+0x1b8>
movslq 0x12e08(%rip),%rsi
mov    (%rbx,%rsi,4),%edi
mov    0x0(%r13,%rsi,4),%edx
shl    $0xa,%rsi
lea    0x2df5(%rip),%rax
add    %rax,%rsi
call   1030 <write@plt>
mov    %eax,0x12deb(%rip)
test   %eax,%eax
jns    1330 <dispatches+0x180>
lea    0xc3f(%rip),%rdi
call   10c0 <perror@plt>
movslq 0x12dcc(%rip),%rax
mov    (%rbx,%rax,4),%edi
call   1050 <close@plt>
movslq 0x12dbd(%rip),%rdi
add    $0xffffffff,%ebp
cmp    %ebp,%edi
je     142e <dispatches+0x27e>
movslq %ebp,%rcx
mov    %rcx,(%rsp)
mov    (%rbx,%rcx,4),%eax
mov    %eax,(%rbx,%rdi,4)
shl    $0xa,%rdi
lea    0x2d9e(%rip),%rax
add    %rax,%rdi
mov    %rcx,%rsi
shl    $0xa,%rsi
add    %rax,%rsi
mov    0x0(%r13,%rcx,4),%edx
call   10b0 <memmove@plt>
mov    (%rsp),%rax
mov    0x0(%r13,%rax,4),%eax
movslq 0x12d77(%rip),%rcx
mov    %eax,0x0(%r13,%rcx,4)
mov    0x2b93(%rip),%rax
mov    (%rax),%edi
lea    0xbcf(%rip),%rsi
mov    %ebp,%edx
call   1060 <fprintf@plt>
mov    0x2b7c(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
jmp    1368 <dispatches+0x1b8>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb90(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%eax
jmp    145a <dispatches+0x2aa>

LLVM IR (-O0):
@dispatches.writefdset = internal global i32 0
@dispatches.pending = internal global [64 x i32] zeroinitializer
@dispatches.buffers = internal global [64 x [1024 x i8]] zeroinitializer
@dispatches.i = internal global i32 0
@dispatches.w = internal global i32 0
@dispatches.setsize = internal global i32 0
@FD_SETSIZE = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"select\00"
@.str.1 = [6 x i8] c"write\00"
@stdout = global i32 0
@.str.2 = [21 x i8] c"%i connections [-1]\0A\00"
define i32 @dispatches(i32 %0, i32* %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 %0, i32* %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32 0, i32* @dispatches.i
br label %12
12: ; preds = %37, %5
%13 = load i32, i32* @dispatches.i
%14 = load i32, i32* %7
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %40
16: ; preds = %12
%17 = load i32, i32* @dispatches.i
%18 = load i32, i32* %9
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i32, i32* @dispatches.i
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %22
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %23, i64 0, i64 0
%25 = load i8*, i8** %11
%26 = load i32, i32* %10
%27 = call i32 @memcpy(i8* %24, i8* %25, i32 %26)
%28 = load i32, i32* %10
%29 = load i32, i32* @dispatches.i
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %30
store i32 %28, i32* %31
br label %36
32: ; preds = %16
%33 = load i32, i32* @dispatches.i
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %34
store i32 0, i32* %35
br label %36
36: ; preds = %32, %20
br label %37
37: ; preds = %36
%38 = load i32, i32* @dispatches.i
%39 = add nsw i32 %38, 1
store i32 %39, i32* @dispatches.i
br label %12
40: ; preds = %12
br label %41
41: ; preds = %40, %80, %187
store i32 0, i32* @dispatches.setsize
%42 = call i32 @FD_ZERO(i32* @dispatches.writefdset)
store i32 0, i32* @dispatches.i
br label %43
43: ; preds = %63, %41
%44 = load i32, i32* @dispatches.i
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %66
47: ; preds = %43
%48 = load i32, i32* @dispatches.i
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %62
53: ; preds = %47
%54 = load i32, i32* @dispatches.setsize
%55 = add nsw i32 %54, 1
store i32 %55, i32* @dispatches.setsize
%56 = load i32*, i32** %8
%57 = load i32, i32* @dispatches.i
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = call i32 @FD_SET(i32 %60, i32* @dispatches.writefdset)
br label %62
62: ; preds = %53, %47
br label %63
63: ; preds = %62
%64 = load i32, i32* @dispatches.i
%65 = add nsw i32 %64, 1
store i32 %65, i32* @dispatches.i
br label %43
66: ; preds = %43
%67 = load i32, i32* @dispatches.setsize
%68 = icmp ne i32 %67, 0
br i1 %68, label %70, label %69
69: ; preds = %66
store i32 0, i32* %6
br label %188
70: ; preds = %66
%71 = load i32, i32* @FD_SETSIZE
%72 = call i64 @select(i32 %71, i32* null, i32* @dispatches.writefdset, i32* null, i32* null)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %81
74: ; preds = %70
%75 = load i64, i64* @errno
%76 = load i64, i64* @EINTR
%77 = icmp ne i64 %75, %76
br i1 %77, label %78, label %80
78: ; preds = %74
%79 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %188
80: ; preds = %74
br label %41
81: ; preds = %70
store i32 0, i32* @dispatches.i
br label %82
82: ; preds = %184, %81
%83 = load i32, i32* @dispatches.i
%84 = load i32, i32* %7
%85 = icmp slt i32 %83, %84
br i1 %85, label %86, label %187
86: ; preds = %82
%87 = load i32*, i32** %8
%88 = load i32, i32* @dispatches.i
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %87, i64 %89
%91 = load i32, i32* %90
%92 = call i64 @FD_ISSET(i32 %91, i32* @dispatches.writefdset)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %183
94: ; preds = %86
%95 = load i32*, i32** %8
%96 = load i32, i32* @dispatches.i
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32, i32* %95, i64 %97
%99 = load i32, i32* %98
%100 = load i32, i32* @dispatches.i
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %101
%103 = getelementptr inbounds [1024 x i8], [1024 x i8]* %102, i64 0, i64 0
%104 = load i32, i32* @dispatches.i
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %105
%107 = load i32, i32* %106
%108 = call i32 @write(i32 %99, i8* %103, i32 %107)
store i32 %108, i32* @dispatches.w
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %158
110: ; preds = %94
%111 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%112 = load i32*, i32** %8
%113 = load i32, i32* @dispatches.i
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i32, i32* %112, i64 %114
%116 = load i32, i32* %115
%117 = call i32 @close(i32 %116)
%118 = load i32, i32* @dispatches.i
%119 = load i32, i32* %7
%120 = add nsw i32 %119, -1
store i32 %120, i32* %7
%121 = icmp ne i32 %118, %120
br i1 %121, label %122, label %152
122: ; preds = %110
%123 = load i32*, i32** %8
%124 = load i32, i32* %7
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds i32, i32* %123, i64 %125
%127 = load i32, i32* %126
%128 = load i32*, i32** %8
%129 = load i32, i32* @dispatches.i
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i32, i32* %128, i64 %130
store i32 %127, i32* %131
%132 = load i32, i32* @dispatches.i
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %133
%135 = getelementptr inbounds [1024 x i8], [1024 x i8]* %134, i64 0, i64 0
%136 = load i32, i32* %7
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %137
%139 = getelementptr inbounds [1024 x i8], [1024 x i8]* %138, i64 0, i64 0
%140 = load i32, i32* %7
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %141
%143 = load i32, i32* %142
%144 = call i32 @memmove(i8* %135, i8* %139, i32 %143)
%145 = load i32, i32* %7
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %146
%148 = load i32, i32* %147
%149 = load i32, i32* @dispatches.i
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %150
store i32 %148, i32* %151
br label %152
152: ; preds = %122, %110
%153 = load i32, i32* @stdout
%154 = load i32, i32* %7
%155 = call i32 @fprintf(i32 %153, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %154)
%156 = load i32, i32* @stdout
%157 = call i32 @fflush(i32 %156)
br label %182
158: ; preds = %94
%159 = load i32, i32* @dispatches.i
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %160
%162 = getelementptr inbounds [1024 x i8], [1024 x i8]* %161, i64 0, i64 0
%163 = load i32, i32* @dispatches.i
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %164
%166 = load i32, i32* @dispatches.w
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds [1024 x i8], [1024 x i8]* %165, i64 0, i64 %167
%169 = load i32, i32* @dispatches.i
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %170
%172 = load i32, i32* %171
%173 = load i32, i32* @dispatches.w
%174 = sub nsw i32 %172, %173
%175 = call i32 @memmove(i8* %162, i8* %168, i32 %174)
%176 = load i32, i32* @dispatches.w
%177 = load i32, i32* @dispatches.i
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %178
%180 = load i32, i32* %179
%181 = sub nsw i32 %180, %176
store i32 %181, i32* %179
br label %182
182: ; preds = %158, %152
br label %183
183: ; preds = %182, %86
br label %184
184: ; preds = %183
%185 = load i32, i32* @dispatches.i
%186 = add nsw i32 %185, 1
store i32 %186, i32* @dispatches.i
br label %82
187: ; preds = %82
br label %41
188: ; preds = %78, %69
%189 = load i32, i32* %6
ret i32 %189
}

LLVM IR (-O2):
@dispatches.writefdset = internal global i32 0
@dispatches.pending = internal unnamed_addr global [64 x i32] zeroinitializer
@dispatches.buffers = internal global [64 x [1024 x i8]] zeroinitializer
@dispatches.i = internal unnamed_addr global i32 0
@dispatches.w = internal unnamed_addr global i32 0
@dispatches.setsize = internal unnamed_addr global i32 0
@FD_SETSIZE = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"select\00"
@.str.1 = [6 x i8] c"write\00"
@stdout = global i32 0
@.str.2 = [21 x i8] c"%i connections [-1]\0A\00"
define i32 @dispatches(i32 %0, i32* nocapture %1, i32 %2, i32 %3, i8* %4) {
store i32 0, i32* @dispatches.i
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %25
7: ; preds = %5
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %8
br label %10
10: ; preds = %7, %21
%11 = phi i32 [ %23, %21 ], [ 0, %7 ]
%12 = icmp eq i32 %11, %2
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %14, i64 0
%16 = tail call i32 @memcpy(i8* %15, i8* %4, i32 %3)
%17 = load i32, i32* @dispatches.i
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %18
store i32 %3, i32* %19
br label %21
20: ; preds = %10
store i32 0, i32* %9
br label %21
21: ; preds = %13, %20
%22 = phi i32 [ %17, %13 ], [ %2, %20 ]
%23 = add nsw i32 %22, 1
store i32 %23, i32* @dispatches.i
%24 = icmp slt i32 %23, %0
br i1 %24, label %10, label %25
25: ; preds = %21, %5
br label %26
26: ; preds = %127, %25
%27 = phi i32 [ %0, %25 ], [ %128, %127 ]
%28 = icmp sgt i32 %27, 0
br label %29
29: ; preds = %26, %56
br label %30
30: ; preds = %29, %57
store i32 0, i32* @dispatches.setsize
%31 = tail call i32 @FD_ZERO(i32* @dispatches.writefdset)
store i32 0, i32* @dispatches.i
br i1 %28, label %32, label %49
32: ; preds = %30, %45
%33 = phi i32 [ %47, %45 ], [ 0, %30 ]
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %32
%39 = load i32, i32* @dispatches.setsize
%40 = add nsw i32 %39, 1
store i32 %40, i32* @dispatches.setsize
%41 = getelementptr inbounds i32, i32* %1, i64 %34
%42 = load i32, i32* %41
%43 = tail call i32 @FD_SET(i32 %42, i32* @dispatches.writefdset)
%44 = load i32, i32* @dispatches.i
br label %45
45: ; preds = %32, %38
%46 = phi i32 [ %33, %32 ], [ %44, %38 ]
%47 = add nsw i32 %46, 1
store i32 %47, i32* @dispatches.i
%48 = icmp slt i32 %47, %27
br i1 %48, label %32, label %49
49: ; preds = %45, %30
%50 = load i32, i32* @dispatches.setsize
%51 = icmp eq i32 %50, 0
br i1 %51, label %132, label %52
52: ; preds = %49
%53 = load i32, i32* @FD_SETSIZE
%54 = tail call i64 @select(i32 %53, i32* null, i32* @dispatches.writefdset, i32* null, i32* null)
%55 = icmp slt i64 %54, 0
br i1 %55, label %57, label %56
56: ; preds = %52
store i32 0, i32* @dispatches.i
br i1 %28, label %63, label %29
57: ; preds = %52
%58 = load i64, i64* @errno
%59 = load i64, i64* @EINTR
%60 = icmp eq i64 %58, %59
br i1 %60, label %30, label %61
61: ; preds = %57
%62 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %132
63: ; preds = %56, %127
%64 = phi i32 [ %128, %127 ], [ %27, %56 ]
%65 = phi i32 [ %130, %127 ], [ 0, %56 ]
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %1, i64 %66
%68 = load i32, i32* %67
%69 = tail call i64 @FD_ISSET(i32 %68, i32* @dispatches.writefdset)
%70 = icmp eq i64 %69, 0
br i1 %70, label %127, label %71
71: ; preds = %63
%72 = load i32, i32* @dispatches.i
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %1, i64 %73
%75 = load i32, i32* %74
%76 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %73, i64 0
%77 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %73
%78 = load i32, i32* %77
%79 = tail call i32 @write(i32 %75, i8* %76, i32 %78)
store i32 %79, i32* @dispatches.w
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %111
81: ; preds = %71
%82 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%83 = load i32, i32* @dispatches.i
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %1, i64 %84
%86 = load i32, i32* %85
%87 = tail call i32 @close(i32 %86)
%88 = load i32, i32* @dispatches.i
%89 = add nsw i32 %64, -1
%90 = icmp eq i32 %88, %89
br i1 %90, label %106, label %91
91: ; preds = %81
%92 = sext i32 %89 to i64
%93 = getelementptr inbounds i32, i32* %1, i64 %92
%94 = load i32, i32* %93
%95 = sext i32 %88 to i64
%96 = getelementptr inbounds i32, i32* %1, i64 %95
store i32 %94, i32* %96
%97 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %95, i64 0
%98 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %92, i64 0
%99 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %92
%100 = load i32, i32* %99
%101 = tail call i32 @memmove(i8* %97, i8* %98, i32 %100)
%102 = load i32, i32* %99
%103 = load i32, i32* @dispatches.i
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %104
store i32 %102, i32* %105
br label %106
106: ; preds = %91, %81
%107 = load i32, i32* @stdout
%108 = tail call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %89)
%109 = load i32, i32* @stdout
%110 = tail call i32 @fflush(i32 %109)
br label %127
111: ; preds = %71
%112 = load i32, i32* @dispatches.i
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %113, i64 0
%115 = zext i32 %79 to i64
%116 = getelementptr inbounds [64 x [1024 x i8]], [64 x [1024 x i8]]* @dispatches.buffers, i64 0, i64 %113, i64 %115
%117 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %113
%118 = load i32, i32* %117
%119 = sub nsw i32 %118, %79
%120 = tail call i32 @memmove(i8* %114, i8* %116, i32 %119)
%121 = load i32, i32* @dispatches.w
%122 = load i32, i32* @dispatches.i
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [64 x i32], [64 x i32]* @dispatches.pending, i64 0, i64 %123
%125 = load i32, i32* %124
%126 = sub nsw i32 %125, %121
store i32 %126, i32* %124
br label %127
127: ; preds = %63, %111, %106
%128 = phi i32 [ %89, %106 ], [ %64, %111 ], [ %64, %63 ]
%129 = load i32, i32* @dispatches.i
%130 = add nsw i32 %129, 1
store i32 %130, i32* @dispatches.i
%131 = icmp slt i32 %130, %128
br i1 %131, label %63, label %26
132: ; preds = %49, %61
%133 = phi i32 [ -1, %61 ], [ 0, %49 ]
ret i32 %133
}