#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
scalar_t__ listen(int, int);
int socket(int, int, int);
scalar_t__ socket_get_backlog(int, int *, char const *, char const *, char *);
int /*<<< orphan*/ warn(char *, char const *, char const *, ...);
int /*<<< orphan*/ warnx(char *, char const *, char const *, int, int);
int socket_listen(int domain, int type, int protocol, int backlog,
                  int create_backlog_assertion, int listen_backlog_assertion,
                  int *sockp, const char *domainstring, const char *typestring,
                  const char *testclass, const char *test) {
  int backlog_retrieved, sock;
  sock = socket(domain, type, protocol);
  if (sock < 0) {
    warn("%s: %s: socket_listen: socket(%s, %s)", testclass, test, domainstring,
         typestring);
    close(sock);
    return (-1);
  }
  if (socket_get_backlog(sock, &backlog_retrieved, testclass, test,
                         "socket_listen") < 0) {
    close(sock);
    return (-1);
  }
  if (backlog_retrieved != create_backlog_assertion) {
    warnx("%s: %s: socket_listen: create backlog is %d not %d", testclass, test,
          backlog_retrieved, create_backlog_assertion);
    close(sock);
    return (-1);
  }
  if (listen(sock, backlog) < 0) {
    warn("%s: %s: socket_listen: listen(, %d)", testclass, test, backlog);
    close(sock);
    return (-1);
  }
  if (socket_get_backlog(sock, &backlog_retrieved, testclass, test,
                         "socket_listen") < 0) {
    close(sock);
    return (-1);
  }
  if (backlog_retrieved != listen_backlog_assertion) {
    warnx("%s: %s: socket_listen: listen backlog is %d not %d", testclass, test,
          backlog_retrieved, listen_backlog_assertion);
    close(sock);
    return (-1);
  }
  *sockp = sock;
  return (0);
}


x86 assembly (clang, -O0):
<socket_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1080 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11dd <socket_listen+0x7d>
mov    0x28(%rbp),%rsi
mov    0x30(%rbp),%rdx
mov    0x18(%rbp),%rcx
mov    0x20(%rbp),%r8
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <socket_listen+0x1b7>
mov    -0x24(%rbp),%edi
mov    0x28(%rbp),%rdx
mov    0x30(%rbp),%rcx
lea    -0x20(%rbp),%rsi
lea    0xe33(%rip),%r8
call   1040 <socket_get_backlog@plt>
cmp    $0x0,%rax
jge    1216 <socket_listen+0xb6>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <socket_listen+0x1b7>
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1251 <socket_listen+0xf1>
mov    0x28(%rbp),%rsi
mov    0x30(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xdfc(%rip),%rdi
call   1050 <warnx@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <socket_listen+0x1b7>
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
jge    1293 <socket_listen+0x133>
mov    0x28(%rbp),%rsi
mov    0x30(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <socket_listen+0x1b7>
mov    -0x24(%rbp),%edi
mov    0x28(%rbp),%rdx
mov    0x30(%rbp),%rcx
lea    -0x20(%rbp),%rsi
lea    0xd7d(%rip),%r8
call   1040 <socket_get_backlog@plt>
cmp    $0x0,%rax
jge    12cc <socket_listen+0x16c>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <socket_listen+0x1b7>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1307 <socket_listen+0x1a7>
mov    0x28(%rbp),%rsi
mov    0x30(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xd9d(%rip),%rdi
call   1050 <warnx@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <socket_listen+0x1b7>
mov    -0x24(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_listen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r12d
mov    %r8d,%ebp
mov    %ecx,%r13d
mov    0x60(%rsp),%r14
mov    0x58(%rsp),%r15
call   1080 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11f4 <socket_listen+0x94>
lea    0xe96(%rip),%r8
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <socket_get_backlog@plt>
test   %rax,%rax
js     1242 <socket_listen+0xe2>
mov    0x4(%rsp),%ecx
cmp    %ebp,%ecx
jne    1214 <socket_listen+0xb4>
mov    %ebx,%edi
mov    %r13d,%esi
call   1070 <listen@plt>
test   %rax,%rax
js     122b <socket_listen+0xcb>
lea    0xe5d(%rip),%r8
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <socket_get_backlog@plt>
test   %rax,%rax
js     1242 <socket_listen+0xe2>
mov    0x4(%rsp),%ecx
cmp    %r12d,%ecx
jne    125d <socket_listen+0xfd>
mov    0x40(%rsp),%rax
mov    %ebx,(%rax)
xor    %eax,%eax
jmp    124e <socket_listen+0xee>
mov    0x50(%rsp),%r8
mov    0x48(%rsp),%rcx
lea    0xdfb(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <warn@plt>
jmp    1242 <socket_listen+0xe2>
lea    0xe19(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %ebp,%r8d
call   1050 <warnx@plt>
jmp    1242 <socket_listen+0xe2>
lea    0xe35(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r13d,%ecx
xor    %eax,%eax
call   1030 <warn@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe27(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12d,%r8d
jmp    1224 <socket_listen+0xc4>

LLVM IR (-O0):
@.str = [38 x i8] c"%s: %s: socket_listen: socket(%s, %s)\00"
@.str.1 = [14 x i8] c"socket_listen\00"
@.str.2 = [51 x i8] c"%s: %s: socket_listen: create backlog is %d not %d\00"
@.str.3 = [36 x i8] c"%s: %s: socket_listen: listen(, %d)\00"
@.str.4 = [51 x i8] c"%s: %s: socket_listen: listen backlog is %d not %d\00"
define i32 @socket_listen(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32* %6, i8* %7, i8* %8, i8* %9, i8* %10) {
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32*
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i8*
%24 = alloca i32
%25 = alloca i32
store i32 %0, i32* %13
store i32 %1, i32* %14
store i32 %2, i32* %15
store i32 %3, i32* %16
store i32 %4, i32* %17
store i32 %5, i32* %18
store i32* %6, i32** %19
store i8* %7, i8** %20
store i8* %8, i8** %21
store i8* %9, i8** %22
store i8* %10, i8** %23
%26 = load i32, i32* %13
%27 = load i32, i32* %14
%28 = load i32, i32* %15
%29 = call i32 @socket(i32 %26, i32 %27, i32 %28)
store i32 %29, i32* %25
%30 = load i32, i32* %25
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %11
%33 = load i8*, i8** %22
%34 = load i8*, i8** %23
%35 = load i8*, i8** %20
%36 = load i8*, i8** %21
%37 = call i32 (i8*, i8*, i8*, ...) @warn(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %34, i8* %35, i8* %36)
%38 = load i32, i32* %25
%39 = call i32 @close(i32 %38)
store i32 -1, i32* %12
br label %97
40: ; preds = %11
%41 = load i32, i32* %25
%42 = load i8*, i8** %22
%43 = load i8*, i8** %23
%44 = call i64 @socket_get_backlog(i32 %41, i32* %24, i8* %42, i8* %43, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = load i32, i32* %25
%48 = call i32 @close(i32 %47)
store i32 -1, i32* %12
br label %97
49: ; preds = %40
%50 = load i32, i32* %24
%51 = load i32, i32* %17
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %61
53: ; preds = %49
%54 = load i8*, i8** %22
%55 = load i8*, i8** %23
%56 = load i32, i32* %24
%57 = load i32, i32* %17
%58 = call i32 @warnx(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %54, i8* %55, i32 %56, i32 %57)
%59 = load i32, i32* %25
%60 = call i32 @close(i32 %59)
store i32 -1, i32* %12
br label %97
61: ; preds = %49
%62 = load i32, i32* %25
%63 = load i32, i32* %16
%64 = call i64 @listen(i32 %62, i32 %63)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %73
66: ; preds = %61
%67 = load i8*, i8** %22
%68 = load i8*, i8** %23
%69 = load i32, i32* %16
%70 = call i32 (i8*, i8*, i8*, ...) @warn(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %67, i8* %68, i32 %69)
%71 = load i32, i32* %25
%72 = call i32 @close(i32 %71)
store i32 -1, i32* %12
br label %97
73: ; preds = %61
%74 = load i32, i32* %25
%75 = load i8*, i8** %22
%76 = load i8*, i8** %23
%77 = call i64 @socket_get_backlog(i32 %74, i32* %24, i8* %75, i8* %76, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %73
%80 = load i32, i32* %25
%81 = call i32 @close(i32 %80)
store i32 -1, i32* %12
br label %97
82: ; preds = %73
%83 = load i32, i32* %24
%84 = load i32, i32* %18
%85 = icmp ne i32 %83, %84
br i1 %85, label %86, label %94
86: ; preds = %82
%87 = load i8*, i8** %22
%88 = load i8*, i8** %23
%89 = load i32, i32* %24
%90 = load i32, i32* %18
%91 = call i32 @warnx(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %87, i8* %88, i32 %89, i32 %90)
%92 = load i32, i32* %25
%93 = call i32 @close(i32 %92)
store i32 -1, i32* %12
br label %97
94: ; preds = %82
%95 = load i32, i32* %25
%96 = load i32*, i32** %19
store i32 %95, i32* %96
store i32 0, i32* %12
br label %97
97: ; preds = %94, %86, %79, %66, %53, %46, %32
%98 = load i32, i32* %12
ret i32 %98
}

LLVM IR (-O2):
@.str = [38 x i8] c"%s: %s: socket_listen: socket(%s, %s)\00"
@.str.1 = [14 x i8] c"socket_listen\00"
@.str.2 = [51 x i8] c"%s: %s: socket_listen: create backlog is %d not %d\00"
@.str.3 = [36 x i8] c"%s: %s: socket_listen: listen(, %d)\00"
@.str.4 = [51 x i8] c"%s: %s: socket_listen: listen backlog is %d not %d\00"
define i32 @socket_listen(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32* nocapture writeonly %6, i8* %7, i8* %8, i8* %9, i8* %10) {
%12 = alloca i32
%13 = bitcast i32* %12 to i8*
%14 = tail call i32 @socket(i32 %0, i32 %1, i32 %2)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = tail call i32 (i8*, i8*, i8*, ...) @warn(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10, i8* %7, i8* %8)
%18 = tail call i32 @close(i32 %14)
br label %48
19: ; preds = %11
%20 = call i64 @socket_get_backlog(i32 %14, i32* %12, i8* %9, i8* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @close(i32 %14)
br label %48
24: ; preds = %19
%25 = load i32, i32* %12
%26 = icmp eq i32 %25, %4
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i32 @warnx(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %10, i32 %25, i32 %4)
%29 = call i32 @close(i32 %14)
br label %48
30: ; preds = %24
%31 = call i64 @listen(i32 %14, i32 %3)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i32 (i8*, i8*, i8*, ...) @warn(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %9, i8* %10, i32 %3)
%35 = call i32 @close(i32 %14)
br label %48
36: ; preds = %30
%37 = call i64 @socket_get_backlog(i32 %14, i32* %12, i8* %9, i8* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @close(i32 %14)
br label %48
41: ; preds = %36
%42 = load i32, i32* %12
%43 = icmp eq i32 %42, %5
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = call i32 @warnx(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %9, i8* %10, i32 %42, i32 %5)
%46 = call i32 @close(i32 %14)
br label %48
47: ; preds = %41
store i32 %14, i32* %6
br label %48
48: ; preds = %47, %44, %39, %33, %27, %22, %16
%49 = phi i32 [ -1, %16 ], [ -1, %22 ], [ -1, %27 ], [ -1, %33 ], [ -1, %39 ], [ -1, %44 ], [ 0, %47 ]
ret i32 %49
}