#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
scalar_t__ inet_ntop(int /*<<< orphan*/, void *, char *, size_t);
int rat_lib_6addr_to_str(char *buf, size_t buflen, struct in6_addr *addr) {
  if (!buf || !buflen || !addr)
    goto exit_err;
  if (inet_ntop(AF_INET6, (void *)addr, buf, buflen))
    return 0;
exit_err:
  return -1;
}


x86 assembly (clang, -O0):
<rat_lib_6addr_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1145 <rat_lib_6addr_to_str+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1145 <rat_lib_6addr_to_str+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    114a <rat_lib_6addr_to_str+0x3a>
jmp    117f <rat_lib_6addr_to_str+0x6f>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
je     117a <rat_lib_6addr_to_str+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    1186 <rat_lib_6addr_to_str+0x76>
jmp    117f <rat_lib_6addr_to_str+0x6f>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rat_lib_6addr_to_str>:
test   %rdi,%rdi
je     114a <rat_lib_6addr_to_str+0x3a>
mov    %rsi,%rcx
test   %rsi,%rsi
je     114a <rat_lib_6addr_to_str+0x3a>
test   %rdx,%rdx
je     114a <rat_lib_6addr_to_str+0x3a>
push   %rax
mov    %rdi,%rax
mov    0x2ebb(%rip),%rsi
mov    (%rsi),%edi
mov    %rdx,%rsi
mov    %rax,%rdx
call   1030 <inet_ntop@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
lea    0x8(%rsp),%rsp
je     114a <rat_lib_6addr_to_str+0x3a>
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
@AF_INET6 = global i32 0
define i32 @rat_lib_6addr_to_str(i8* %0, i64 %1, %struct.in6_addr* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.in6_addr*
store i8* %0, i8** %5
store i64 %1, i64* %6
store %struct.in6_addr* %2, %struct.in6_addr** %7
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = load i64, i64* %6
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load %struct.in6_addr*, %struct.in6_addr** %7
%15 = icmp ne %struct.in6_addr* %14, null
br i1 %15, label %17, label %16
16: ; preds = %13, %10, %3
br label %27
17: ; preds = %13
%18 = load i32, i32* @AF_INET6
%19 = load %struct.in6_addr*, %struct.in6_addr** %7
%20 = bitcast %struct.in6_addr* %19 to i8*
%21 = load i8*, i8** %5
%22 = load i64, i64* %6
%23 = call i64 @inet_ntop(i32 %18, i8* %20, i8* %21, i64 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 0, i32* %4
br label %28
26: ; preds = %17
br label %27
27: ; preds = %26, %16
store i32 -1, i32* %4
br label %28
28: ; preds = %27, %25
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@AF_INET6 = global i32 0
define i32 @rat_lib_6addr_to_str(i8* %0, i64 %1, %struct.in6_addr* %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i64 %1, 0
%6 = and i1 %4, %5
%7 = icmp ne %struct.in6_addr* %2, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i32, i32* @AF_INET6
%11 = bitcast %struct.in6_addr* %2 to i8*
%12 = tail call i64 @inet_ntop(i32 %10, i8* %11, i8* %0, i64 %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9, %3
br label %15
15: ; preds = %9, %14
%16 = phi i32 [ -1, %14 ], [ 0, %9 ]
ret i32 %16
}