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

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int inet_pton(int /*<<< orphan*/, char *, unsigned char *);
int /*<<< orphan*/ memcpy(char *, char const *, unsigned long);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ipv6_to_uchar(const char *p, unsigned long len, unsigned char *result) {
  char buf[46];
  if (len > 46 - 1)
    return 0;
  memset(buf, 0, sizeof(buf));
  memcpy(buf, p, len);
  if (inet_pton(AF_INET6, buf, result) == 1)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<ipv6_to_uchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x2d,-0x18(%rbp)
jbe    115b <ipv6_to_uchar+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    11ae <ipv6_to_uchar+0x7e>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x2e,%edx
call   1030 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
jne    11a7 <ipv6_to_uchar+0x77>
movl   $0x1,-0x4(%rbp)
jmp    11ae <ipv6_to_uchar+0x7e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv6_to_uchar>:
xor    %eax,%eax
cmp    $0x2d,%rsi
ja     1195 <ipv6_to_uchar+0x65>
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x2e,%edx
call   1030 <memset@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <inet_pton@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
sete   %al
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@AF_INET6 = global i32 0
define i32 @ipv6_to_uchar(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [46 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%9 = load i64, i64* %6
%10 = icmp ugt i64 %9, 45
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 0, i32* %4
br label %26
12: ; preds = %3
%13 = getelementptr inbounds [46 x i8], [46 x i8]* %8, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 46)
%15 = getelementptr inbounds [46 x i8], [46 x i8]* %8, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = call i32 @memcpy(i8* %15, i8* %16, i64 %17)
%19 = load i32, i32* @AF_INET6
%20 = getelementptr inbounds [46 x i8], [46 x i8]* %8, i64 0, i64 0
%21 = load i8*, i8** %7
%22 = call i32 @inet_pton(i32 %19, i8* %20, i8* %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %12
store i32 1, i32* %4
br label %26
25: ; preds = %12
store i32 0, i32* %4
br label %26
26: ; preds = %25, %24, %11
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@AF_INET6 = global i32 0
define i32 @ipv6_to_uchar(i8* %0, i64 %1, i8* %2) {
%4 = alloca [46 x i8]
%5 = getelementptr inbounds [46 x i8], [46 x i8]* %4, i64 0, i64 0
%6 = icmp ugt i64 %1, 45
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = call i32 @memset(i8* %5, i32 0, i32 46)
%9 = call i32 @memcpy(i8* %5, i8* %0, i64 %1)
%10 = load i32, i32* @AF_INET6
%11 = call i32 @inet_pton(i32 %10, i8* %5, i8* %2)
%12 = icmp eq i32 %11, 1
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %7, %3
%15 = phi i32 [ 0, %3 ], [ %13, %7 ]
ret i32 %15
}