#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_family;
  int /*<<< orphan*/ sin6_addr;
  void *sin6_family;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  void *sin_family;
  int /*<<< orphan*/ sin6_addr;
  void *sin6_family;
};

/* Variables and functions */
void *AF_INET;
void *AF_INET6;
int /*<<< orphan*/ error_exit(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ gettext(char *);
int inet_pton(void *, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int, int);
char *strchr(char const *, char);
void parse_bind_to(const char *in, struct sockaddr_in *bind_to_4,
                   struct sockaddr_in6 *bind_to_6,
                   struct sockaddr_in **bind_to) {
  char *dummy = strchr(in, ':');
  if (dummy) {
    *bind_to = (struct sockaddr_in *)bind_to_6;
    memset(bind_to_6, 0x00, sizeof *bind_to_6);
    bind_to_6->sin6_family = AF_INET6;
    if (inet_pton(AF_INET6, in, &bind_to_6->sin6_addr) != 1)
      error_exit(gettext("cannot convert ip address '%s' (for -y)\n"), in);
  } else {
    *bind_to = (struct sockaddr_in *)bind_to_4;
    memset(bind_to_4, 0x00, sizeof *bind_to_4);
    bind_to_4->sin_family = AF_INET;
    if (inet_pton(AF_INET, in, &bind_to_4->sin_addr) != 1)
      error_exit(gettext("cannot convert ip address '%s' (for -y)\n"), in);
  }
}


x86 assembly (clang, -O0):
<parse_bind_to>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f2 <parse_bind_to+0xa2>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    0x2e27(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x10,%rdx
call   1070 <inet_pton@plt>
cmp    $0x1,%eax
je     11ed <parse_bind_to+0x9d>
lea    0xe23(%rip),%rdi
call   1030 <gettext@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
call   1060 <error_exit@plt>
jmp    125b <parse_bind_to+0x10b>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    0x2dc2(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <inet_pton@plt>
cmp    $0x1,%eax
je     1256 <parse_bind_to+0x106>
lea    0xdba(%rip),%rdi
call   1030 <gettext@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
call   1060 <error_exit@plt>
jmp    125b <parse_bind_to+0x10b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_bind_to>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a0 <parse_bind_to+0x50>
mov    %rbx,(%r12)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%rdi
mov    %rdi,0x18(%rbx)
add    $0x10,%rbx
mov    %r14,%rsi
mov    %rbx,%rdx
jmp    11c7 <parse_bind_to+0x77>
mov    %r15,(%r12)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rdi
mov    %rdi,0x8(%r15)
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <inet_pton@plt>
cmp    $0x1,%eax
jne    11dd <parse_bind_to+0x8d>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe1c(%rip),%rdi
call   1030 <gettext@plt>
mov    %eax,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <error_exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i8*, i32, i8* }
%struct.sockaddr_in6 = type { i32, i8*, i32, i8* }
@AF_INET6 = global i8* null
@.str = [41 x i8] c"cannot convert ip address '%s' (for -y)\0A\00"
@AF_INET = global i8* null
define void @parse_bind_to(i8* %0, %struct.sockaddr_in* %1, %struct.sockaddr_in6* %2, %struct.sockaddr_in** %3) {
%5 = alloca i8*
%6 = alloca %struct.sockaddr_in*
%7 = alloca %struct.sockaddr_in6*
%8 = alloca %struct.sockaddr_in**
%9 = alloca i8*
store i8* %0, i8** %5
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %6
store %struct.sockaddr_in6* %2, %struct.sockaddr_in6** %7
store %struct.sockaddr_in** %3, %struct.sockaddr_in*** %8
%10 = load i8*, i8** %5
%11 = call i8* @strchr(i8* %10, i8 signext 58)
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %34
14: ; preds = %4
%15 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%16 = bitcast %struct.sockaddr_in6* %15 to %struct.sockaddr_in*
%17 = load %struct.sockaddr_in**, %struct.sockaddr_in*** %8
store %struct.sockaddr_in* %16, %struct.sockaddr_in** %17
%18 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%19 = call i32 @memset(%struct.sockaddr_in6* %18, i32 0, i32 32)
%20 = load i8*, i8** @AF_INET6
%21 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%22 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %21, i32 0, i32 3
store i8* %20, i8** %22
%23 = load i8*, i8** @AF_INET6
%24 = load i8*, i8** %5
%25 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%26 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %25, i32 0, i32 2
%27 = call i32 @inet_pton(i8* %23, i8* %24, i32* %26)
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %14
%30 = call i32 @gettext(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%31 = load i8*, i8** %5
%32 = call i32 @error_exit(i32 %30, i8* %31)
br label %33
33: ; preds = %29, %14
br label %54
34: ; preds = %4
%35 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%36 = load %struct.sockaddr_in**, %struct.sockaddr_in*** %8
store %struct.sockaddr_in* %35, %struct.sockaddr_in** %36
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%38 = bitcast %struct.sockaddr_in* %37 to %struct.sockaddr_in6*
%39 = call i32 @memset(%struct.sockaddr_in6* %38, i32 0, i32 32)
%40 = load i8*, i8** @AF_INET
%41 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %41, i32 0, i32 1
store i8* %40, i8** %42
%43 = load i8*, i8** @AF_INET
%44 = load i8*, i8** %5
%45 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %45, i32 0, i32 0
%47 = call i32 @inet_pton(i8* %43, i8* %44, i32* %46)
%48 = icmp ne i32 %47, 1
br i1 %48, label %49, label %53
49: ; preds = %34
%50 = call i32 @gettext(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%51 = load i8*, i8** %5
%52 = call i32 @error_exit(i32 %50, i8* %51)
br label %53
53: ; preds = %49, %34
br label %54
54: ; preds = %53, %33
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i8*, i32, i8* }
%struct.sockaddr_in6 = type { i32, i8*, i32, i8* }
@AF_INET6 = global i8* null
@.str = [41 x i8] c"cannot convert ip address '%s' (for -y)\0A\00"
@AF_INET = global i8* null
define void @parse_bind_to(i8* %0, %struct.sockaddr_in* %1, %struct.sockaddr_in6* %2, %struct.sockaddr_in** nocapture writeonly %3) {
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%6 = icmp eq i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = bitcast %struct.sockaddr_in** %3 to %struct.sockaddr_in6**
store %struct.sockaddr_in6* %2, %struct.sockaddr_in6** %8
%9 = tail call i32 @memset(%struct.sockaddr_in6* %2, i32 0, i32 32)
%10 = load i8*, i8** @AF_INET6
%11 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %2, i64 0, i32 3
store i8* %10, i8** %11
%12 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %2, i64 0, i32 2
%13 = tail call i32 @inet_pton(i8* %10, i8* %0, i32* %12)
%14 = icmp eq i32 %13, 1
br i1 %14, label %26, label %23
15: ; preds = %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %3
%16 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr_in6*
%17 = tail call i32 @memset(%struct.sockaddr_in6* %16, i32 0, i32 32)
%18 = load i8*, i8** @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i8* %18, i8** %19
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%21 = tail call i32 @inet_pton(i8* %18, i8* %0, i32* %20)
%22 = icmp eq i32 %21, 1
br i1 %22, label %26, label %23
23: ; preds = %15, %7
%24 = tail call i32 @gettext(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @error_exit(i32 %24, i8* %0)
br label %26
26: ; preds = %23, %15, %7
ret void
}