#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_in6 {
  int /*<<< orphan*/ sin_addr;
  void *sin_port;
  void *sin_family;
  int /*<<< orphan*/ sin6_addr;
  void *sin6_port;
  void *sin6_family;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  void *sin_port;
  void *sin_family;
  int /*<<< orphan*/ sin6_addr;
  void *sin6_port;
  void *sin6_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ enable;
typedef int /*<<< orphan*/ disable;
typedef int /*<<< orphan*/ address_ipv6;
typedef int /*<<< orphan*/ address_ipv4;

/* Variables and functions */
void *AF_INET;
void *AF_INET6;
scalar_t__ EADDRINUSE;
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_V6ONLY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *htons(int);
scalar_t__ inet_pton(void *, char *, int /*<<< orphan*/ *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int socket_ipv4;
  int socket_ipv6;
  int ret;
  if ((socket_ipv6 = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
    perror("socket(ipv6)");
    return 1;
  }
  if ((socket_ipv4 = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket(ipv4)");
    return 1;
  }
  int enable = 1;
  if (setsockopt(socket_ipv6, SOL_SOCKET, SO_REUSEADDR, &enable,
                 sizeof(enable)) < 0) {
    perror("setsockopt(ipv6, SO_REUSEADDR = 1)");
    return 1;
  }
  if (setsockopt(socket_ipv4, SOL_SOCKET, SO_REUSEADDR, &enable,
                 sizeof(enable)) < 0) {
    perror("setsockopt(ipv4, SO_REUSEADDR = 1)");
    return 1;
  }
  int disable = 0;
  if (setsockopt(socket_ipv6, IPPROTO_IPV6, IPV6_V6ONLY, &disable,
                 sizeof(disable)) < 0) {
    perror("setsockopt(IPV6_V6ONLY = 0)");
    return 1;
  }
  struct sockaddr_in6 address_ipv6;
  memset(&address_ipv6, 0, sizeof(address_ipv6));
  address_ipv6.sin6_family = AF_INET6;
  address_ipv6.sin6_port = htons(11112);
  if (inet_pton(AF_INET6, "::1/128", &address_ipv6.sin6_addr) < 0) {
    perror("inet_pton(ipv6)");
    return 1;
  }
  if (bind(socket_ipv6, (struct sockaddr *)&address_ipv6,
           sizeof(address_ipv6)) < 0) {
    perror("bind(ipv6)");
    return 1;
  }
  if (listen(socket_ipv6, 3) < 0) {
    perror("listen(ipv6)");
    return 1;
  }
  struct sockaddr_in address_ipv4;
  memset(&address_ipv4, 0, sizeof(address_ipv4));
  address_ipv4.sin_family = AF_INET;
  address_ipv4.sin_port = htons(11112);
  if (inet_pton(AF_INET, "127.0.0.1", &address_ipv4.sin_addr) < 0) {
    perror("inet_pton(ipv4)");
    return 1;
  }
  ret =
      bind(socket_ipv4, (struct sockaddr *)&address_ipv4, sizeof(address_ipv4));
  if (ret != -1 || errno != EADDRINUSE) {
    fprintf(stderr, "bind(ipv4) was successful even though there is no "
                    "IPV6_V6ONLY on same port\n");
    return 1;
  }
  puts("test completed successfully");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%rdi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11f7 <main+0x57>
lea    0xe1a(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
mov    0x2de2(%rip),%rax
mov    (%rax),%rdi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1235 <main+0x95>
lea    0xde9(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
movl   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1282 <main+0xe2>
lea    0xda9(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
mov    -0x14(%rbp),%edi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
mov    0x2d03(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    12c8 <main+0x128>
lea    0xd86(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2cc7(%rip),%rax
mov    (%rax),%esi
mov    0x2cd6(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1315 <main+0x175>
lea    0xd5c(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    $0x2b68,%edi
call   1050 <htons@plt>
mov    %rax,-0x38(%rbp)
mov    0x2c90(%rip),%rax
mov    (%rax),%rdi
lea    -0x58(%rbp),%rdx
add    $0x18,%rdx
lea    0xd22(%rip),%rsi
call   1080 <inet_pton@plt>
cmp    $0x0,%rax
jge    1381 <main+0x1e1>
lea    0xd14(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
mov    -0x18(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0x30,%edx
call   10a0 <bind@plt>
cmp    $0x0,%eax
jge    13b3 <main+0x213>
lea    0xcf2(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
mov    -0x18(%rbp),%edi
mov    $0x3,%esi
call   1090 <listen@plt>
cmp    $0x0,%rax
jge    13e2 <main+0x242>
lea    0xcce(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
lea    -0x88(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
mov    0x2be4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x78(%rbp)
mov    $0x2b68,%edi
call   1050 <htons@plt>
mov    %rax,-0x80(%rbp)
mov    0x2bc8(%rip),%rax
mov    (%rax),%rdi
lea    -0x88(%rbp),%rdx
lea    0xc83(%rip),%rsi
call   1080 <inet_pton@plt>
cmp    $0x0,%rax
jge    1450 <main+0x2b0>
lea    0xc77(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
mov    -0x14(%rbp),%edi
lea    -0x88(%rbp),%rsi
mov    $0x30,%edx
call   10a0 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    148b <main+0x2eb>
mov    0x2b30(%rip),%rax
mov    (%rax),%rax
mov    0x2b2e(%rip),%rcx
cmp    (%rcx),%rax
je     14ac <main+0x30c>
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
lea    0xc2b(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14bf <main+0x31f>
lea    0xc5f(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2e23(%rip),%r15
mov    (%r15),%rdi
mov    0x2e01(%rip),%rbx
mov    (%rbx),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     1386 <main+0x1e6>
mov    %eax,%ebp
mov    0x2e07(%rip),%r14
mov    (%r14),%rdi
mov    (%rbx),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     138f <main+0x1ef>
mov    %eax,%r12d
movl   $0x1,(%rsp)
mov    0x2dea(%rip),%r13
mov    0x0(%r13),%esi
mov    0x2d8f(%rip),%rbx
mov    (%rbx),%edx
mov    %rsp,%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     1398 <main+0x1f8>
mov    0x0(%r13),%esi
mov    (%rbx),%edx
mov    %rsp,%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     13a1 <main+0x201>
movl   $0x0,0x4(%rsp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
mov    0x2d5c(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     13aa <main+0x20a>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x30(%rsp)
mov    $0x2b68,%edi
call   1050 <htons@plt>
mov    %rax,0x28(%rsp)
mov    (%r15),%rdi
lea    0x20(%rsp),%rdx
lea    0xdcc(%rip),%rsi
call   1080 <inet_pton@plt>
test   %rax,%rax
js     13b3 <main+0x213>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x30,%edx
call   10a0 <bind@plt>
test   %eax,%eax
js     13bc <main+0x21c>
mov    %ebp,%edi
mov    $0x3,%esi
call   1090 <listen@plt>
test   %rax,%rax
js     13c5 <main+0x225>
lea    0x38(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
mov    (%r14),%rax
mov    %rax,0x48(%rsp)
mov    $0x2b68,%edi
call   1050 <htons@plt>
mov    %rax,0x40(%rsp)
mov    (%r14),%rdi
lea    0xd8b(%rip),%rsi
mov    %rbp,%rdx
call   1080 <inet_pton@plt>
test   %rax,%rax
js     13ce <main+0x22e>
lea    0x38(%rsp),%rsi
mov    %r12d,%edi
mov    $0x30,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    136f <main+0x1cf>
mov    0x2c58(%rip),%rax
mov    (%rax),%rax
mov    0x2c56(%rip),%rcx
cmp    (%rcx),%rax
jne    136f <main+0x1cf>
lea    0xdac(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    13df <main+0x23f>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%rsi
call   1070 <fprintf@plt>
jmp    13da <main+0x23a>
lea    0xc73(%rip),%rdi
jmp    13d5 <main+0x235>
lea    0xc77(%rip),%rdi
jmp    13d5 <main+0x235>
lea    0xc7b(%rip),%rdi
jmp    13d5 <main+0x235>
lea    0xc95(%rip),%rdi
jmp    13d5 <main+0x235>
lea    0xcaf(%rip),%rdi
jmp    13d5 <main+0x235>
lea    0xcca(%rip),%rdi
jmp    13d5 <main+0x235>
lea    0xcd1(%rip),%rdi
jmp    13d5 <main+0x235>
lea    0xcd3(%rip),%rdi
jmp    13d5 <main+0x235>
lea    0xce1(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i8*, i8*, i32, i8*, i8* }
%struct.sockaddr_in = type { i32, i8*, i8*, i32, i8*, i8* }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i8* null
@SOCK_STREAM = global i32 0
@.str = [13 x i8] c"socket(ipv6)\00"
@AF_INET = global i8* null
@.str.1 = [13 x i8] c"socket(ipv4)\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [35 x i8] c"setsockopt(ipv6, SO_REUSEADDR = 1)\00"
@.str.3 = [35 x i8] c"setsockopt(ipv4, SO_REUSEADDR = 1)\00"
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
@.str.4 = [28 x i8] c"setsockopt(IPV6_V6ONLY = 0)\00"
@.str.5 = [8 x i8] c"::1/128\00"
@.str.6 = [16 x i8] c"inet_pton(ipv6)\00"
@.str.7 = [11 x i8] c"bind(ipv6)\00"
@.str.8 = [13 x i8] c"listen(ipv6)\00"
@.str.9 = [10 x i8] c"127.0.0.1\00"
@.str.10 = [16 x i8] c"inet_pton(ipv4)\00"
@errno = global i64 0
@EADDRINUSE = global i64 0
@stderr = global i32 0
@.str.11 = [76 x i8] c"bind(ipv4) was successful even though there is no IPV6_V6ONLY on same port\0A\00"
@.str.12 = [28 x i8] c"test completed successfully\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in6
%12 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8*, i8** @AF_INET6
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i8* %13, i32 %14, i32 0)
store i32 %15, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %103
19: ; preds = %2
%20 = load i8*, i8** @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i8* %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %103
26: ; preds = %19
store i32 1, i32* %9
%27 = load i32, i32* %7
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_REUSEADDR
%30 = call i64 @setsockopt(i32 %27, i32 %28, i32 %29, i32* %9, i32 4)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %103
34: ; preds = %26
%35 = load i32, i32* %6
%36 = load i32, i32* @SOL_SOCKET
%37 = load i32, i32* @SO_REUSEADDR
%38 = call i64 @setsockopt(i32 %35, i32 %36, i32 %37, i32* %9, i32 4)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %103
42: ; preds = %34
store i32 0, i32* %10
%43 = load i32, i32* %7
%44 = load i32, i32* @IPPROTO_IPV6
%45 = load i32, i32* @IPV6_V6ONLY
%46 = call i64 @setsockopt(i32 %43, i32 %44, i32 %45, i32* %10, i32 4)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %103
50: ; preds = %42
%51 = call i32 @memset(%struct.sockaddr_in6* %11, i32 0, i32 48)
%52 = load i8*, i8** @AF_INET6
%53 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 5
store i8* %52, i8** %53
%54 = call i8* @htons(i32 11112)
%55 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 4
store i8* %54, i8** %55
%56 = load i8*, i8** @AF_INET6
%57 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 3
%58 = call i64 @inet_pton(i8* %56, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32* %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %50
%61 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %103
62: ; preds = %50
%63 = load i32, i32* %7
%64 = bitcast %struct.sockaddr_in6* %11 to %struct.sockaddr*
%65 = call i32 @bind(i32 %63, %struct.sockaddr* %64, i32 48)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %103
69: ; preds = %62
%70 = load i32, i32* %7
%71 = call i64 @listen(i32 %70, i32 3)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %69
%74 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %103
75: ; preds = %69
%76 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr_in6*
%77 = call i32 @memset(%struct.sockaddr_in6* %76, i32 0, i32 48)
%78 = load i8*, i8** @AF_INET
%79 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i8* %78, i8** %79
%80 = call i8* @htons(i32 11112)
%81 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i8* %80, i8** %81
%82 = load i8*, i8** @AF_INET
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%84 = call i64 @inet_pton(i8* %82, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32* %83)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %75
%87 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %103
88: ; preds = %75
%89 = load i32, i32* %6
%90 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%91 = call i32 @bind(i32 %89, %struct.sockaddr* %90, i32 48)
store i32 %91, i32* %8
%92 = load i32, i32* %8
%93 = icmp ne i32 %92, -1
br i1 %93, label %98, label %94
94: ; preds = %88
%95 = load i64, i64* @errno
%96 = load i64, i64* @EADDRINUSE
%97 = icmp ne i64 %95, %96
br i1 %97, label %98, label %101
98: ; preds = %94, %88
%99 = load i32, i32* @stderr
%100 = call i32 @fprintf(i32 %99, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %3
br label %103
101: ; preds = %94
%102 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %3
br label %103
103: ; preds = %101, %98, %86, %73, %67, %60, %48, %40, %32, %24, %17
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i8*, i8*, i32, i8*, i8* }
%struct.sockaddr_in = type { i32, i8*, i8*, i32, i8*, i8* }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i8* null
@SOCK_STREAM = global i32 0
@.str = [13 x i8] c"socket(ipv6)\00"
@AF_INET = global i8* null
@.str.1 = [13 x i8] c"socket(ipv4)\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [35 x i8] c"setsockopt(ipv6, SO_REUSEADDR = 1)\00"
@.str.3 = [35 x i8] c"setsockopt(ipv4, SO_REUSEADDR = 1)\00"
@IPPROTO_IPV6 = global i32 0
@IPV6_V6ONLY = global i32 0
@.str.4 = [28 x i8] c"setsockopt(IPV6_V6ONLY = 0)\00"
@.str.5 = [8 x i8] c"::1/128\00"
@.str.6 = [16 x i8] c"inet_pton(ipv6)\00"
@.str.7 = [11 x i8] c"bind(ipv6)\00"
@.str.8 = [13 x i8] c"listen(ipv6)\00"
@.str.9 = [10 x i8] c"127.0.0.1\00"
@.str.10 = [16 x i8] c"inet_pton(ipv4)\00"
@errno = global i64 0
@EADDRINUSE = global i64 0
@stderr = global i32 0
@.str.11 = [76 x i8] c"bind(ipv4) was successful even though there is no IPV6_V6ONLY on same port\0A\00"
@.str.12 = [28 x i8] c"test completed successfully\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in6
%6 = alloca %struct.sockaddr_in
%7 = load i8*, i8** @AF_INET6
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i8* %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %102
13: ; preds = %2
%14 = load i8*, i8** @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i8* %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %102
20: ; preds = %13
%21 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = call i64 @setsockopt(i32 %9, i32 %22, i32 %23, i32* %3, i32 4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %100
28: ; preds = %20
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_REUSEADDR
%31 = call i64 @setsockopt(i32 %16, i32 %29, i32 %30, i32* %3, i32 4)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %100
35: ; preds = %28
%36 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%37 = load i32, i32* @IPPROTO_IPV6
%38 = load i32, i32* @IPV6_V6ONLY
%39 = call i64 @setsockopt(i32 %9, i32 %37, i32 %38, i32* %4, i32 4)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %98
43: ; preds = %35
%44 = bitcast %struct.sockaddr_in6* %5 to i8*
%45 = call i32 @memset(%struct.sockaddr_in6* %5, i32 0, i32 48)
%46 = load i8*, i8** @AF_INET6
%47 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i64 0, i32 5
store i8* %46, i8** %47
%48 = call i8* @htons(i32 11112)
%49 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i64 0, i32 4
store i8* %48, i8** %49
%50 = load i8*, i8** @AF_INET6
%51 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i64 0, i32 3
%52 = call i64 @inet_pton(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32* %51)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %43
%55 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %96
56: ; preds = %43
%57 = bitcast %struct.sockaddr_in6* %5 to %struct.sockaddr*
%58 = call i32 @bind(i32 %9, %struct.sockaddr* %57, i32 48)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %96
62: ; preds = %56
%63 = call i64 @listen(i32 %9, i32 3)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %96
67: ; preds = %62
%68 = bitcast %struct.sockaddr_in* %6 to i8*
%69 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr_in6*
%70 = call i32 @memset(%struct.sockaddr_in6* %69, i32 0, i32 48)
%71 = load i8*, i8** @AF_INET
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i8* %71, i8** %72
%73 = call i8* @htons(i32 11112)
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i8* %73, i8** %74
%75 = load i8*, i8** @AF_INET
%76 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
%77 = call i64 @inet_pton(i8* %75, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32* %76)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %67
%80 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %94
81: ; preds = %67
%82 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%83 = call i32 @bind(i32 %16, %struct.sockaddr* %82, i32 48)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %89
85: ; preds = %81
%86 = load i64, i64* @errno
%87 = load i64, i64* @EADDRINUSE
%88 = icmp eq i64 %86, %87
br i1 %88, label %92, label %89
89: ; preds = %85, %81
%90 = load i32, i32* @stderr
%91 = call i32 @fprintf(i32 %90, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.11, i64 0, i64 0))
br label %94
92: ; preds = %85
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0))
br label %94
94: ; preds = %92, %89, %79
%95 = phi i32 [ 1, %79 ], [ 1, %89 ], [ 0, %92 ]
br label %96
96: ; preds = %94, %65, %60, %54
%97 = phi i32 [ 1, %54 ], [ 1, %60 ], [ 1, %65 ], [ %95, %94 ]
br label %98
98: ; preds = %96, %41
%99 = phi i32 [ 1, %41 ], [ %97, %96 ]
br label %100
100: ; preds = %98, %33, %26
%101 = phi i32 [ 1, %26 ], [ 1, %33 ], [ %99, %98 ]
br label %102
102: ; preds = %100, %18, %11
%103 = phi i32 [ 1, %11 ], [ 1, %18 ], [ %101, %100 ]
ret i32 %103
}