#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 *, char, char, char, int, int, int,
                           int);
char *demangle(int vendor, int device) {
  static char ret[8];
  sprintf(ret, "%c%c%c%x%x%x%x", 'A' + ((vendor >> 2) & 0x3f) - 1,
          'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
          'A' + ((vendor >> 8) & 0x1f) - 1, (device >> 4) & 0x0f, device & 0x0f,
          (device >> 12) & 0x0f, (device >> 8) & 0x0f);
  return ret;
}


x86 assembly (clang, -O0):
<demangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x2,%eax
and    $0x3f,%eax
add    $0x41,%eax
sub    $0x1,%eax
mov    %al,%dl
mov    -0x4(%rbp),%eax
and    $0x3,%eax
shl    $0x3,%eax
mov    -0x4(%rbp),%ecx
sar    $0xd,%ecx
and    $0x7,%ecx
or     %ecx,%eax
add    $0x41,%eax
sub    $0x1,%eax
mov    %al,%cl
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
and    $0x1f,%eax
add    $0x41,%eax
sub    $0x1,%eax
mov    %al,%r8b
mov    -0x8(%rbp),%r9d
sar    $0x4,%r9d
and    $0xf,%r9d
mov    -0x8(%rbp),%r11d
and    $0xf,%r11d
mov    -0x8(%rbp),%r10d
sar    $0xc,%r10d
and    $0xf,%r10d
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xf,%eax
lea    0x2e9c(%rip),%rdi
lea    0xe6c(%rip),%rsi
movsbl %dl,%edx
movsbl %cl,%ecx
movsbl %r8b,%r8d
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1030 <sprintf@plt>
lea    0x2e72(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<demangle>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%edx
shr    $0x2,%dl
or     $0x40,%dl
mov    %edi,%ecx
and    $0x3,%ecx
mov    %edi,%esi
shr    $0xd,%esi
and    $0x7,%esi
lea    (%rsi,%rcx,8),%ecx
or     $0x40,%cl
shr    $0x8,%edi
and    $0x1f,%dil
or     $0x40,%dil
mov    %ebx,%r9d
shr    $0x4,%r9d
and    $0xf,%r9d
mov    %ebx,%r10d
and    $0xf,%r10d
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
shr    $0x8,%ebx
and    $0xf,%ebx
sub    $0x8,%rsp
movzbl %cl,%ecx
movzbl %dl,%edx
movzbl %dil,%r8d
lea    0x2eb8(%rip),%r14
lea    0xe88(%rip),%rsi
mov    %r14,%rdi
push   %rbx
push   %rax
push   %r10
call   1030 <sprintf@plt>
add    $0x20,%rsp
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@demangle.ret = internal global [8 x i8] zeroinitializer
@.str = [15 x i8] c"%c%c%c%x%x%x%x\00"
define i8* @demangle(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = ashr i32 %5, 2
%7 = and i32 %6, 63
%8 = add nsw i32 65, %7
%9 = sub nsw i32 %8, 1
%10 = trunc i32 %9 to i8
%11 = load i32, i32* %3
%12 = and i32 %11, 3
%13 = shl i32 %12, 3
%14 = load i32, i32* %3
%15 = ashr i32 %14, 13
%16 = and i32 %15, 7
%17 = or i32 %13, %16
%18 = add nsw i32 65, %17
%19 = sub nsw i32 %18, 1
%20 = trunc i32 %19 to i8
%21 = load i32, i32* %3
%22 = ashr i32 %21, 8
%23 = and i32 %22, 31
%24 = add nsw i32 65, %23
%25 = sub nsw i32 %24, 1
%26 = trunc i32 %25 to i8
%27 = load i32, i32* %4
%28 = ashr i32 %27, 4
%29 = and i32 %28, 15
%30 = load i32, i32* %4
%31 = and i32 %30, 15
%32 = load i32, i32* %4
%33 = ashr i32 %32, 12
%34 = and i32 %33, 15
%35 = load i32, i32* %4
%36 = ashr i32 %35, 8
%37 = and i32 %36, 15
%38 = call i32 @sprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @demangle.ret, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %10, i8 signext %20, i8 signext %26, i32 %29, i32 %31, i32 %34, i32 %37)
ret i8* getelementptr inbounds ([8 x i8], [8 x i8]* @demangle.ret, i64 0, i64 0)
}

LLVM IR (-O2):
@demangle.ret = internal global [8 x i8] zeroinitializer
@.str = [15 x i8] c"%c%c%c%x%x%x%x\00"
define i8* @demangle(i32 %0, i32 %1) {
%3 = trunc i32 %0 to i8
%4 = lshr i8 %3, 2
%5 = or i8 %4, 64
%6 = shl i32 %0, 3
%7 = and i32 %6, 24
%8 = lshr i32 %0, 13
%9 = and i32 %8, 7
%10 = or i32 %7, %9
%11 = trunc i32 %10 to i8
%12 = or i8 %11, 64
%13 = lshr i32 %0, 8
%14 = trunc i32 %13 to i8
%15 = and i8 %14, 31
%16 = or i8 %15, 64
%17 = lshr i32 %1, 4
%18 = and i32 %17, 15
%19 = and i32 %1, 15
%20 = lshr i32 %1, 12
%21 = and i32 %20, 15
%22 = lshr i32 %1, 8
%23 = and i32 %22, 15
%24 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @demangle.ret, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8 signext %5, i8 signext %12, i8 signext %16, i32 %18, i32 %19, i32 %21, i32 %23)
ret i8* getelementptr inbounds ([8 x i8], [8 x i8]* @demangle.ret, i64 0, i64 0)
}