#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_ZERO(int /*<<< orphan*/ *);
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int client_treatment(int, char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int create_client_socket(int *sockets, char *document_root) {
  fd_set fds;
  int pid;
  int client_socket = -1;
  FD_ZERO(&fds);
  FD_SET(sockets[0], &fds);
  FD_SET(sockets[1], &fds);
  if (select(sockets[1] + 1, &fds, NULL, NULL, NULL) == -1) {
    if (errno != EINTR) {
      perror("select");
      return -1;
    }
  } else {
    if (FD_ISSET(sockets[0], &fds))
      client_socket = accept(sockets[0], NULL, NULL);
    else if (FD_ISSET(sockets[1], &fds))
      client_socket = accept(sockets[1], NULL, NULL);
    else
      printf("Why can I even read this?!\n");
    if (client_socket < 0) {
      perror("accept");
      return -1;
    }
    if ((pid = fork()) == -1) {
      perror("fork");
      return -1;
    } else if (pid == 0) {
      sleep(1);
      if (client_treatment(client_socket, document_root) == -1) {
        printf("Could not start client treatment");
      }
    }
    close(client_socket);
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_client_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x24(%rbp)
lea    -0x1c(%rbp),%rdi
call   1060 <FD_ZERO@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
call   10b0 <FD_SET@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x1c(%rbp),%rsi
call   10b0 <FD_SET@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
add    $0x1,%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1070 <select@plt>
cmp    $0xffffffff,%eax
jne    124d <create_client_socket+0x9d>
mov    0x2dc3(%rip),%rax
mov    (%rax),%rax
mov    0x2db1(%rip),%rcx
cmp    (%rcx),%rax
je     1248 <create_client_socket+0x98>
lea    0xdc9(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1361 <create_client_socket+0x1b1>
jmp    135a <create_client_socket+0x1aa>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1280 <create_client_socket+0xd0>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10a0 <accept@plt>
mov    %eax,-0x24(%rbp)
jmp    12c6 <create_client_socket+0x116>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12b5 <create_client_socket+0x105>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10a0 <accept@plt>
mov    %eax,-0x24(%rbp)
jmp    12c1 <create_client_socket+0x111>
lea    0xd4b(%rip),%rdi
call   1040 <printf@plt>
jmp    12c6 <create_client_socket+0x116>
cmpl   $0x0,-0x24(%rbp)
jge    12e8 <create_client_socket+0x138>
lea    0xd4c(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1361 <create_client_socket+0x1b1>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    1313 <create_client_socket+0x163>
lea    0xd28(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1361 <create_client_socket+0x1b1>
cmpl   $0x0,-0x20(%rbp)
jne    134d <create_client_socket+0x19d>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <client_treatment@plt>
cmp    $0xffffffff,%eax
jne    1348 <create_client_socket+0x198>
lea    0xcec(%rip),%rdi
call   1040 <printf@plt>
jmp    134d <create_client_socket+0x19d>
jmp    1352 <create_client_socket+0x1a2>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_client_socket>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x4(%rsp),%r12
mov    %r12,%rdi
call   1070 <FD_ZERO@plt>
mov    (%rbx),%edi
mov    %r12,%rsi
call   10c0 <FD_SET@plt>
mov    0x4(%rbx),%edi
mov    %r12,%rsi
call   10c0 <FD_SET@plt>
mov    0x4(%rbx),%edi
add    $0x1,%edi
xor    %r15d,%r15d
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <select@plt>
cmp    $0xffffffff,%eax
je     1265 <create_client_socket+0xa5>
mov    (%rbx),%edi
lea    0x4(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
jne    1237 <create_client_socket+0x77>
add    $0x4,%rbx
mov    (%rbx),%edi
lea    0x4(%rsp),%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
je     12c2 <create_client_socket+0x102>
mov    (%rbx),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
test   %eax,%eax
js     12ce <create_client_socket+0x10e>
mov    %eax,%ebx
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     1284 <create_client_socket+0xc4>
cmp    $0xffffffff,%eax
jne    12a9 <create_client_socket+0xe9>
lea    0xdab(%rip),%rdi
jmp    12d5 <create_client_socket+0x115>
mov    0x2d74(%rip),%rax
mov    (%rax),%rax
mov    0x2d62(%rip),%rcx
cmp    (%rcx),%rax
je     12b3 <create_client_socket+0xf3>
lea    0xd7e(%rip),%rdi
jmp    12d5 <create_client_socket+0x115>
mov    $0x1,%edi
call   10d0 <sleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1090 <client_treatment@plt>
cmp    $0xffffffff,%eax
jne    12a9 <create_client_socket+0xe9>
lea    0xd6f(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd6b(%rip),%rdi
call   1030 <puts@plt>
lea    0xd32(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%r15d
jmp    12b3 <create_client_socket+0xf3>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"select\00"
@.str.1 = [28 x i8] c"Why can I even read this?!\0A\00"
@.str.2 = [7 x i8] c"accept\00"
@.str.3 = [5 x i8] c"fork\00"
@.str.4 = [33 x i8] c"Could not start client treatment\00"
define i32 @create_client_socket(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 -1, i32* %8
%9 = call i32 @FD_ZERO(i32* %6)
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = call i32 @FD_SET(i32 %12, i32* %6)
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = load i32, i32* %15
%17 = call i32 @FD_SET(i32 %16, i32* %6)
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
%22 = call i32 @select(i32 %21, i32* %6, i32* null, i32* null, i32* null)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %31
24: ; preds = %2
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %83
30: ; preds = %24
br label %82
31: ; preds = %2
%32 = load i32*, i32** %4
%33 = getelementptr inbounds i32, i32* %32, i64 0
%34 = load i32, i32* %33
%35 = call i64 @FD_ISSET(i32 %34, i32* %6)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i32*, i32** %4
%39 = getelementptr inbounds i32, i32* %38, i64 0
%40 = load i32, i32* %39
%41 = call i32 @accept(i32 %40, i32* null, i32* null)
store i32 %41, i32* %8
br label %56
42: ; preds = %31
%43 = load i32*, i32** %4
%44 = getelementptr inbounds i32, i32* %43, i64 1
%45 = load i32, i32* %44
%46 = call i64 @FD_ISSET(i32 %45, i32* %6)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = load i32*, i32** %4
%50 = getelementptr inbounds i32, i32* %49, i64 1
%51 = load i32, i32* %50
%52 = call i32 @accept(i32 %51, i32* null, i32* null)
store i32 %52, i32* %8
br label %55
53: ; preds = %42
%54 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %55
55: ; preds = %53, %48
br label %56
56: ; preds = %55, %37
%57 = load i32, i32* %8
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %83
61: ; preds = %56
%62 = call i32 (...) @fork()
store i32 %62, i32* %7
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %83
66: ; preds = %61
%67 = load i32, i32* %7
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %78
69: ; preds = %66
%70 = call i32 @sleep(i32 1)
%71 = load i32, i32* %8
%72 = load i8*, i8** %5
%73 = call i32 @client_treatment(i32 %71, i8* %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %77
75: ; preds = %69
%76 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %77
77: ; preds = %75, %69
br label %78
78: ; preds = %77, %66
br label %79
79: ; preds = %78
%80 = load i32, i32* %8
%81 = call i32 @close(i32 %80)
br label %82
82: ; preds = %79, %30
store i32 0, i32* %3
br label %83
83: ; preds = %82, %64, %59, %28
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [7 x i8] c"select\00"
@.str.2 = [7 x i8] c"accept\00"
@.str.3 = [5 x i8] c"fork\00"
@.str.4 = [33 x i8] c"Could not start client treatment\00"
@str = [27 x i8] c"Why can I even read this?!\00"
define i32 @create_client_socket(i32* nocapture %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @FD_ZERO(i32* %3)
%6 = load i32, i32* %0
%7 = call i32 @FD_SET(i32 %6, i32* %3)
%8 = getelementptr inbounds i32, i32* %0, i64 1
%9 = load i32, i32* %8
%10 = call i32 @FD_SET(i32 %9, i32* %3)
%11 = load i32, i32* %8
%12 = add nsw i32 %11, 1
%13 = call i32 @select(i32 %12, i32* %3, i32* null, i32* null, i32* null)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %50, label %19
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %50
21: ; preds = %2
%22 = load i32, i32* %0
%23 = call i64 @FD_ISSET(i32 %22, i32* %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i32, i32* %8
%27 = call i64 @FD_ISSET(i32 %26, i32* %3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %36
31: ; preds = %25, %21
%32 = phi i32* [ %0, %21 ], [ %8, %25 ]
%33 = load i32, i32* %32
%34 = call i32 @accept(i32 %33, i32* null, i32* null)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %29, %31
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %50
38: ; preds = %31
%39 = call i32 (...) @fork()
switch i32 %39, label %48 [
i32 -1, label %40
i32 0, label %42
]
40: ; preds = %38
%41 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %50
42: ; preds = %38
%43 = call i32 @sleep(i32 1)
%44 = call i32 @client_treatment(i32 %34, i8* %1)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %38, %46, %42
%49 = call i32 @close(i32 %34)
br label %50
50: ; preds = %48, %15, %40, %36, %19
%51 = phi i32 [ -1, %19 ], [ -1, %36 ], [ -1, %40 ], [ 0, %15 ], [ 0, %48 ]
ret i32 %51
}