#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s6_addr;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
  TYPE_1__ sin6_addr;
  int /*<<< orphan*/ sin6_family;
};
struct sockaddr {
  int dummy;
};
struct in6_addr {
  int dummy;
};
typedef int /*<<< orphan*/ on;
typedef int /*<<< orphan*/ in6addr_any;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ FIONBIO;
struct in6_addr IN6ADDR_ANY_INIT;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int ioctl(int, int /*<<< orphan*/, char *);
int listen(int, int);
int /*<<< orphan*/ memcpy(void *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int lissen(struct sockaddr_in6 addr, int port) {
  int s = socket(AF_INET6, SOCK_STREAM, 0);
  int rc, on = 1;
  const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
  if (s < 0) {
    perror("socket() failed");
    exit(-1);
  }
  rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on));
  if (rc < 0) {
    perror("setsockopt() failed");
    close(s);
    exit(-1);
  }
  rc = ioctl(s, FIONBIO, (char *)&on);
  if (rc < 0) {
    perror("ioctl() failed");
    close(s);
    exit(-1);
  }
  memset(&addr, 0, sizeof(addr));
  addr.sin6_family = AF_INET6;
  memcpy((void *)&in6addr_any, &addr.sin6_addr.s6_addr, sizeof(in6addr_any));
  addr.sin6_port = htons(port);
  rc = bind(s, (struct sockaddr *)&addr, sizeof(addr));
  if (rc < 0) {
    perror("bind() failed");
    close(s);
    exit(-1);
  }
  rc = listen(s, 32);
  if (rc < 0) {
    perror("listen() failed");
    close(s);
    exit(-1);
  }
  return s;
}


x86 assembly (clang, -O0):
<lissen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x20(%rbp)
mov    %esi,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    %edx,-0x24(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x30(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    121f <lissen+0x6f>
lea    0xdf0(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    126e <lissen+0xbe>
lea    0xdb9(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%edi
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    12ae <lissen+0xfe>
lea    0xd8d(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
lea    -0x38(%rbp),%rdi
lea    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
mov    -0x24(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1327 <lissen+0x177>
lea    0xd23(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%edi
mov    $0x20,%esi
call   1090 <listen@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    135f <lissen+0x1af>
lea    0xcf9(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lissen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %rdi,0x18(%rsp)
mov    %esi,0x20(%rsp)
mov    0x2e13(%rip),%r15
mov    (%r15),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
test   %ebx,%ebx
js     12b3 <lissen+0x103>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     12c9 <lissen+0x119>
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1060 <ioctl@plt>
test   %eax,%eax
js     12d2 <lissen+0x122>
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x20(%rsp)
lea    0x1c(%rsp),%rsi
lea    0x10(%rsp),%rdi
mov    $0x4,%edx
call   1080 <memcpy@plt>
mov    %r14d,%edi
call   1040 <htons@plt>
mov    %eax,0x18(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %eax,%eax
js     12db <lissen+0x12b>
mov    %ebx,%edi
mov    $0x20,%esi
call   1090 <listen@plt>
test   %eax,%eax
js     12e4 <lissen+0x134>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd46(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    0xd40(%rip),%rdi
jmp    12eb <lissen+0x13b>
lea    0xd4b(%rip),%rdi
jmp    12eb <lissen+0x13b>
lea    0xd51(%rip),%rdi
jmp    12eb <lissen+0x13b>
lea    0xd56(%rip),%rdi
call   10b0 <perror@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
%struct.sockaddr_in6 = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@IN6ADDR_ANY_INIT = global %struct.in6_addr zeroinitializer
@.str = [16 x i8] c"socket() failed\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [20 x i8] c"setsockopt() failed\00"
@FIONBIO = global i32 0
@.str.2 = [15 x i8] c"ioctl() failed\00"
@.str.3 = [14 x i8] c"bind() failed\00"
@.str.4 = [16 x i8] c"listen() failed\00"
define i32 @lissen(i64 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_in6
%5 = alloca { i64, i32 }
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.in6_addr
%11 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %5, i32 0, i32 0
store i64 %0, i64* %11
%12 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %5, i32 0, i32 1
store i32 %1, i32* %12
%13 = bitcast %struct.sockaddr_in6* %4 to i8*
%14 = bitcast { i64, i32 }* %5 to i8*
store i32 %2, i32* %6
%15 = load i32, i32* @AF_INET6
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %7
store i32 1, i32* %9
%18 = bitcast %struct.in6_addr* %10 to i8*
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %3
%22 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %3
%25 = load i32, i32* %7
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_REUSEADDR
%28 = bitcast i32* %9 to i8*
%29 = call i32 @setsockopt(i32 %25, i32 %26, i32 %27, i8* %28, i32 4)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %24
%33 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %7
%35 = call i32 @close(i32 %34)
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %24
%38 = load i32, i32* %7
%39 = load i32, i32* @FIONBIO
%40 = bitcast i32* %9 to i8*
%41 = call i32 @ioctl(i32 %38, i32 %39, i8* %40)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %37
%45 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %37
%50 = call i32 @memset(%struct.sockaddr_in6* %4, i32 0, i32 12)
%51 = load i32, i32* @AF_INET6
%52 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i32 0, i32 2
store i32 %51, i32* %52
%53 = bitcast %struct.in6_addr* %10 to i8*
%54 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i32 0, i32 1
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
%56 = call i32 @memcpy(i8* %53, i32* %55, i32 4)
%57 = load i32, i32* %6
%58 = call i32 @htons(i32 %57)
%59 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i32 0, i32 0
store i32 %58, i32* %59
%60 = load i32, i32* %7
%61 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%62 = call i32 @bind(i32 %60, %struct.sockaddr* %61, i32 12)
store i32 %62, i32* %8
%63 = load i32, i32* %8
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %49
%66 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%67 = load i32, i32* %7
%68 = call i32 @close(i32 %67)
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %49
%71 = load i32, i32* %7
%72 = call i32 @listen(i32 %71, i32 32)
store i32 %72, i32* %8
%73 = load i32, i32* %8
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %80
75: ; preds = %70
%76 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%77 = load i32, i32* %7
%78 = call i32 @close(i32 %77)
%79 = call i32 @exit(i32 -1)
unreachable
80: ; preds = %70
%81 = load i32, i32* %7
ret i32 %81
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
%struct.sockaddr_in6 = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@SOCK_STREAM = global i32 0
@IN6ADDR_ANY_INIT = global %struct.in6_addr zeroinitializer
@.str = [16 x i8] c"socket() failed\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [20 x i8] c"setsockopt() failed\00"
@FIONBIO = global i32 0
@.str.2 = [15 x i8] c"ioctl() failed\00"
@.str.3 = [14 x i8] c"bind() failed\00"
@.str.4 = [16 x i8] c"listen() failed\00"
define i32 @lissen(i64 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_in6
%5 = alloca i32
%6 = alloca %struct.in6_addr
%7 = bitcast %struct.sockaddr_in6* %4 to i64*
store i64 %0, i64* %7
%8 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 2
store i32 %1, i32* %8
%9 = load i32, i32* @AF_INET6
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%13 = bitcast %struct.in6_addr* %6 to i8*
%14 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %6, i64 0, i32 0
%15 = load i32, i32* getelementptr inbounds (%struct.in6_addr, %struct.in6_addr* @IN6ADDR_ANY_INIT, i64 0, i32 0)
store i32 %15, i32* %14
%16 = icmp slt i32 %11, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %3
%21 = load i32, i32* @SOL_SOCKET
%22 = load i32, i32* @SO_REUSEADDR
%23 = call i32 @setsockopt(i32 %11, i32 %21, i32 %22, i8* %12, i32 4)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @close(i32 %11)
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %20
%30 = load i32, i32* @FIONBIO
%31 = call i32 @ioctl(i32 %11, i32 %30, i8* %12)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @close(i32 %11)
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %29
%38 = call i32 @memset(%struct.sockaddr_in6* %4, i32 0, i32 12)
%39 = load i32, i32* @AF_INET6
store i32 %39, i32* %8
%40 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 1, i32 0
%41 = call i32 @memcpy(i8* %13, i32* %40, i32 4)
%42 = call i32 @htons(i32 %2)
%43 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 0
store i32 %42, i32* %43
%44 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%45 = call i32 @bind(i32 %11, %struct.sockaddr* %44, i32 12)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %37
%48 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @close(i32 %11)
%50 = call i32 @exit(i32 -1)
unreachable
51: ; preds = %37
%52 = call i32 @listen(i32 %11, i32 32)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @close(i32 %11)
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %51
ret i32 %11
}