#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_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int read(int, int *, int);
void server(int sock, struct sockaddr_in address) {
  int accepted;
  int addrlen = sizeof(address);
  int buffer;
  while (1) {
    accepted = accept(sock, (struct sockaddr *)&address, (socklen_t *)&addrlen);
    if (accepted < 0)
      error(-1, errno, "accept");
    if (read(accepted, &buffer, sizeof(buffer)) == -1)
      error(-1, errno, "read");
    close(accepted);
  }
}


x86 assembly (clang, -O0):
<server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %esi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    118c <server+0x4c>
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
lea    0xe79(%rip),%rdx
call   1050 <error@plt>
mov    -0x10(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    11c0 <server+0x80>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
lea    0xe4c(%rip),%rdx
call   1050 <error@plt>
mov    -0x10(%rbp),%edi
call   1030 <close@plt>
jmp    1155 <server+0x15>

x86 assembly (clang, -O2):
<server>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %esi,0x8(%rsp)
movl   $0x4,0x10(%rsp)
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
mov    0x2e73(%rip),%rbp
lea    0x14(%rsp),%r13
jmp    1188 <server+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12d,%edi
call   1030 <close@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <accept@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    11b0 <server+0x70>
mov    0x0(%rbp),%esi
mov    $0xffffffff,%edi
lea    0xe55(%rip),%rdx
call   1050 <error@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    1180 <server+0x40>
mov    0x0(%rbp),%esi
mov    $0xffffffff,%edi
lea    0xe33(%rip),%rdx
call   1050 <error@plt>
jmp    1180 <server+0x40>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@.str = [7 x i8] c"accept\00"
@.str.1 = [5 x i8] c"read\00"
define void @server(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %1, i32* %8
store i32 %0, i32* %4
store i32 4, i32* %6
br label %9
9: ; preds = %2, %25
%10 = load i32, i32* %4
%11 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%12 = call i32 @accept(i32 %10, %struct.sockaddr* %11, i32* %6)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i32, i32* @errno
%17 = call i32 @error(i32 -1, i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %9
%19 = load i32, i32* %5
%20 = call i32 @read(i32 %19, i32* %7, i32 4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @errno
%24 = call i32 @error(i32 -1, i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %22, %18
%26 = load i32, i32* %5
%27 = call i32 @close(i32 %26)
br label %9
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@errno = global i32 0
@.str = [7 x i8] c"accept\00"
@.str.1 = [5 x i8] c"read\00"
define void @server(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %1, i32* %6
%7 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%8 = bitcast i32* %5 to i8*
%9 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %10
10: ; preds = %22, %2
%11 = call i32 @accept(i32 %0, %struct.sockaddr* %9, i32* %4)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @errno
%15 = call i32 @error(i32 -1, i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %10
%17 = call i32 @read(i32 %11, i32* %5, i32 4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @errno
%21 = call i32 @error(i32 -1, i32 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %16
%23 = call i32 @close(i32 %11)
br label %10
}