#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 */

/* Variables and functions */
int /*<<< orphan*/ ipv4_from_asc(unsigned char *, char const *);
int /*<<< orphan*/ ipv6_from_asc(unsigned char *, char const *);
scalar_t__ strchr(char const *, char);
int a2i_ipadd(unsigned char *ipout, const char *ipasc) {
  if (strchr(ipasc, ':')) {
    if (!ipv6_from_asc(ipout, ipasc))
      return 0;
    return 16;
  } else {
    if (!ipv4_from_asc(ipout, ipasc))
      return 0;
    return 4;
  }
}


x86 assembly (clang, -O0):
<a2i_ipadd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1186 <a2i_ipadd+0x56>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <ipv6_from_asc@plt>
cmp    $0x0,%eax
jne    117a <a2i_ipadd+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    11af <a2i_ipadd+0x7f>
movl   $0x10,-0x4(%rbp)
jmp    11af <a2i_ipadd+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <ipv4_from_asc@plt>
cmp    $0x0,%eax
jne    11a8 <a2i_ipadd+0x78>
movl   $0x0,-0x4(%rbp)
jmp    11af <a2i_ipadd+0x7f>
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a2i_ipadd>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
test   %rax,%rax
je     115e <a2i_ipadd+0x2e>
call   1050 <ipv6_from_asc@plt>
mov    $0x10,%ecx
jmp    1168 <a2i_ipadd+0x38>
call   1030 <ipv4_from_asc@plt>
mov    $0x4,%ecx
test   %eax,%eax
cmove  %eax,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @a2i_ipadd(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = call i64 @strchr(i8* %6, i8 signext 58)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i32 @ipv6_from_asc(i8* %10, i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %9
store i32 0, i32* %3
br label %23
15: ; preds = %9
store i32 16, i32* %3
br label %23
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i32 @ipv4_from_asc(i8* %17, i8* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %16
store i32 0, i32* %3
br label %23
22: ; preds = %16
store i32 4, i32* %3
br label %23
23: ; preds = %22, %21, %15, %14
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @a2i_ipadd(i8* %0, i8* %1) {
%3 = tail call i64 @strchr(i8* %1, i8 signext 58)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @ipv6_from_asc(i8* %0, i8* %1)
br label %9
7: ; preds = %2
%8 = tail call i32 @ipv4_from_asc(i8* %0, i8* %1)
br label %9
9: ; preds = %7, %5
%10 = phi i32 [ %8, %7 ], [ %6, %5 ]
%11 = phi i32 [ 4, %7 ], [ 16, %5 ]
%12 = icmp eq i32 %10, 0
%13 = select i1 %12, i32 0, i32 %11
ret i32 %13
}