#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 sockaddr_in6 {
  int sin6_family;
  scalar_t__ sin6_scope_id;
  scalar_t__ sin6_flowinfo;
  scalar_t__ sin6_port;
  int /*<<< orphan*/ sin6_addr;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int sin_family;
  scalar_t__ sin_port;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int AF_INET;
int AF_INET6;
int /*<<< orphan*/ INADDR_ANY;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ in6addr_any;
int bindAny(int s, int domain) {
  int result = -1;
  if (domain == AF_INET) {
    struct sockaddr_in addr;
    addr.sin_addr.s_addr = INADDR_ANY;
    addr.sin_port = 0;
    addr.sin_family = domain;
    result = bind(s, (struct sockaddr *)&addr, sizeof(addr));
  } else if (domain == AF_INET6) {
    struct sockaddr_in6 addr;
    addr.sin6_addr = in6addr_any;
    addr.sin6_port = 0;
    addr.sin6_flowinfo = 0;
    addr.sin6_scope_id = 0;
    addr.sin6_family = domain;
    result = bind(s, (struct sockaddr *)&addr, sizeof(addr));
  }
  return result;
}


x86 assembly (clang, -O0):
<bindAny>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2eb1(%rip),%rcx
cmp    (%rcx),%eax
jne    116a <bindAny+0x5a>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1030 <bind@plt>
mov    %eax,-0xc(%rbp)
jmp    11bf <bindAny+0xaf>
mov    -0x8(%rbp),%eax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%eax
jne    11ba <bindAny+0xaa>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x28,%edx
call   1030 <bind@plt>
mov    %eax,-0xc(%rbp)
jmp    11bf <bindAny+0xaf>
mov    -0xc(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bindAny>:
sub    $0x28,%rsp
mov    0x2ec5(%rip),%rax
cmp    %esi,(%rax)
jne    1142 <bindAny+0x32>
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    %esi,(%rsp)
mov    %rsp,%rsi
mov    $0x18,%edx
jmp    117b <bindAny+0x6b>
mov    0x2e87(%rip),%rcx
mov    $0xffffffff,%eax
cmp    %esi,(%rcx)
jne    1180 <bindAny+0x70>
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
mov    %esi,(%rsp)
mov    %rsp,%rsi
mov    $0x28,%edx
call   1030 <bind@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i64, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32, i64, i64, i64, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@AF_INET6 = global i32 0
@in6addr_any = global i32 0
define i32 @bindAny(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in6
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 -1, i32* %5
%8 = load i32, i32* %4
%9 = load i32, i32* @AF_INET
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = load i32, i32* @INADDR_ANY
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
store i32 %12, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i64 0, i64* %15
%16 = load i32, i32* %4
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %3
%19 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%20 = call i32 @bind(i32 %18, %struct.sockaddr* %19, i32 24)
store i32 %20, i32* %5
br label %37
21: ; preds = %2
%22 = load i32, i32* %4
%23 = load i32, i32* @AF_INET6
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load i32, i32* @in6addr_any
%27 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %7, i32 0, i32 4
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %7, i32 0, i32 3
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %7, i32 0, i32 2
store i64 0, i64* %29
%30 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %7, i32 0, i32 1
store i64 0, i64* %30
%31 = load i32, i32* %4
%32 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %7, i32 0, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* %3
%34 = bitcast %struct.sockaddr_in6* %7 to %struct.sockaddr*
%35 = call i32 @bind(i32 %33, %struct.sockaddr* %34, i32 40)
store i32 %35, i32* %5
br label %36
36: ; preds = %25, %21
br label %37
37: ; preds = %36, %11
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i64, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { i32, i64, i64, i64, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@AF_INET6 = global i32 0
@in6addr_any = global i32 0
define i32 @bindAny(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in6
%5 = load i32, i32* @AF_INET
%6 = icmp eq i32 %5, %1
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = load i32, i32* @INADDR_ANY
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %1, i32* %12
%13 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%14 = call i32 @bind(i32 %0, %struct.sockaddr* %13, i32 24)
br label %27
15: ; preds = %2
%16 = load i32, i32* @AF_INET6
%17 = icmp eq i32 %16, %1
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = bitcast %struct.sockaddr_in6* %4 to i8*
%20 = load i32, i32* @in6addr_any
%21 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 4
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 1
%23 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 0
%24 = bitcast i64* %22 to i8*
store i32 %1, i32* %23
%25 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%26 = call i32 @bind(i32 %0, %struct.sockaddr* %25, i32 40)
br label %27
27: ; preds = %15, %18, %7
%28 = phi i32 [ %14, %7 ], [ %26, %18 ], [ -1, %15 ]
ret i32 %28
}