#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*/ sprintf(char *, char *, ...);
int strlen(char *);
void truncatePrefixFromConfig(char *src, char *dst, char length) {
  int i = 0;
  dst[0] = 0;
  for (i = 0; i < length / 8; i++) {
    sprintf(dst + strlen(dst), "%02x", src[i]);
    if (i && (i % 2))
      sprintf(dst + strlen(dst), ":");
  }
  if (i % 2)
    sprintf(dst + strlen(dst), "::");
  else
    sprintf(dst + strlen(dst), ":");
}


x86 assembly (clang, -O0):
<truncatePrefixFromConfig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x11(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11f6 <truncatePrefixFromConfig+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
cmpl   $0x0,-0x18(%rbp)
je     11e3 <truncatePrefixFromConfig+0xc3>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11e3 <truncatePrefixFromConfig+0xc3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    11e8 <truncatePrefixFromConfig+0xc8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <truncatePrefixFromConfig+0x2a>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1237 <truncatePrefixFromConfig+0x117>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    125f <truncatePrefixFromConfig+0x13f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rdi
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<truncatePrefixFromConfig>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
movb   $0x0,(%rsi)
cmp    $0x8,%dl
jl     11a4 <truncatePrefixFromConfig+0x84>
mov    %rdi,%r14
mov    %edx,%r12d
sar    $0x7,%r12b
shr    $0x5,%r12b
add    %dl,%r12b
sar    $0x3,%r12b
movsbl %r12b,%eax
mov    %eax,%r13d
lea    0xea7(%rip),%r15
xor    %ebp,%ebp
jmp    1169 <truncatePrefixFromConfig+0x49>
nopl   (%rax)
add    $0x1,%rbp
cmp    %rbp,%r13
je     119e <truncatePrefixFromConfig+0x7e>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
movsbl (%r14,%rbp,1),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
test   $0x1,%bpl
je     1160 <truncatePrefixFromConfig+0x40>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movw   $0x3a,(%rbx,%rax,1)
jmp    1160 <truncatePrefixFromConfig+0x40>
test   $0x1,%r12b
jne    11b6 <truncatePrefixFromConfig+0x96>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movw   $0x3a,(%rbx,%rax,1)
jmp    11cb <truncatePrefixFromConfig+0xab>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movw   $0x3a3a,(%rbx,%rax,1)
movb   $0x0,0x2(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [3 x i8] c"::\00"
define void @truncatePrefixFromConfig(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 0, i8* %9
store i32 0, i32* %7
br label %10
10: ; preds = %43, %3
%11 = load i32, i32* %7
%12 = load i8, i8* %6
%13 = sext i8 %12 to i32
%14 = sdiv i32 %13, 8
%15 = icmp slt i32 %11, %14
br i1 %15, label %16, label %46
16: ; preds = %10
%17 = load i8*, i8** %5
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8*, i8** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %16
%32 = load i32, i32* %7
%33 = srem i32 %32, 2
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %31
%36 = load i8*, i8** %5
%37 = load i8*, i8** %5
%38 = call i32 @strlen(i8* %37)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %35, %31, %16
br label %43
43: ; preds = %42
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %10
46: ; preds = %10
%47 = load i32, i32* %7
%48 = srem i32 %47, 2
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %46
%51 = load i8*, i8** %5
%52 = load i8*, i8** %5
%53 = call i32 @strlen(i8* %52)
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %64
57: ; preds = %46
%58 = load i8*, i8** %5
%59 = load i8*, i8** %5
%60 = call i32 @strlen(i8* %59)
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %58, i64 %61
%63 = call i32 (i8*, i8*, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %64
64: ; preds = %57, %50
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
@.str.2 = [3 x i8] c"::\00"
define void @truncatePrefixFromConfig(i8* nocapture %0, i8* %1, i8 signext %2) {
store i8 0, i8* %1
%4 = sdiv i8 %2, 8
%5 = sext i8 %4 to i32
%6 = icmp sgt i8 %2, 7
br i1 %6, label %7, label %35
7: ; preds = %3
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %25
%10 = phi i64 [ 0, %7 ], [ %26, %25 ]
%11 = tail call i32 @strlen(i8* %1)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = getelementptr inbounds i8, i8* %0, i64 %10
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = and i64 %10, 1
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %9
%21 = tail call i32 @strlen(i8* %1)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = bitcast i8* %23 to i16*
store i16 58, i16* %24
br label %25
25: ; preds = %9, %20
%26 = add nuw nsw i64 %10, 1
%27 = icmp eq i64 %26, %8
br i1 %27, label %28, label %9
28: ; preds = %25
%29 = and i32 %5, 1
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %28
%32 = tail call i32 @strlen(i8* %1)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %1, i64 %33
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %34, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 3, i1 false)
br label %40
35: ; preds = %3, %28
%36 = tail call i32 @strlen(i8* %1)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %1, i64 %37
%39 = bitcast i8* %38 to i16*
store i16 58, i16* %39
br label %40
40: ; preds = %35, %31
ret void
}