#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 {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ dummy;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int sock_accept(int *server_fd, int *client_fd, struct sockaddr *addr) {
  struct sockaddr dummy;
  socklen_t len = sizeof(dummy);
  (*client_fd) = (addr ? (accept((*server_fd), addr, &len))
                       : (accept((*server_fd), &dummy, &len)));
  return (*client_fd);
}


x86 assembly (clang, -O0):
<sock_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1151 <sock_accept+0x41>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1030 <accept@plt>
mov    %eax,-0x28(%rbp)
jmp    1167 <sock_accept+0x57>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1030 <accept@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_accept>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x4,0x4(%rsp)
test   %rdx,%rdx
mov    (%rdi),%edi
lea    0x8(%rsp),%rsi
cmovne %rdx,%rsi
lea    0x4(%rsp),%rdx
call   1030 <accept@plt>
mov    %eax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
define i32 @sock_accept(i32* %0, i32* %1, %struct.sockaddr* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca %struct.sockaddr*
%7 = alloca %struct.sockaddr
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store %struct.sockaddr* %2, %struct.sockaddr** %6
store i32 4, i32* %8
%9 = load %struct.sockaddr*, %struct.sockaddr** %6
%10 = icmp ne %struct.sockaddr* %9, null
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %12
%14 = load %struct.sockaddr*, %struct.sockaddr** %6
%15 = call i32 @accept(i32 %13, %struct.sockaddr* %14, i32* %8)
br label %20
16: ; preds = %3
%17 = load i32*, i32** %4
%18 = load i32, i32* %17
%19 = call i32 @accept(i32 %18, %struct.sockaddr* %7, i32* %8)
br label %20
20: ; preds = %16, %11
%21 = phi i32 [ %15, %11 ], [ %19, %16 ]
%22 = load i32*, i32** %5
store i32 %21, i32* %22
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define i32 @sock_accept(i32* nocapture %0, i32* nocapture writeonly %1, %struct.sockaddr* %2) {
%4 = alloca %struct.sockaddr
%5 = alloca i32
%6 = bitcast %struct.sockaddr* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%8 = icmp eq %struct.sockaddr* %2, null
%9 = load i32, i32* %0
%10 = select i1 %8, %struct.sockaddr* %4, %struct.sockaddr* %2
%11 = call i32 @accept(i32 %9, %struct.sockaddr* %10, i32* %5)
store i32 %11, i32* %1
ret i32 %11
}