#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 uint8_t;
struct in6_addr {
  int dummy;
};

/* Variables and functions */
scalar_t__ IN6_IS_ADDR_V4MAPPED(struct in6_addr const *);
int /*<<< orphan*/ addr_ntop(char *, size_t, struct in6_addr const *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
const char *prefix_ntop(char *dst, size_t bufflen, const struct in6_addr *addr,
                        uint8_t plen) {
  if (bufflen < 4 || !addr_ntop(dst, bufflen - 4, addr))
    return NULL;
  char *str = dst + strlen(dst);
  if (plen >= 96 && IN6_IS_ADDR_V4MAPPED(addr)) {
    sprintf(str, "/%d", plen - 96);
  } else {
    sprintf(str, "/%d", plen);
  }
  return dst;
}


x86 assembly (clang, -O0):
<prefix_ntop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x4,-0x18(%rbp)
jb     1180 <prefix_ntop+0x40>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x4,%rsi
mov    -0x20(%rbp),%rdx
call   1050 <addr_ntop@plt>
cmp    $0x0,%eax
jne    118d <prefix_ntop+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    1201 <prefix_ntop+0xc1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x60,-0x24(%rbp)
jl     11e6 <prefix_ntop+0xa6>
mov    -0x20(%rbp),%rdi
call   1030 <IN6_IS_ADDR_V4MAPPED@plt>
cmp    $0x0,%rax
je     11e6 <prefix_ntop+0xa6>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
sub    $0x60,%edx
lea    0xe24(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11f9 <prefix_ntop+0xb9>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe0c(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prefix_ntop>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%rsi
jb     11a2 <prefix_ntop+0x62>
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rdi,%rbx
add    $0xfffffffffffffffc,%rsi
call   1050 <addr_ntop@plt>
test   %eax,%eax
je     11a2 <prefix_ntop+0x62>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%r12
add    %rbx,%r12
cmp    $0x60,%r14d
jl     118e <prefix_ntop+0x4e>
mov    %r15,%rdi
call   1030 <IN6_IS_ADDR_V4MAPPED@plt>
lea    -0x60(%r14),%ecx
test   %rax,%rax
cmove  %r14d,%ecx
mov    %ecx,%r14d
lea    0xe6b(%rip),%rsi
mov    %r12,%rdi
mov    %r14d,%edx
call   1060 <sprintf@plt>
jmp    11a4 <prefix_ntop+0x64>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
@.str = [4 x i8] c"/%d\00"
define i8* @prefix_ntop(i8* %0, i64 %1, %struct.in6_addr* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.in6_addr*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store %struct.in6_addr* %2, %struct.in6_addr** %8
store i32 %3, i32* %9
%11 = load i64, i64* %7
%12 = icmp ult i64 %11, 4
br i1 %12, label %20, label %13
13: ; preds = %4
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = sub i64 %15, 4
%17 = load %struct.in6_addr*, %struct.in6_addr** %8
%18 = call i32 @addr_ntop(i8* %14, i64 %16, %struct.in6_addr* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %13, %4
store i8* null, i8** %5
br label %44
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8* %26, i8** %10
%27 = load i32, i32* %9
%28 = icmp sge i32 %27, 96
br i1 %28, label %29, label %38
29: ; preds = %21
%30 = load %struct.in6_addr*, %struct.in6_addr** %8
%31 = call i64 @IN6_IS_ADDR_V4MAPPED(%struct.in6_addr* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i8*, i8** %10
%35 = load i32, i32* %9
%36 = sub nsw i32 %35, 96
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %42
38: ; preds = %29, %21
%39 = load i8*, i8** %10
%40 = load i32, i32* %9
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %38, %33
%43 = load i8*, i8** %6
store i8* %43, i8** %5
br label %44
44: ; preds = %42, %20
%45 = load i8*, i8** %5
ret i8* %45
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@.str = [4 x i8] c"/%d\00"
define i8* @prefix_ntop(i8* %0, i64 %1, %struct.in6_addr* %2, i32 %3) {
%5 = icmp ult i64 %1, 4
br i1 %5, label %23, label %6
6: ; preds = %4
%7 = add i64 %1, -4
%8 = tail call i32 @addr_ntop(i8* %0, i64 %7, %struct.in6_addr* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %6
%11 = tail call i32 @strlen(i8* %0)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = icmp sgt i32 %3, 95
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = tail call i64 @IN6_IS_ADDR_V4MAPPED(%struct.in6_addr* %2)
%17 = icmp eq i64 %16, 0
%18 = add nsw i32 %3, -96
%19 = select i1 %17, i32 %3, i32 %18
br label %20
20: ; preds = %15, %10
%21 = phi i32 [ %3, %10 ], [ %19, %15 ]
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %4, %6
%24 = phi i8* [ null, %6 ], [ null, %4 ], [ %0, %20 ]
ret i8* %24
}