#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*/ fprintf(int /*<<< orphan*/, char *);
int snprintf(char *, int, char *, char, unsigned int, unsigned int,
             unsigned int);
int /*<<< orphan*/ stderr;
int obderrconvert_r(char *buf, int n, unsigned int A, unsigned int B) {
  unsigned int partcode = (A >> 4) & 0x0F;
  unsigned int numbercode = 0;
  char strpartcode;
  switch (partcode) {
  case 0x00:
  case 0x01:
  case 0x02:
  case 0x03:
    strpartcode = 'P';
    numbercode = partcode;
    break;
  case 0x04:
  case 0x05:
  case 0x06:
  case 0x07:
    strpartcode = 'C';
    numbercode = partcode - 4;
    break;
  case 0x08:
  case 0x09:
  case 0x0A:
  case 0x0B:
    strpartcode = 'B';
    numbercode = partcode - 8;
    break;
  case 0x0C:
  case 0x0D:
  case 0x0E:
  case 0x0F:
    strpartcode = 'U';
    numbercode = partcode - 12;
    break;
  default:
    fprintf(stderr, "Could not decode error code.\n");
    return 0;
    break;
  }
  return snprintf(buf, n, "%c%u%01X%02X", strpartcode, numbercode, A & 0x0F, B);
}


x86 assembly (clang, -O0):
<obderrconvert_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%eax
mov    %rax,-0x30(%rbp)
sub    $0xf,%rax
ja     11b2 <obderrconvert_r+0x92>
mov    -0x30(%rbp),%rax
lea    0xe9c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x50,-0x25(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11d3 <obderrconvert_r+0xb3>
movb   $0x43,-0x25(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x24(%rbp)
jmp    11d3 <obderrconvert_r+0xb3>
movb   $0x42,-0x25(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x24(%rbp)
jmp    11d3 <obderrconvert_r+0xb3>
movb   $0x55,-0x25(%rbp)
mov    -0x20(%rbp),%eax
sub    $0xc,%eax
mov    %eax,-0x24(%rbp)
jmp    11d3 <obderrconvert_r+0xb3>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1201 <obderrconvert_r+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x25(%rbp),%cl
mov    -0x24(%rbp),%r8d
mov    -0x18(%rbp),%r9d
and    $0xf,%r9d
mov    -0x1c(%rbp),%eax
lea    0xe6b(%rip),%rdx
movsbl %cl,%ecx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<obderrconvert_r>:
push   %rax
mov    %edx,%r9d
mov    %edx,%eax
shr    $0x4,%eax
and    $0xf,%eax
lea    0xeed(%rip),%rdx
mov    (%rdx,%rax,4),%r8d
lea    0xf22(%rip),%rdx
movsbl (%rax,%rdx,1),%eax
and    $0xf,%r9d
mov    %ecx,(%rsp)
lea    0xec0(%rip),%rdx
mov    %eax,%ecx
call   1030 <snprintf@plt>
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Could not decode error code.\0A\00"
@.str.1 = [13 x i8] c"%c%u%01X%02X\00"
define i32 @obderrconvert_r(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* %8
%14 = lshr i32 %13, 4
%15 = and i32 %14, 15
store i32 %15, i32* %10
store i32 0, i32* %11
%16 = load i32, i32* %10
switch i32 %16, label %28 [
i32 0, label %17
i32 1, label %17
i32 2, label %17
i32 3, label %17
i32 4, label %19
i32 5, label %19
i32 6, label %19
i32 7, label %19
i32 8, label %22
i32 9, label %22
i32 10, label %22
i32 11, label %22
i32 12, label %25
i32 13, label %25
i32 14, label %25
i32 15, label %25
]
17: ; preds = %4, %4, %4, %4
store i8 80, i8* %12
%18 = load i32, i32* %10
store i32 %18, i32* %11
br label %31
19: ; preds = %4, %4, %4, %4
store i8 67, i8* %12
%20 = load i32, i32* %10
%21 = sub i32 %20, 4
store i32 %21, i32* %11
br label %31
22: ; preds = %4, %4, %4, %4
store i8 66, i8* %12
%23 = load i32, i32* %10
%24 = sub i32 %23, 8
store i32 %24, i32* %11
br label %31
25: ; preds = %4, %4, %4, %4
store i8 85, i8* %12
%26 = load i32, i32* %10
%27 = sub i32 %26, 12
store i32 %27, i32* %11
br label %31
28: ; preds = %4
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %40
31: ; preds = %25, %22, %19, %17
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = load i8, i8* %12
%35 = load i32, i32* %11
%36 = load i32, i32* %8
%37 = and i32 %36, 15
%38 = load i32, i32* %9
%39 = call i32 @snprintf(i8* %32, i32 %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8 signext %34, i32 %35, i32 %37, i32 %38)
store i32 %39, i32* %5
br label %40
40: ; preds = %31, %28
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [13 x i8] c"%c%u%01X%02X\00"
@switch.table.obderrconvert_r = [16 x i32] [i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3]
@switch.table.obderrconvert_r.2 = [16 x i8] c"PPPPCCCCBBBBUUUU"
define i32 @obderrconvert_r(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = lshr i32 %2, 4
%6 = and i32 %5, 15
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds [16 x i32], [16 x i32]* @switch.table.obderrconvert_r, i64 0, i64 %7
%9 = load i32, i32* %8
%10 = zext i32 %6 to i64
%11 = getelementptr inbounds [16 x i8], [16 x i8]* @switch.table.obderrconvert_r.2, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = and i32 %2, 15
%14 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8 signext %12, i32 %9, i32 %13, i32 %3)
ret i32 %14
}