#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*/ dtc_isvalid(char const *);
int sscanf(char const *, char *, unsigned int *, unsigned int *);
int dtc_humantobytes(const char *human, unsigned int *A, unsigned int *B) {
  if (!dtc_isvalid(human)) {
    return -1;
  }
  int mod = human[1] - '0';
  if (mod > 3 || mod < 0) {
    return -1;
  }
  unsigned int val;
  switch (human[0]) {
  case 'P':
    val = mod;
    break;
  case 'C':
    val = mod + 0x04;
    break;
  case 'B':
    val = mod + 0x08;
    break;
  case 'U':
    val = mod + 0x0C;
    break;
  default:
    return -1;
  }
  unsigned int one, two;
  if (2 != sscanf(human + 2, "%1X%02X", &one, &two)) {
    return -1;
  }
  *A = one + (val << 4);
  *B = two;
  return 0;
}


x86 assembly (clang, -O0):
<dtc_humantobytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <dtc_isvalid@plt>
cmp    $0x0,%eax
jne    1152 <dtc_humantobytes+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <dtc_humantobytes+0x126>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jg     1174 <dtc_humantobytes+0x54>
cmpl   $0x0,-0x24(%rbp)
jge    1180 <dtc_humantobytes+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <dtc_humantobytes+0x126>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x13,%eax
ja     11e2 <dtc_humantobytes+0xc2>
mov    -0x38(%rbp),%rax
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11ee <dtc_humantobytes+0xce>
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x28(%rbp)
jmp    11ee <dtc_humantobytes+0xce>
mov    -0x24(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x28(%rbp)
jmp    11ee <dtc_humantobytes+0xce>
mov    -0x24(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x28(%rbp)
jmp    11ee <dtc_humantobytes+0xce>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <dtc_humantobytes+0x126>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
lea    0xe53(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cmp    %ecx,%eax
je     1225 <dtc_humantobytes+0x105>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <dtc_humantobytes+0x126>
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%eax
shl    $0x4,%eax
add    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dtc_humantobytes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <dtc_isvalid@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     11b2 <dtc_humantobytes+0x92>
movsbl 0x1(%rbx),%ecx
lea    -0x34(%rcx),%edx
cmp    $0xfc,%dl
jb     11b2 <dtc_humantobytes+0x92>
movsbl (%rbx),%edx
add    $0xffffffbe,%edx
cmp    $0x13,%edx
ja     11b2 <dtc_humantobytes+0x92>
lea    -0x30(%rcx),%ebp
lea    0xe9f(%rip),%rsi
movslq (%rsi,%rdx,4),%rdx
add    %rsi,%rdx
jmp    *%rdx
add    $0xffffffd8,%ecx
jmp    1177 <dtc_humantobytes+0x57>
add    $0xffffffd4,%ecx
jmp    1177 <dtc_humantobytes+0x57>
add    $0xffffffdc,%ecx
mov    %ecx,%ebp
add    $0x2,%rbx
lea    0xecc(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x2,%ecx
jne    11b2 <dtc_humantobytes+0x92>
shl    $0x4,%ebp
add    0x4(%rsp),%ebp
mov    %ebp,(%r15)
mov    (%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"%1X%02X\00"
define i32 @dtc_humantobytes(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32 @dtc_isvalid(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %38, label %8
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = add i8 %10, -52
%13 = icmp ult i8 %12, -4
br i1 %13, label %38, label %14
14: ; preds = %8
%15 = add nsw i32 %11, -48
%16 = load i8, i8* %0
%17 = sext i8 %16 to i32
switch i32 %17, label %38 [
i32 80, label %24
i32 67, label %18
i32 66, label %20
i32 85, label %22
]
18: ; preds = %14
%19 = add nsw i32 %11, -44
br label %24
20: ; preds = %14
%21 = add nsw i32 %11, -40
br label %24
22: ; preds = %14
%23 = add nsw i32 %11, -36
br label %24
24: ; preds = %14, %22, %20, %18
%25 = phi i32 [ %23, %22 ], [ %21, %20 ], [ %19, %18 ], [ %15, %14 ]
%26 = bitcast i32* %4 to i8*
%27 = bitcast i32* %5 to i8*
%28 = getelementptr inbounds i8, i8* %0, i64 2
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5)
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i32, i32* %4
%33 = shl nsw i32 %25, 4
%34 = add i32 %32, %33
store i32 %34, i32* %1
%35 = load i32, i32* %5
store i32 %35, i32* %2
br label %36
36: ; preds = %24, %31
%37 = phi i32 [ 0, %31 ], [ -1, %24 ]
br label %38
38: ; preds = %8, %14, %36, %3
%39 = phi i32 [ -1, %3 ], [ -1, %8 ], [ %37, %36 ], [ -1, %14 ]
ret i32 %39
}