#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 in6_addr {
  int /*<<< orphan*/ s6_addr;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int INET6_ADDRSTRLEN;
scalar_t__ IsAddressIPv4(char *);
int /*<<< orphan*/ in6addr_any;
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int ip6_atoi(struct in6_addr *ip, const char *addrString) {
  if (addrString == NULL || (strlen((char *)addrString) < 2)) {
    memcpy(ip->s6_addr, &in6addr_any, sizeof(struct in6_addr));
    return 1;
  } else if (IsAddressIPv4((char *)addrString)) {
    char buf[INET6_ADDRSTRLEN];
    strncpy(buf, (char *)addrString, sizeof(buf) - 1);
    {
      char tempAddress[INET6_ADDRSTRLEN];
      if (IsAddressIPv4(buf)) {
        strncpy(tempAddress, buf, INET6_ADDRSTRLEN);
        (void)snprintf(buf, 64, "%s%s", "::ffff:", tempAddress);
      }
    }
    return (inet_pton(AF_INET6, (char *)buf, ip->s6_addr) > 0) ? 1 : 0;
  } else
    return (inet_pton(AF_INET6, (char *)addrString, ip->s6_addr) > 0) ? 1 : 0;
}


x86 assembly (clang, -O0):
<ip6_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118d <ip6_atoi+0x2d>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jge    11b0 <ip6_atoi+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2e56(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    12de <ip6_atoi+0x17e>
mov    -0x18(%rbp),%rdi
call   1080 <IsAddressIPv4@plt>
cmp    $0x0,%rax
je     12b2 <ip6_atoi+0x152>
mov    0x2e16(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    (%rax),%eax
mov    %eax,%edx
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
add    $0xffffffff,%edx
call   1030 <strncpy@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
call   1080 <IsAddressIPv4@plt>
cmp    $0x0,%rax
je     1273 <ip6_atoi+0x113>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%r8
mov    $0x40,%esi
lea    0xd99(%rip),%rdx
lea    0xd97(%rip),%rcx
call   1050 <snprintf@plt>
mov    -0x50(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1070 <inet_pton@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovg  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    12de <ip6_atoi+0x17e>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1070 <inet_pton@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovg  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip6_atoi>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rsi,%rsi
je     1186 <ip6_atoi+0x26>
mov    %rsi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jg     11a1 <ip6_atoi+0x41>
mov    (%r14),%edi
mov    0x2e60(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    $0x1,%al
jmp    1272 <ip6_atoi+0x112>
mov    %rbx,%rdi
call   1080 <IsAddressIPv4@plt>
test   %rax,%rax
je     1258 <ip6_atoi+0xf8>
mov    %rsp,-0x30(%rbp)
mov    0x2e23(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r15
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r15
mov    %r15,%rsp
lea    -0x1(%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %rsp,%r12
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r15,%rdi
call   1080 <IsAddressIPv4@plt>
test   %rax,%rax
je     1235 <ip6_atoi+0xd5>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
lea    0xde2(%rip),%rdx
lea    0xde0(%rip),%rcx
mov    %r15,%rdi
mov    $0x40,%esi
mov    %rbx,%r8
call   1050 <snprintf@plt>
mov    %r12,%rsp
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%edx
mov    %r15,%rsi
call   1070 <inet_pton@plt>
test   %rax,%rax
setg   %al
mov    -0x30(%rbp),%rsp
jmp    1272 <ip6_atoi+0x112>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%edx
mov    %rbx,%rsi
call   1070 <inet_pton@plt>
test   %rax,%rax
setg   %al
movzbl %al,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
@in6addr_any = global i32 0
@INET6_ADDRSTRLEN = global i32 0
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [8 x i8] c"::ffff:\00"
@AF_INET6 = global i32 0
define i32 @ip6_atoi(%struct.in6_addr* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.in6_addr*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store %struct.in6_addr* %0, %struct.in6_addr** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %12, %2
%17 = load %struct.in6_addr*, %struct.in6_addr** %4
%18 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @memcpy(i32 %19, i32* @in6addr_any, i32 4)
store i32 1, i32* %3
br label %65
21: ; preds = %12
%22 = load i8*, i8** %5
%23 = call i64 @IsAddressIPv4(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %55
25: ; preds = %21
%26 = load i32, i32* @INET6_ADDRSTRLEN
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %6
%29 = alloca i8, i64 %27
store i64 %27, i64* %7
%30 = load i8*, i8** %5
%31 = sub i64 %27, 1
%32 = trunc i64 %31 to i32
%33 = call i32 @strncpy(i8* %29, i8* %30, i32 %32)
%34 = load i32, i32* @INET6_ADDRSTRLEN
%35 = zext i32 %34 to i64
%36 = call i8* @llvm.stacksave()
store i8* %36, i8** %8
%37 = alloca i8, i64 %35
store i64 %35, i64* %9
%38 = call i64 @IsAddressIPv4(i8* %29)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %25
%41 = load i32, i32* @INET6_ADDRSTRLEN
%42 = call i32 @strncpy(i8* %37, i8* %29, i32 %41)
%43 = call i32 @snprintf(i8* %29, i32 64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %44
44: ; preds = %40, %25
%45 = load i8*, i8** %8
%46 = load i32, i32* @AF_INET6
%47 = load %struct.in6_addr*, %struct.in6_addr** %4
%48 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i64 @inet_pton(i32 %46, i8* %29, i32 %49)
%51 = icmp sgt i64 %50, 0
%52 = zext i1 %51 to i64
%53 = select i1 %51, i32 1, i32 0
store i32 %53, i32* %3
%54 = load i8*, i8** %6
br label %65
55: ; preds = %21
%56 = load i32, i32* @AF_INET6
%57 = load i8*, i8** %5
%58 = load %struct.in6_addr*, %struct.in6_addr** %4
%59 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i64 @inet_pton(i32 %56, i8* %57, i32 %60)
%62 = icmp sgt i64 %61, 0
%63 = zext i1 %62 to i64
%64 = select i1 %62, i32 1, i32 0
store i32 %64, i32* %3
br label %65
65: ; preds = %55, %44, %16
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@in6addr_any = global i32 0
@INET6_ADDRSTRLEN = global i32 0
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [8 x i8] c"::ffff:\00"
@AF_INET6 = global i32 0
define i32 @ip6_atoi(%struct.in6_addr* nocapture %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp slt i32 %5, 2
br i1 %6, label %7, label %11
7: ; preds = %4, %2
%8 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @memcpy(i32 %9, i32* @in6addr_any, i32 4)
br label %43
11: ; preds = %4
%12 = tail call i64 @IsAddressIPv4(i8* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %37, label %14
14: ; preds = %11
%15 = load i32, i32* @INET6_ADDRSTRLEN
%16 = zext i32 %15 to i64
%17 = tail call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = add i32 %15, -1
%20 = call i32 @strncpy(i8* %18, i8* %1, i32 %19)
%21 = load i32, i32* @INET6_ADDRSTRLEN
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
%24 = alloca i8, i64 %22
%25 = call i64 @IsAddressIPv4(i8* %18)
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %14
%28 = load i32, i32* @INET6_ADDRSTRLEN
%29 = call i32 @strncpy(i8* %24, i8* %18, i32 %28)
%30 = call i32 @snprintf(i8* %18, i32 64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %31
31: ; preds = %27, %14
%32 = load i32, i32* @AF_INET6
%33 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %0, i64 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @inet_pton(i32 %32, i8* %18, i32 %34)
%36 = icmp sgt i64 %35, 0
br label %43
37: ; preds = %11
%38 = load i32, i32* @AF_INET6
%39 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %0, i64 0, i32 0
%40 = load i32, i32* %39
%41 = tail call i64 @inet_pton(i32 %38, i8* %1, i32 %40)
%42 = icmp sgt i64 %41, 0
br label %43
43: ; preds = %37, %31, %7
%44 = phi i1 [ true, %7 ], [ %36, %31 ], [ %42, %37 ]
%45 = zext i1 %44 to i32
ret i32 %45
}