#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 */
char c_unescape_char(int /*<<< orphan*/);
scalar_t__ isdigit(char const);
scalar_t__ strtol(char const *, char **, int);
char toupper(char const);
char c_unescape_char_ptr(const char *str, char **endptr) {
  char ch;
  if (toupper(*str) == 'X')
    ch = (char)strtol(++str, endptr, 16);
  else if (isdigit(*str))
    ch = (char)strtol(++str, endptr, 8);
  else {
    ch = c_unescape_char(*(str++));
    if (endptr != NULL)
      *endptr = (char *)str;
  }
  return (ch);
}


x86 assembly (clang, -O0):
<c_unescape_char_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x58,%eax
jne    118a <c_unescape_char_ptr+0x4a>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x8(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %al,-0x11(%rbp)
jmp    11fc <c_unescape_char_ptr+0xbc>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11c2 <c_unescape_char_ptr+0x82>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x8(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1050 <strtol@plt>
mov    %al,-0x11(%rbp)
jmp    11f7 <c_unescape_char_ptr+0xb7>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1060 <c_unescape_char@plt>
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f2 <c_unescape_char_ptr+0xb2>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11f7 <c_unescape_char_ptr+0xb7>
jmp    11fc <c_unescape_char_ptr+0xbc>
movsbl -0x11(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_unescape_char_ptr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1040 <toupper@plt>
cmp    $0x58,%al
jne    116c <c_unescape_char_ptr+0x2c>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <strtol@plt>
jmp    11a3 <c_unescape_char_ptr+0x63>
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     118f <c_unescape_char_ptr+0x4f>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1050 <strtol@plt>
jmp    11a3 <c_unescape_char_ptr+0x63>
movsbl (%rbx),%edi
call   1060 <c_unescape_char@plt>
test   %r14,%r14
je     11a3 <c_unescape_char_ptr+0x63>
add    $0x1,%rbx
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define signext i8 @c_unescape_char_ptr(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8
store i8* %0, i8** %3
store i8** %1, i8*** %4
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = call signext i8 @toupper(i8 signext %7)
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 88
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
%14 = load i8**, i8*** %4
%15 = call i64 @strtol(i8* %13, i8** %14, i32 16)
%16 = trunc i64 %15 to i8
store i8 %16, i8* %5
br label %41
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = call i64 @isdigit(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
%25 = load i8**, i8*** %4
%26 = call i64 @strtol(i8* %24, i8** %25, i32 8)
%27 = trunc i64 %26 to i8
store i8 %27, i8* %5
br label %40
28: ; preds = %17
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
%31 = load i8, i8* %29
%32 = sext i8 %31 to i32
%33 = call signext i8 @c_unescape_char(i32 %32)
store i8 %33, i8* %5
%34 = load i8**, i8*** %4
%35 = icmp ne i8** %34, null
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i8*, i8** %3
%38 = load i8**, i8*** %4
store i8* %37, i8** %38
br label %39
39: ; preds = %36, %28
br label %40
40: ; preds = %39, %22
br label %41
41: ; preds = %40, %11
%42 = load i8, i8* %5
ret i8 %42
}

LLVM IR (-O2):
define signext i8 @c_unescape_char_ptr(i8* %0, i8** %1) {
%3 = load i8, i8* %0
%4 = tail call signext i8 @toupper(i8 signext %3)
%5 = icmp eq i8 %4, 88
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = tail call i64 @strtol(i8* %7, i8** %1, i32 16)
%9 = trunc i64 %8 to i8
br label %25
10: ; preds = %2
%11 = load i8, i8* %0
%12 = tail call i64 @isdigit(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %0, i64 1
%16 = tail call i64 @strtol(i8* %15, i8** %1, i32 8)
%17 = trunc i64 %16 to i8
br label %25
18: ; preds = %10
%19 = load i8, i8* %0
%20 = sext i8 %19 to i32
%21 = tail call signext i8 @c_unescape_char(i32 %20)
%22 = icmp eq i8** %1, null
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = getelementptr inbounds i8, i8* %0, i64 1
store i8* %24, i8** %1
br label %25
25: ; preds = %14, %23, %18, %6
%26 = phi i8 [ %9, %6 ], [ %17, %14 ], [ %21, %23 ], [ %21, %18 ]
ret i8 %26
}