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

/* Variables and functions */
int bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int listen(int, int);
int tcpListen(char *err, int s, struct sockaddr *sa, socklen_t len) {
  if (bind(s, sa, len) == -1) {
    close(s);
    return -1;
  }
  if (listen(s, 511) == -1) {
    close(s);
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<tcpListen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <bind@plt>
cmp    $0xffffffff,%eax
jne    1172 <tcpListen+0x42>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <tcpListen+0x73>
mov    -0x14(%rbp),%edi
mov    $0x1ff,%esi
call   1040 <listen@plt>
cmp    $0xffffffff,%eax
jne    119c <tcpListen+0x6c>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <tcpListen+0x73>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcpListen>:
push   %rbx
mov    %esi,%ebx
mov    %esi,%edi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1050 <bind@plt>
cmp    $0xffffffff,%eax
je     115e <tcpListen+0x2e>
mov    %ebx,%edi
mov    $0x1ff,%esi
call   1040 <listen@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
je     115e <tcpListen+0x2e>
pop    %rbx
ret
mov    %ebx,%edi
call   1030 <close@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define i32 @tcpListen(i8* nocapture readnone %0, i32 %1, %struct.sockaddr* %2, i32 %3) {
%5 = tail call i32 @bind(i32 %1, %struct.sockaddr* %2, i32 %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @listen(i32 %1, i32 511)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7, %4
%11 = tail call i32 @close(i32 %1)
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ 1, %7 ], [ -1, %10 ]
ret i32 %13
}