#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 sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
struct pollfd {
  int fd;
  int events;
  int revents;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ server_address;
typedef int /*<<< orphan*/ poll_set;
typedef int /*<<< orphan*/ client_address;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ FIONREAD;
int POLLIN;
int POLLPRI;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct pollfd *, char, int);
int /*<<< orphan*/ poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int server_sockfd, client_sockfd;
  int server_len, client_len;
  struct sockaddr_un server_address;
  struct sockaddr_un client_address;
  int result;
  struct pollfd poll_set[32];
  int numfds = 0;
  unlink("web/server_socket.sock");
  server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  server_address.sun_family = AF_UNIX;
  strcpy(server_address.sun_path, "web/server_socket.sock");
  server_len = sizeof(server_address);
  bind(server_sockfd, (struct sockaddr *)&server_address,
       (socklen_t)server_len);
  listen(server_sockfd, 5);
  memset(poll_set, '\0', sizeof(poll_set));
  poll_set[0].fd = server_sockfd;
  poll_set[0].events = POLLIN | POLLPRI;
  numfds++;
  while (1) {
    char ch;
    int fd_index;
    int nread;
    printf("Waiting for client (%d total)...\n", numfds);
    poll(poll_set, numfds, 2000);
    for (fd_index = 0; fd_index < numfds; fd_index++) {
      if (poll_set[fd_index].revents & POLLIN) {
        if (poll_set[fd_index].fd == server_sockfd) {
          client_len = sizeof(client_address);
          client_sockfd =
              accept(server_sockfd, (struct sockaddr *)&client_address,
                     (socklen_t *)&client_len);
          poll_set[numfds].fd = client_sockfd;
          poll_set[numfds].events = POLLIN;
          numfds++;
          printf("Adding client on fd %d\n", client_sockfd);
        } else {
          ioctl(poll_set[fd_index].fd, FIONREAD, &nread);
          if (nread == 0) {
            close(poll_set[fd_index].fd);
            poll_set[fd_index].events = 0;
            printf("Removing client on fd %d\n", poll_set[fd_index].fd);
            poll_set[fd_index] = poll_set[fd_index + 1];
            numfds--;
          } else {
            read(poll_set[fd_index].fd, &ch, 1);
            printf("Serving client on fd %d\n", poll_set[fd_index].fd);
            ch++;
            write(poll_set[fd_index].fd, &ch, 1);
          }
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1b4(%rbp)
lea    0xe0d(%rip),%rdi
call   1030 <unlink@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    0xdd6(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x8,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   10d0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
lea    -0x1b0(%rbp),%rdi
xor    %esi,%esi
mov    $0x180,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    0x2d72(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1ac(%rbp)
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%esi
lea    0xd75(%rip),%rdi
call   1060 <printf@plt>
lea    -0x1b0(%rbp),%rdi
mov    -0x1b4(%rbp),%esi
mov    $0x7d0,%edx
call   10c0 <poll@plt>
movl   $0x0,-0x1bc(%rbp)
mov    -0x1bc(%rbp),%eax
cmp    -0x1b4(%rbp),%eax
jge    1523 <main+0x353>
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    0x2cd7(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     150a <main+0x33a>
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    139c <main+0x1cc>
movl   $0x8,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
movslq -0x1b4(%rbp),%rdx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
mov    0x2c71(%rip),%rax
mov    (%rax),%ecx
movslq -0x1b4(%rbp),%rdx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,0x4(%rax)
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
mov    -0xc(%rbp),%esi
lea    0xca7(%rip),%rdi
call   1060 <printf@plt>
jmp    1505 <main+0x335>
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
mov    0x2c26(%rip),%rax
mov    (%rax),%esi
lea    -0x1c0(%rbp),%rdx
call   1080 <ioctl@plt>
cmpl   $0x0,-0x1c0(%rbp)
jne    147f <main+0x2af>
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
call   1090 <close@plt>
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0x0,0x4(%rax)
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%esi
lea    0xc26(%rip),%rdi
call   1060 <printf@plt>
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    -0x1bc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rdx
lea    -0x1b0(%rbp),%rcx
imul   $0xc,%rdx,%rdx
add    %rdx,%rcx
mov    (%rcx),%rdx
mov    %rdx,(%rax)
mov    0x8(%rcx),%ecx
mov    %ecx,0x8(%rax)
mov    -0x1b4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1b4(%rbp)
jmp    1500 <main+0x330>
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x1b5(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%esi
lea    0xba6(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1b5(%rbp),%al
add    $0x1,%al
mov    %al,-0x1b5(%rbp)
movslq -0x1bc(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x1b5(%rbp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
jmp    1505 <main+0x335>
jmp    150a <main+0x33a>
jmp    150f <main+0x33f>
mov    -0x1bc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1bc(%rbp)
jmp    12c8 <main+0xf8>
jmp    1295 <main+0xc5>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
lea    0xe18(%rip),%r14
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    0x2de1(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x14(%rsp)
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   10d0 <bind@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
lea    0x20(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x180,%edx
call   1070 <memset@plt>
mov    0x2d7d(%rip),%r13
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
or     0x0(%r13),%eax
mov    %ebx,0x20(%rsp)
mov    %eax,0x24(%rsp)
mov    $0x1,%ebp
lea    0x7(%rsp),%r12
jmp    1285 <main+0xb5>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x20(%rsp),%r15
lea    0xd8b(%rip),%rdi
mov    %ebp,%esi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x7d0,%edx
call   10c0 <poll@plt>
test   %ebp,%ebp
jle    1280 <main+0xb0>
xor    %r14d,%r14d
jmp    12fd <main+0x12d>
nopl   0x0(%rax,%rax,1)
movl   $0x8,0xc(%rsp)
mov    %ebx,%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10e0 <accept@plt>
movslq %ebp,%rcx
lea    (%rcx,%rcx,2),%rcx
mov    %eax,0x20(%rsp,%rcx,4)
mov    0x0(%r13),%edx
mov    %edx,0x24(%rsp,%rcx,4)
add    $0x1,%ebp
lea    0xd53(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
add    $0x1,%r14
movslq %ebp,%rax
add    $0xc,%r15
cmp    %rax,%r14
jge    1280 <main+0xb0>
mov    0x0(%r13),%eax
test   %eax,0x8(%r15)
je     12ed <main+0x11d>
mov    (%r15),%edi
cmp    %ebx,%edi
je     12b0 <main+0xe0>
mov    0x2ccb(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1080 <ioctl@plt>
cmpl   $0x0,0x8(%rsp)
mov    (%r15),%edi
je     135e <main+0x18e>
mov    %r12,%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
mov    (%r15),%esi
lea    0xd29(%rip),%rdi
call   1060 <printf@plt>
addb   $0x1,0x7(%rsp)
mov    (%r15),%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
jmp    12ed <main+0x11d>
call   1090 <close@plt>
movl   $0x0,0x4(%r15)
mov    (%r15),%esi
lea    0xcdc(%rip),%rdi
call   1060 <printf@plt>
mov    0xc(%r15),%rax
mov    %rax,(%r15)
mov    0x14(%r15),%eax
mov    %eax,0x8(%r15)
add    $0xffffffff,%ebp
jmp    12ed <main+0x11d>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.pollfd = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"web/server_socket.sock\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@POLLIN = global i32 0
@POLLPRI = global i32 0
@.str.1 = [34 x i8] c"Waiting for client (%d total)...\0A\00"
@.str.2 = [24 x i8] c"Adding client on fd %d\0A\00"
@FIONREAD = global i32 0
@.str.3 = [26 x i8] c"Removing client on fd %d\0A\00"
@.str.4 = [25 x i8] c"Serving client on fd %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_un
%7 = alloca %struct.sockaddr_un
%8 = alloca i32
%9 = alloca [32 x %struct.pollfd]
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %10
%14 = call i32 @unlink(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @AF_UNIX
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %2
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @strcpy(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 8, i32* %4
%23 = load i32, i32* %2
%24 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%25 = load i32, i32* %4
%26 = call i32 @bind(i32 %23, %struct.sockaddr* %24, i32 %25)
%27 = load i32, i32* %2
%28 = call i32 @listen(i32 %27, i32 5)
%29 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 0
%30 = call i32 @memset(%struct.pollfd* %29, i8 signext 0, i32 384)
%31 = load i32, i32* %2
%32 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 0
%33 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load i32, i32* @POLLIN
%35 = load i32, i32* @POLLPRI
%36 = or i32 %34, %35
%37 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 0
%38 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %37, i32 0, i32 1
store i32 %36, i32* %38
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %41
41: ; preds = %0, %151
%42 = load i32, i32* %10
%43 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 0
%45 = load i32, i32* %10
%46 = call i32 @poll(%struct.pollfd* %44, i32 %45, i32 2000)
store i32 0, i32* %12
br label %47
47: ; preds = %148, %41
%48 = load i32, i32* %12
%49 = load i32, i32* %10
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %151
51: ; preds = %47
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %53
%55 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %54, i32 0, i32 2
%56 = load i32, i32* %55
%57 = load i32, i32* @POLLIN
%58 = and i32 %56, %57
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %147
60: ; preds = %51
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %62
%64 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = load i32, i32* %2
%67 = icmp eq i32 %65, %66
br i1 %67, label %68, label %86
68: ; preds = %60
store i32 8, i32* %5
%69 = load i32, i32* %2
%70 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%71 = call i32 @accept(i32 %69, %struct.sockaddr* %70, i32* %5)
store i32 %71, i32* %3
%72 = load i32, i32* %3
%73 = load i32, i32* %10
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %74
%76 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %75, i32 0, i32 0
store i32 %72, i32* %76
%77 = load i32, i32* @POLLIN
%78 = load i32, i32* %10
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %79
%81 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %80, i32 0, i32 1
store i32 %77, i32* %81
%82 = load i32, i32* %10
%83 = add nsw i32 %82, 1
store i32 %83, i32* %10
%84 = load i32, i32* %3
%85 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %84)
br label %146
86: ; preds = %60
%87 = load i32, i32* %12
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %88
%90 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %89, i32 0, i32 0
%91 = load i32, i32* %90
%92 = load i32, i32* @FIONREAD
%93 = call i32 @ioctl(i32 %91, i32 %92, i32* %13)
%94 = load i32, i32* %13
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %124
96: ; preds = %86
%97 = load i32, i32* %12
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %98
%100 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %99, i32 0, i32 0
%101 = load i32, i32* %100
%102 = call i32 @close(i32 %101)
%103 = load i32, i32* %12
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %104
%106 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %105, i32 0, i32 1
store i32 0, i32* %106
%107 = load i32, i32* %12
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %108
%110 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %109, i32 0, i32 0
%111 = load i32, i32* %110
%112 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %111)
%113 = load i32, i32* %12
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %114
%116 = load i32, i32* %12
%117 = add nsw i32 %116, 1
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %118
%120 = bitcast %struct.pollfd* %115 to i8*
%121 = bitcast %struct.pollfd* %119 to i8*
%122 = load i32, i32* %10
%123 = add nsw i32 %122, -1
store i32 %123, i32* %10
br label %145
124: ; preds = %86
%125 = load i32, i32* %12
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %126
%128 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %127, i32 0, i32 0
%129 = load i32, i32* %128
%130 = call i32 @read(i32 %129, i8* %11, i32 1)
%131 = load i32, i32* %12
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %132
%134 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %133, i32 0, i32 0
%135 = load i32, i32* %134
%136 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %135)
%137 = load i8, i8* %11
%138 = add i8 %137, 1
store i8 %138, i8* %11
%139 = load i32, i32* %12
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %9, i64 0, i64 %140
%142 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %141, i32 0, i32 0
%143 = load i32, i32* %142
%144 = call i32 @write(i32 %143, i8* %11, i32 1)
br label %145
145: ; preds = %124, %96
br label %146
146: ; preds = %145, %68
br label %147
147: ; preds = %146, %51
br label %148
148: ; preds = %147
%149 = load i32, i32* %12
%150 = add nsw i32 %149, 1
store i32 %150, i32* %12
br label %47
151: ; preds = %47
br label %41
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.pollfd = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"web/server_socket.sock\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@POLLIN = global i32 0
@POLLPRI = global i32 0
@.str.1 = [34 x i8] c"Waiting for client (%d total)...\0A\00"
@.str.2 = [24 x i8] c"Adding client on fd %d\0A\00"
@FIONREAD = global i32 0
@.str.3 = [26 x i8] c"Removing client on fd %d\0A\00"
@.str.4 = [25 x i8] c"Serving client on fd %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_un
%3 = alloca %struct.sockaddr_un
%4 = alloca [32 x %struct.pollfd]
%5 = alloca i8
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
%8 = bitcast %struct.sockaddr_un* %2 to i8*
%9 = bitcast %struct.sockaddr_un* %3 to i8*
%10 = bitcast [32 x %struct.pollfd]* %4 to i8*
%11 = tail call i32 @unlink(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @AF_UNIX
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = load i32, i32* @AF_UNIX
%16 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %15, i32* %16
%17 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%18 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%19 = call i32 @bind(i32 %14, %struct.sockaddr* %18, i32 8)
%20 = call i32 @listen(i32 %14, i32 5)
%21 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %4, i64 0, i64 0
%22 = call i32 @memset(%struct.pollfd* %21, i8 signext 0, i32 384)
%23 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %4, i64 0, i64 0, i32 0
store i32 %14, i32* %23
%24 = load i32, i32* @POLLIN
%25 = load i32, i32* @POLLPRI
%26 = or i32 %25, %24
%27 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %4, i64 0, i64 0, i32 1
store i32 %26, i32* %27
%28 = bitcast i32* %6 to i8*
%29 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
br label %30
30: ; preds = %85, %0
%31 = phi i32 [ 1, %0 ], [ %86, %85 ]
%32 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = call i32 @poll(%struct.pollfd* %21, i32 %31, i32 2000)
%34 = icmp sgt i32 %31, 0
br i1 %34, label %35, label %85
35: ; preds = %30, %80
%36 = phi i64 [ %82, %80 ], [ 0, %30 ]
%37 = phi i32 [ %81, %80 ], [ %31, %30 ]
%38 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %4, i64 0, i64 %36
%39 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %4, i64 0, i64 %36, i32 2
%40 = load i32, i32* %39
%41 = load i32, i32* @POLLIN
%42 = and i32 %41, %40
%43 = icmp eq i32 %42, 0
br i1 %43, label %80, label %44
44: ; preds = %35
%45 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %38, i64 0, i32 0
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, %14
br i1 %47, label %48, label %56
48: ; preds = %44
store i32 8, i32* %1
%49 = call i32 @accept(i32 %14, %struct.sockaddr* %29, i32* %1)
%50 = sext i32 %37 to i64
%51 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %4, i64 0, i64 %50, i32 0
store i32 %49, i32* %51
%52 = load i32, i32* @POLLIN
%53 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %4, i64 0, i64 %50, i32 1
store i32 %52, i32* %53
%54 = add nsw i32 %37, 1
%55 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %49)
br label %80
56: ; preds = %44
%57 = load i32, i32* @FIONREAD
%58 = call i32 @ioctl(i32 %46, i32 %57, i32* %6)
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, 0
%61 = load i32, i32* %45
br i1 %60, label %62, label %72
62: ; preds = %56
%63 = call i32 @close(i32 %61)
%64 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %4, i64 0, i64 %36, i32 1
store i32 0, i32* %64
%65 = load i32, i32* %45
%66 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %65)
%67 = add nuw nsw i64 %36, 1
%68 = getelementptr inbounds [32 x %struct.pollfd], [32 x %struct.pollfd]* %4, i64 0, i64 %67
%69 = bitcast %struct.pollfd* %38 to i8*
%70 = bitcast %struct.pollfd* %68 to i8*
%71 = add nsw i32 %37, -1
br label %80
72: ; preds = %56
%73 = call i32 @read(i32 %61, i8* %5, i32 1)
%74 = load i32, i32* %45
%75 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %74)
%76 = load i8, i8* %5
%77 = add i8 %76, 1
store i8 %77, i8* %5
%78 = load i32, i32* %45
%79 = call i32 @write(i32 %78, i8* %5, i32 1)
br label %80
80: ; preds = %35, %62, %72, %48
%81 = phi i32 [ %54, %48 ], [ %71, %62 ], [ %37, %72 ], [ %37, %35 ]
%82 = add nuw nsw i64 %36, 1
%83 = sext i32 %81 to i64
%84 = icmp slt i64 %82, %83
br i1 %84, label %35, label %85
85: ; preds = %80, %30
%86 = phi i32 [ %31, %30 ], [ %81, %80 ]
br label %30
}