#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*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ listen(int, int);
int socket(int, int, int);
int server(int sock, int domain, int type, int protocol,
           struct sockaddr *serv_addr, int addrlen, int backlog,
           struct sockaddr_storage client_addr, socklen_t addr_size) {
  int returnvalue;
  sock = socket(domain, type, protocol);
  bind(sock, serv_addr, addrlen);
  listen(sock, backlog);
  addr_size = sizeof client_addr;
  returnvalue = accept(sock, (struct sockaddr *)&client_addr, &addr_size);
  return returnvalue;
}


x86 assembly (clang, -O0):
<server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%r10d
mov    %eax,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <socket@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <bind@plt>
mov    -0xc(%rbp),%edi
mov    0x10(%rbp),%esi
call   1030 <listen@plt>
movl   $0x4,0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    0x20(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r9d,%r15d
mov    %r8,%rbx
mov    %esi,%edi
mov    0x30(%rsp),%r14d
mov    %edx,%esi
mov    %ecx,%edx
call   1060 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <bind@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <listen@plt>
movl   $0x4,0x4(%rsp)
lea    0x38(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   1050 <accept@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_storage = type { i32 }
define i32 @server(i32 %0, i32 %1, i32 %2, i32 %3, %struct.sockaddr* %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca %struct.sockaddr_storage
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.sockaddr*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %10, i32 0, i32 0
store i32 %7, i32* %20
store i32 %0, i32* %11
store i32 %1, i32* %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store %struct.sockaddr* %4, %struct.sockaddr** %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store i32 %8, i32* %18
%21 = load i32, i32* %12
%22 = load i32, i32* %13
%23 = load i32, i32* %14
%24 = call i32 @socket(i32 %21, i32 %22, i32 %23)
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = load %struct.sockaddr*, %struct.sockaddr** %15
%27 = load i32, i32* %16
%28 = call i32 @bind(i32 %25, %struct.sockaddr* %26, i32 %27)
%29 = load i32, i32* %11
%30 = load i32, i32* %17
%31 = call i32 @listen(i32 %29, i32 %30)
store i32 4, i32* %18
%32 = load i32, i32* %11
%33 = bitcast %struct.sockaddr_storage* %10 to %struct.sockaddr*
%34 = call i32 @accept(i32 %32, %struct.sockaddr* %33, i32* %18)
store i32 %34, i32* %19
%35 = load i32, i32* %19
ret i32 %35
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.sockaddr_storage = type { i32 }
define i32 @server(i32 %0, i32 %1, i32 %2, i32 %3, %struct.sockaddr* %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca %struct.sockaddr_storage
%11 = alloca i32
%12 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %10, i64 0, i32 0
store i32 %7, i32* %12
%13 = tail call i32 @socket(i32 %1, i32 %2, i32 %3)
%14 = tail call i32 @bind(i32 %13, %struct.sockaddr* %4, i32 %5)
%15 = tail call i32 @listen(i32 %13, i32 %6)
store i32 4, i32* %11
%16 = bitcast %struct.sockaddr_storage* %10 to %struct.sockaddr*
%17 = call i32 @accept(i32 %13, %struct.sockaddr* %16, i32* %11)
ret i32 %17
}