#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 /*<<< orphan*/ socklen_t;

/* Variables and functions */
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int listen(int, int const);
int tlisten_accept_a(int sockfd, const int BACKLOG,
                     struct sockaddr_storage *addr, socklen_t *addr_size) {
  int retfd;
  if (listen(sockfd, BACKLOG) == -1) {
    return -1;
  }
  if ((retfd = accept(sockfd, (struct sockaddr *)addr, addr_size)) == -1) {
    return -2;
  }
  return retfd;
}


x86 assembly (clang, -O0):
<tlisten_accept_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <listen@plt>
cmp    $0xffffffff,%eax
jne    1156 <tlisten_accept_a+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <tlisten_accept_a+0x64>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    117e <tlisten_accept_a+0x5e>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1184 <tlisten_accept_a+0x64>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tlisten_accept_a>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %edi,%ebp
call   1030 <listen@plt>
cmp    $0xffffffff,%eax
je     1152 <tlisten_accept_a+0x32>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <accept@plt>
mov    %eax,%ecx
cmp    $0xffffffff,%eax
mov    $0xfffffffe,%eax
cmovne %ecx,%eax
jmp    1157 <tlisten_accept_a+0x37>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @tlisten_accept_a(i32 %0, i32 %1, %struct.sockaddr_storage* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_storage*
%9 = alloca i32*
%10 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store %struct.sockaddr_storage* %2, %struct.sockaddr_storage** %8
store i32* %3, i32** %9
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = call i32 @listen(i32 %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 -1, i32* %5
br label %26
16: ; preds = %4
%17 = load i32, i32* %6
%18 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %8
%19 = bitcast %struct.sockaddr_storage* %18 to %struct.sockaddr*
%20 = load i32*, i32** %9
%21 = call i32 @accept(i32 %17, %struct.sockaddr* %19, i32* %20)
store i32 %21, i32* %10
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 -2, i32* %5
br label %26
24: ; preds = %16
%25 = load i32, i32* %10
store i32 %25, i32* %5
br label %26
26: ; preds = %24, %23, %15
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @tlisten_accept_a(i32 %0, i32 %1, %struct.sockaddr_storage* %2, i32* %3) {
%5 = tail call i32 @listen(i32 %0, i32 %1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = bitcast %struct.sockaddr_storage* %2 to %struct.sockaddr*
%9 = tail call i32 @accept(i32 %0, %struct.sockaddr* %8, i32* %3)
%10 = icmp eq i32 %9, -1
%11 = select i1 %10, i32 -2, i32 %9
br label %12
12: ; preds = %7, %4
%13 = phi i32 [ -1, %4 ], [ %11, %7 ]
ret i32 %13
}