#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int toupper(char);
int name_mangle(char *In, char *Out, char name_type) {
  int i;
  int c;
  int len;
  char buf[20];
  char *p = Out;
  char *scope = "";
  (void)memset(buf, 0, 20);
  if (strcmp(In, "*") == 0)
    buf[0] = '*';
  else
    (void)sprintf(buf, "%-15.15s%c", In, name_type);
  p[0] = 32;
  p++;
  for (i = 0; i < 16; i++) {
    c = toupper(buf[i]);
    p[i * 2] = ((c >> 4) & 0x000F) + 'A';
    p[(i * 2) + 1] = (c & 0x000F) + 'A';
  }
  p += 32;
  p[0] = '\0';
  for (i = 0, len = 0; NULL != scope; i++, len++) {
    switch (scope[i]) {
    case '\0':
      p[0] = len;
      if (len > 0)
        p[len + 1] = 0;
      return (strlen(Out));
    case '.':
      p[0] = len;
      p += (len + 1);
      len = 0;
      break;
    default:
      p[len + 1] = scope[i];
      break;
    }
  }
  return (strlen(Out));
}


x86 assembly (clang, -O0):
<name_mangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11ab <name_mangle+0x5b>
movb   $0x2a,-0x40(%rbp)
jmp    11c3 <name_mangle+0x73>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe48(%rip),%rsi
movsbl -0x19(%rbp),%ecx
call   1070 <sprintf@plt>
mov    -0x48(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x10,-0x20(%rbp)
jge    1242 <name_mangle+0xf2>
movslq -0x20(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%edi
call   1030 <toupper@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sar    $0x4,%eax
and    $0xf,%eax
add    $0x41,%eax
mov    %al,%dl
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
and    $0xf,%eax
add    $0x41,%eax
mov    %al,%dl
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11dd <name_mangle+0x8d>
mov    -0x48(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x50(%rbp),%rax
je     1335 <name_mangle+0x1e5>
mov    -0x50(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x54(%rbp)
test   %eax,%eax
je     129c <name_mangle+0x14c>
jmp    128b <name_mangle+0x13b>
mov    -0x54(%rbp),%eax
sub    $0x2e,%eax
je     12d3 <name_mangle+0x183>
jmp    12fe <name_mangle+0x1ae>
mov    -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,(%rax)
cmpl   $0x0,-0x28(%rbp)
jle    12c2 <name_mangle+0x172>
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    1341 <name_mangle+0x1f1>
mov    -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x28(%rbp)
jmp    1319 <name_mangle+0x1c9>
mov    -0x50(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    131e <name_mangle+0x1ce>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1263 <name_mangle+0x113>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<name_mangle>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
lea    0xe8a(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     119b <name_mangle+0x4b>
movsbl %bpl,%ecx
lea    0xe74(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
jmp    119f <name_mangle+0x4f>
movb   $0x2a,(%rsp)
movb   $0x20,(%rbx)
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
movsbl -0x1(%rsp,%rbp,1),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
shr    $0x4,%cl
add    $0x41,%cl
mov    %cl,-0x1(%rbx,%rbp,2)
and    $0xf,%al
add    $0x41,%al
mov    %al,(%rbx,%rbp,2)
add    $0x1,%rbp
cmp    $0x11,%rbp
jne    11b0 <name_mangle+0x60>
movb   $0x0,0x21(%rbx)
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"*\00"
@.str.2 = [11 x i8] c"%-15.15s%c\00"
define i32 @name_mangle(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [20 x i8]
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
%14 = load i8*, i8** %6
store i8* %14, i8** %12
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %13
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 20)
%17 = load i8*, i8** %5
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
store i8 42, i8* %21
br label %27
22: ; preds = %3
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%24 = load i8*, i8** %5
%25 = load i8, i8* %7
%26 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8 signext %25)
br label %27
27: ; preds = %22, %20
%28 = load i8*, i8** %12
%29 = getelementptr inbounds i8, i8* %28, i64 0
store i8 32, i8* %29
%30 = load i8*, i8** %12
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %12
store i32 0, i32* %8
br label %32
32: ; preds = %61, %27
%33 = load i32, i32* %8
%34 = icmp slt i32 %33, 16
br i1 %34, label %35, label %64
35: ; preds = %32
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @toupper(i8 signext %39)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = ashr i32 %41, 4
%43 = and i32 %42, 15
%44 = add nsw i32 %43, 65
%45 = trunc i32 %44 to i8
%46 = load i8*, i8** %12
%47 = load i32, i32* %8
%48 = mul nsw i32 %47, 2
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
store i8 %45, i8* %50
%51 = load i32, i32* %9
%52 = and i32 %51, 15
%53 = add nsw i32 %52, 65
%54 = trunc i32 %53 to i8
%55 = load i8*, i8** %12
%56 = load i32, i32* %8
%57 = mul nsw i32 %56, 2
%58 = add nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %55, i64 %59
store i8 %54, i8* %60
br label %61
61: ; preds = %35
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
br label %32
64: ; preds = %32
%65 = load i8*, i8** %12
%66 = getelementptr inbounds i8, i8* %65, i64 32
store i8* %66, i8** %12
%67 = load i8*, i8** %12
%68 = getelementptr inbounds i8, i8* %67, i64 0
store i8 0, i8* %68
store i32 0, i32* %8
store i32 0, i32* %10
br label %69
69: ; preds = %117, %64
%70 = load i8*, i8** %13
%71 = icmp ne i8* null, %70
br i1 %71, label %72, label %122
72: ; preds = %69
%73 = load i8*, i8** %13
%74 = load i32, i32* %8
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
switch i32 %78, label %105 [
i32 0, label %79
i32 46, label %95
]
79: ; preds = %72
%80 = load i32, i32* %10
%81 = trunc i32 %80 to i8
%82 = load i8*, i8** %12
%83 = getelementptr inbounds i8, i8* %82, i64 0
store i8 %81, i8* %83
%84 = load i32, i32* %10
%85 = icmp sgt i32 %84, 0
br i1 %85, label %86, label %92
86: ; preds = %79
%87 = load i8*, i8** %12
%88 = load i32, i32* %10
%89 = add nsw i32 %88, 1
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %87, i64 %90
store i8 0, i8* %91
br label %92
92: ; preds = %86, %79
%93 = load i8*, i8** %6
%94 = call i32 @strlen(i8* %93)
store i32 %94, i32* %4
br label %125
95: ; preds = %72
%96 = load i32, i32* %10
%97 = trunc i32 %96 to i8
%98 = load i8*, i8** %12
%99 = getelementptr inbounds i8, i8* %98, i64 0
store i8 %97, i8* %99
%100 = load i32, i32* %10
%101 = add nsw i32 %100, 1
%102 = load i8*, i8** %12
%103 = sext i32 %101 to i64
%104 = getelementptr inbounds i8, i8* %102, i64 %103
store i8* %104, i8** %12
store i32 0, i32* %10
br label %116
105: ; preds = %72
%106 = load i8*, i8** %13
%107 = load i32, i32* %8
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %106, i64 %108
%110 = load i8, i8* %109
%111 = load i8*, i8** %12
%112 = load i32, i32* %10
%113 = add nsw i32 %112, 1
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i8, i8* %111, i64 %114
store i8 %110, i8* %115
br label %116
116: ; preds = %105, %95
br label %117
117: ; preds = %116
%118 = load i32, i32* %8
%119 = add nsw i32 %118, 1
store i32 %119, i32* %8
%120 = load i32, i32* %10
%121 = add nsw i32 %120, 1
store i32 %121, i32* %10
br label %69
122: ; preds = %69
%123 = load i8*, i8** %6
%124 = call i32 @strlen(i8* %123)
store i32 %124, i32* %4
br label %125
125: ; preds = %122, %92
%126 = load i32, i32* %4
ret i32 %126
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"*\00"
@.str.2 = [11 x i8] c"%-15.15s%c\00"
define i32 @name_mangle(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 20)
%7 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %3
store i8 42, i8* %5
br label %12
10: ; preds = %3
%11 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8 signext %2)
br label %12
12: ; preds = %10, %9
store i8 32, i8* %1
%13 = getelementptr inbounds i8, i8* %1, i64 1
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %28, %14 ]
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = call i32 @toupper(i8 signext %17)
%19 = trunc i32 %18 to i8
%20 = lshr i8 %19, 4
%21 = add nuw nsw i8 %20, 65
%22 = shl nuw nsw i64 %15, 1
%23 = getelementptr inbounds i8, i8* %13, i64 %22
store i8 %21, i8* %23
%24 = and i8 %19, 15
%25 = add nuw nsw i8 %24, 65
%26 = or i64 %22, 1
%27 = getelementptr inbounds i8, i8* %13, i64 %26
store i8 %25, i8* %27
%28 = add nuw nsw i64 %15, 1
%29 = icmp eq i64 %28, 16
br i1 %29, label %30, label %14
30: ; preds = %14
%31 = getelementptr inbounds i8, i8* %1, i64 33
store i8 0, i8* %31
%32 = call i32 @strlen(i8* %1)
ret i32 %32
}