#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*/ s_addr;
};
struct sockaddr_in6 {
  void *sin6_port;
  int /*<<< orphan*/ sin6_addr;
  void *sin6_family;
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr_in {
  void *sin6_port;
  int /*<<< orphan*/ sin6_addr;
  void *sin6_family;
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr6;
typedef int /*<<< orphan*/ addr4;

/* Variables and functions */
void *AF_INET;
void *AF_INET6;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
void *htons(int);
int /*<<< orphan*/ in6addr_any;
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int rc;
  int sock4 = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in addr4;
  memset(&addr4, 0, sizeof(struct sockaddr_in));
  addr4.sin_family = AF_INET;
  addr4.sin_addr.s_addr = INADDR_ANY;
  addr4.sin_port = htons(30000);
  rc = bind(sock4, (struct sockaddr *)&addr4, sizeof(addr4));
  if (rc != 0) {
    fprintf(stderr, "Bind on IPv4 socket to INADDR_ANY failed! errno = %d\n",
            errno);
    exit(1);
  }
  close(sock4);
  int sock6 = socket(AF_INET6, SOCK_STREAM, 0);
  struct sockaddr_in6 addr6;
  memset(&addr6, 0, sizeof(struct sockaddr_in6));
  addr6.sin6_family = AF_INET6;
  addr6.sin6_addr = in6addr_any;
  addr6.sin6_port = htons(30000);
  rc = bind(sock6, (struct sockaddr *)&addr6, sizeof(addr6));
  if (rc != 0) {
    fprintf(stderr, "Bind on IPv6 socket to in6addr_any failed! errno = %d\n",
            errno);
    exit(1);
  }
  close(sock6);
  printf("Tests passed!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%rdi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x18(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x7530,%edi
call   1030 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x30,%edx
call   1080 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1234 <main+0xb4>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
lea    0xddb(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%rdi
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    $0x7530,%edi
call   1030 <htons@plt>
mov    %rax,-0x80(%rbp)
mov    -0x4c(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x30,%edx
call   1080 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12d7 <main+0x157>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
mov    0x2cf1(%rip),%rax
mov    (%rax),%edx
lea    0xd6e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x4c(%rbp),%edi
call   1060 <close@plt>
lea    0xd87(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2e4e(%rip),%r12
mov    (%r12),%rdi
mov    0x2e1b(%rip),%r15
mov    (%r15),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
lea    0x38(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x60(%rsp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x58(%rsp)
mov    $0x7530,%edi
call   1040 <htons@plt>
mov    %rax,0x50(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x30,%edx
call   1080 <bind@plt>
test   %eax,%eax
jne    1284 <main+0x104>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2dc9(%rip),%r12
mov    (%r12),%rdi
mov    (%r15),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x18(%rsp)
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x7530,%edi
call   1040 <htons@plt>
mov    %rax,0x8(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x30,%edx
call   1080 <bind@plt>
test   %eax,%eax
jne    129f <main+0x11f>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xdfc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    0x2d1c(%rip),%rax
mov    (%rax),%edx
lea    0xd63(%rip),%rsi
jmp    12b8 <main+0x138>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%edx
lea    0xd7e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, i32, i8*, i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i8*, i32, i8*, i8*, %struct.TYPE_2__, i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@stderr = global i32 0
@.str = [54 x i8] c"Bind on IPv4 socket to INADDR_ANY failed! errno = %d\0A\00"
@errno = global i32 0
@AF_INET6 = global i8* null
@in6addr_any = global i32 0
@.str.1 = [55 x i8] c"Bind on IPv6 socket to in6addr_any failed! errno = %d\0A\00"
@.str.2 = [15 x i8] c"Tests passed!\0A\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 %struct.sockaddr_in
%9 = alloca i32
%10 = alloca %struct.sockaddr_in6
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8*, i8** @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i8* %11, i32 %12, i32 0)
store i32 %13, i32* %7
%14 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr_in6*
%15 = call i32 @memset(%struct.sockaddr_in6* %14, i32 0, i32 48)
%16 = load i8*, i8** @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 5
store i8* %16, i8** %17
%18 = load i32, i32* @INADDR_ANY
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 4
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = call i8* @htons(i32 30000)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 3
store i8* %21, i8** %22
%23 = load i32, i32* %7
%24 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%25 = call i32 @bind(i32 %23, %struct.sockaddr* %24, i32 48)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %2
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %2
%34 = load i32, i32* %7
%35 = call i32 @close(i32 %34)
%36 = load i8*, i8** @AF_INET6
%37 = load i32, i32* @SOCK_STREAM
%38 = call i32 @socket(i8* %36, i32 %37, i32 0)
store i32 %38, i32* %9
%39 = call i32 @memset(%struct.sockaddr_in6* %10, i32 0, i32 48)
%40 = load i8*, i8** @AF_INET6
%41 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 2
store i8* %40, i8** %41
%42 = load i32, i32* @in6addr_any
%43 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 1
store i32 %42, i32* %43
%44 = call i8* @htons(i32 30000)
%45 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %10, i32 0, i32 0
store i8* %44, i8** %45
%46 = load i32, i32* %9
%47 = bitcast %struct.sockaddr_in6* %10 to %struct.sockaddr*
%48 = call i32 @bind(i32 %46, %struct.sockaddr* %47, i32 48)
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %33
%52 = load i32, i32* @stderr
%53 = load i32, i32* @errno
%54 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %33
%57 = load i32, i32* %9
%58 = call i32 @close(i32 %57)
%59 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, i32, i8*, i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i8*, i32, i8*, i8*, %struct.TYPE_2__, i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@stderr = global i32 0
@.str = [54 x i8] c"Bind on IPv4 socket to INADDR_ANY failed! errno = %d\0A\00"
@errno = global i32 0
@AF_INET6 = global i8* null
@in6addr_any = global i32 0
@.str.1 = [55 x i8] c"Bind on IPv6 socket to in6addr_any failed! errno = %d\0A\00"
@str = [14 x i8] c"Tests passed!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in6
%5 = load i8*, i8** @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i8* %5, i32 %6, i32 0)
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr_in6*
%10 = call i32 @memset(%struct.sockaddr_in6* %9, i32 0, i32 48)
%11 = load i8*, i8** @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 5
store i8* %11, i8** %12
%13 = load i32, i32* @INADDR_ANY
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 4, i32 0
store i32 %13, i32* %14
%15 = call i8* @htons(i32 30000)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i8* %15, i8** %16
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%18 = call i32 @bind(i32 %7, %struct.sockaddr* %17, i32 48)
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = call i32 @close(i32 %7)
%27 = load i8*, i8** @AF_INET6
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i8* %27, i32 %28, i32 0)
%30 = bitcast %struct.sockaddr_in6* %4 to i8*
%31 = call i32 @memset(%struct.sockaddr_in6* %4, i32 0, i32 48)
%32 = load i8*, i8** @AF_INET6
%33 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 2
store i8* %32, i8** %33
%34 = load i32, i32* @in6addr_any
%35 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 1
store i32 %34, i32* %35
%36 = call i8* @htons(i32 30000)
%37 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 0
store i8* %36, i8** %37
%38 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%39 = call i32 @bind(i32 %29, %struct.sockaddr* %38, i32 48)
%40 = icmp eq i32 %39, 0
br i1 %40, label %46, label %41
41: ; preds = %25
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %25
%47 = call i32 @close(i32 %29)
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
ret i32 0
}