#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_storage {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *);
int process_request(int, char *);
int /*<<< orphan*/ report_errno(char *);
int /*<<< orphan*/ send_server_error(int);
int acceptConnections(int serverfd, char *hostname) {
  int connfd;
  struct sockaddr_storage client_addr;
  socklen_t client_addr_len = sizeof client_addr;
  while (1) {
    connfd =
        accept(serverfd, (struct sockaddr *)&client_addr, &client_addr_len);
    if (connfd == -1) {
      report_errno("error accepting connection.");
      break;
    } else {
      if (process_request(connfd, hostname) == -1) {
        printf("error processing request, "
               "sending server error message.\n");
        send_server_error(connfd);
      }
    }
    close(connfd);
  }
  return -1;
}


x86 assembly (clang, -O0):
<acceptConnections>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1080 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11a4 <acceptConnections+0x44>
lea    0xe66(%rip),%rdi
call   1060 <report_errno@plt>
jmp    11df <acceptConnections+0x7f>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <process_request@plt>
cmp    $0xffffffff,%eax
jne    11cd <acceptConnections+0x6d>
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <send_server_error@plt>
jmp    11d2 <acceptConnections+0x72>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    1176 <acceptConnections+0x16>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acceptConnections>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    %edi,%ebp
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1080 <accept@plt>
cmp    $0xffffffff,%eax
je     11eb <acceptConnections+0x8b>
mov    %eax,%ebx
lea    0xe84(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
jmp    11cb <acceptConnections+0x6b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1080 <accept@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11eb <acceptConnections+0x8b>
mov    %ebx,%edi
mov    %r13,%rsi
call   1040 <process_request@plt>
cmp    $0xffffffff,%eax
jne    11b0 <acceptConnections+0x50>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <send_server_error@plt>
jmp    11b0 <acceptConnections+0x50>
lea    0xe0e(%rip),%rdi
call   1060 <report_errno@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [28 x i8] c"error accepting connection.\00"
@.str.1 = [57 x i8] c"error processing request, sending server error message.\0A\00"
define i32 @acceptConnections(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 4, i32* %7
br label %8
8: ; preds = %2, %26
%9 = load i32, i32* %3
%10 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%11 = call i32 @accept(i32 %9, %struct.sockaddr* %10, i32* %7)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @report_errno(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %29
16: ; preds = %8
%17 = load i32, i32* %5
%18 = load i8*, i8** %4
%19 = call i32 @process_request(i32 %17, i8* %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %5
%24 = call i32 @send_server_error(i32 %23)
br label %25
25: ; preds = %21, %16
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = call i32 @close(i32 %27)
br label %8
29: ; preds = %14
ret i32 -1
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [28 x i8] c"error accepting connection.\00"
@str = [56 x i8] c"error processing request, sending server error message.\00"
define i32 @acceptConnections(i32 %0, i8* %1) {
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = bitcast %struct.sockaddr_storage* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%7 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%8 = call i32 @accept(i32 %0, %struct.sockaddr* %7, i32* %4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %19, %2
%11 = call i32 @report_errno(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
ret i32 -1
12: ; preds = %2, %19
%13 = phi i32 [ %21, %19 ], [ %8, %2 ]
%14 = call i32 @process_request(i32 %13, i8* %1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%18 = call i32 @send_server_error(i32 %13)
br label %19
19: ; preds = %12, %16
%20 = call i32 @close(i32 %13)
%21 = call i32 @accept(i32 %0, %struct.sockaddr* %7, i32* %4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %10, label %12
}