#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 */
typedef scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ hex_digit(char const);
scalar_t__ octal_digit(char const);
scalar_t__ read_escape_control_char(char);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
size_t u8_read_escape_sequence(const char *str, size_t ssz, uint32_t *dest) {
  assert(ssz > 0);
  uint32_t ch;
  char digs[10];
  int dno = 0, ndig;
  size_t i = 1;
  char c0 = str[0];
  if (octal_digit(c0)) {
    i = 0;
    do {
      digs[dno++] = str[i++];
    } while (i < ssz && octal_digit(str[i]) && dno < 3);
    digs[dno] = '\0';
    ch = strtol(digs, NULL, 8);
  } else if ((c0 == 'x' && (ndig = 2)) || (c0 == 'u' && (ndig = 4)) ||
             (c0 == 'U' && (ndig = 8))) {
    while (i < ssz && hex_digit(str[i]) && dno < ndig) {
      digs[dno++] = str[i++];
    }
    if (dno == 0)
      return 0;
    digs[dno] = '\0';
    ch = strtol(digs, NULL, 16);
  } else {
    ch = (uint32_t)read_escape_control_char(c0);
  }
  *dest = ch;
  return i;
}


x86 assembly (clang, -O0):
<u8_read_escape_sequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x38(%rbp)
movq   $0x1,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x49(%rbp)
movsbl -0x49(%rbp),%edi
call   1060 <octal_digit@plt>
cmp    $0x0,%rax
je     123f <u8_read_escape_sequence+0xef>
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x48(%rbp)
mov    (%rax,%rcx,1),%cl
mov    -0x38(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x38(%rbp)
cltq
mov    %cl,-0x32(%rbp,%rax,1)
mov    -0x48(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x4a(%rbp)
jae    1210 <u8_read_escape_sequence+0xc0>
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <octal_digit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x4a(%rbp)
je     1210 <u8_read_escape_sequence+0xc0>
cmpl   $0x3,-0x38(%rbp)
setl   %al
mov    %al,-0x4a(%rbp)
mov    -0x4a(%rbp),%al
test   $0x1,%al
jne    11a9 <u8_read_escape_sequence+0x59>
movslq -0x38(%rbp),%rax
movb   $0x0,-0x32(%rbp,%rax,1)
lea    -0x32(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
jmp    136e <u8_read_escape_sequence+0x21e>
movsbl -0x49(%rbp),%eax
cmp    $0x78,%eax
jne    125d <u8_read_escape_sequence+0x10d>
movl   $0x2,-0x3c(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    129e <u8_read_escape_sequence+0x14e>
movsbl -0x49(%rbp),%eax
cmp    $0x75,%eax
jne    127b <u8_read_escape_sequence+0x12b>
movl   $0x4,-0x3c(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    129e <u8_read_escape_sequence+0x14e>
movsbl -0x49(%rbp),%eax
cmp    $0x55,%eax
jne    135c <u8_read_escape_sequence+0x20c>
movl   $0x8,-0x3c(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    129e <u8_read_escape_sequence+0x14e>
jmp    135c <u8_read_escape_sequence+0x20c>
jmp    12a3 <u8_read_escape_sequence+0x153>
mov    -0x48(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x4b(%rbp)
jae    12e5 <u8_read_escape_sequence+0x195>
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <hex_digit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x4b(%rbp)
je     12e5 <u8_read_escape_sequence+0x195>
mov    -0x38(%rbp),%eax
cmp    -0x3c(%rbp),%eax
setl   %al
mov    %al,-0x4b(%rbp)
mov    -0x4b(%rbp),%al
test   $0x1,%al
jne    12f5 <u8_read_escape_sequence+0x1a5>
jmp    1321 <u8_read_escape_sequence+0x1d1>
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x48(%rbp)
mov    (%rax,%rcx,1),%cl
mov    -0x38(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x38(%rbp)
cltq
mov    %cl,-0x32(%rbp,%rax,1)
jmp    12a3 <u8_read_escape_sequence+0x153>
cmpl   $0x0,-0x38(%rbp)
jne    1338 <u8_read_escape_sequence+0x1e8>
movq   $0x0,-0x8(%rbp)
jmp    1381 <u8_read_escape_sequence+0x231>
movslq -0x38(%rbp),%rax
movb   $0x0,-0x32(%rbp,%rax,1)
lea    -0x32(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
jmp    1369 <u8_read_escape_sequence+0x219>
movsbl -0x49(%rbp),%edi
call   1070 <read_escape_control_char@plt>
mov    %rax,-0x28(%rbp)
jmp    136e <u8_read_escape_sequence+0x21e>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u8_read_escape_sequence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
mov    (%r15),%r12b
movsbl %r12b,%ebp
mov    %ebp,%edi
call   1060 <octal_digit@plt>
test   %rax,%rax
je     11cd <u8_read_escape_sequence+0x7d>
cmp    $0x2,%rbx
mov    $0x1,%r12d
cmovae %rbx,%r12
lea    -0x1(%r12),%rbp
xor    %ecx,%ecx
nopl   (%rax)
mov    %rcx,%rbx
movzbl (%r15,%rcx,1),%eax
mov    %al,0xa(%rsp,%rcx,1)
cmp    %rcx,%rbp
je     11f5 <u8_read_escape_sequence+0xa5>
movsbl 0x1(%r15,%rbx,1),%edi
call   1060 <octal_digit@plt>
lea    0x1(%rbx),%rcx
test   %rax,%rax
je     11f8 <u8_read_escape_sequence+0xa8>
cmp    $0x2,%rbx
jb     11a0 <u8_read_escape_sequence+0x50>
jmp    11f8 <u8_read_escape_sequence+0xa8>
cmp    $0x55,%r12b
je     1229 <u8_read_escape_sequence+0xd9>
cmp    $0x78,%r12b
je     123a <u8_read_escape_sequence+0xea>
cmp    $0x75,%r12b
jne    12ad <u8_read_escape_sequence+0x15d>
mov    $0x4,%r13d
cmp    $0x2,%rbx
jb     12cb <u8_read_escape_sequence+0x17b>
jmp    124a <u8_read_escape_sequence+0xfa>
mov    %r12,%rcx
mov    %ecx,%eax
movb   $0x0,0xa(%rsp,%rax,1)
lea    0xa(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <strtol@plt>
add    $0x1,%rbx
mov    %rax,(%r14)
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x8,%r13d
cmp    $0x2,%rbx
jae    124a <u8_read_escape_sequence+0xfa>
jmp    12cb <u8_read_escape_sequence+0x17b>
mov    $0x2,%r13d
cmp    $0x2,%rbx
jb     12cb <u8_read_escape_sequence+0x17b>
lea    -0x1(%rbx),%eax
mov    %eax,0x14(%rsp)
lea    -0x1(%rbx),%r12
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%r15,%rbp,1),%edi
call   1030 <hex_digit@plt>
test   %rax,%rax
je     12be <u8_read_escape_sequence+0x16e>
cmp    %r13,%rbp
jae    12be <u8_read_escape_sequence+0x16e>
movzbl 0x1(%r15,%rbp,1),%eax
mov    %al,0xa(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1260 <u8_read_escape_sequence+0x110>
mov    0x14(%rsp),%eax
test   %eax,%eax
je     12cb <u8_read_escape_sequence+0x17b>
mov    %eax,%eax
movb   $0x0,0xa(%rsp,%rax,1)
lea    0xa(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
jmp    1214 <u8_read_escape_sequence+0xc4>
mov    %ebp,%edi
call   1070 <read_escape_control_char@plt>
mov    $0x1,%ebx
jmp    1214 <u8_read_escape_sequence+0xc4>
mov    %rbp,%rbx
add    $0x1,%rbx
mov    %ebp,%eax
test   %eax,%eax
jne    1290 <u8_read_escape_sequence+0x140>
xor    %ebx,%ebx
jmp    1217 <u8_read_escape_sequence+0xc7>

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

LLVM IR (-O2):
define i64 @u8_read_escape_sequence(i8* nocapture %0, i64 %1, i64* nocapture writeonly %2) {
%4 = alloca [10 x i8]
%5 = icmp ne i64 %1, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%9 = load i8, i8* %0
%10 = tail call i64 @octal_digit(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %34, label %12
12: ; preds = %3
%13 = call i64 @llvm.umax.i64(i64 %1, i64 1)
%14 = add i64 %13, -1
br label %15
15: ; preds = %12, %22
%16 = phi i64 [ %17, %22 ], [ 0, %12 ]
%17 = add nuw nsw i64 %16, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %16
%19 = load i8, i8* %18
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %16
store i8 %19, i8* %20
%21 = icmp eq i64 %16, %14
br i1 %21, label %29, label %22
22: ; preds = %15
%23 = getelementptr inbounds i8, i8* %0, i64 %17
%24 = load i8, i8* %23
%25 = tail call i64 @octal_digit(i8 signext %24)
%26 = icmp ne i64 %25, 0
%27 = icmp ult i64 %16, 2
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %15, label %29
29: ; preds = %15, %22
%30 = phi i64 [ %13, %15 ], [ %17, %22 ]
%31 = and i64 %30, 4294967295
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %31
store i8 0, i8* %32
%33 = call i64 @strtol(i8* nocapture %8, i32* null, i32 8)
br label %71
34: ; preds = %3
switch i8 %9, label %69 [
i8 120, label %37
i8 117, label %35
i8 85, label %36
]
35: ; preds = %34
br label %37
36: ; preds = %34
br label %37
37: ; preds = %34, %35, %36
%38 = phi i64 [ 4, %35 ], [ 8, %36 ], [ 2, %34 ]
%39 = icmp ugt i64 %1, 1
br i1 %39, label %40, label %74
40: ; preds = %37
%41 = trunc i64 %1 to i32
%42 = add i32 %41, -1
%43 = add i64 %1, -1
br label %44
44: ; preds = %40, %53
%45 = phi i64 [ 0, %40 ], [ %56, %53 ]
%46 = phi i64 [ 1, %40 ], [ %54, %53 ]
%47 = getelementptr inbounds i8, i8* %0, i64 %46
%48 = load i8, i8* %47
%49 = tail call i64 @hex_digit(i8 signext %48)
%50 = icmp ne i64 %49, 0
%51 = icmp ult i64 %45, %38
%52 = select i1 %50, i1 %51, i1 false
br i1 %52, label %53, label %59
53: ; preds = %44
%54 = add nuw nsw i64 %46, 1
%55 = load i8, i8* %47
%56 = add nuw nsw i64 %45, 1
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %45
store i8 %55, i8* %57
%58 = icmp eq i64 %56, %43
br i1 %58, label %61, label %44
59: ; preds = %44
%60 = trunc i64 %45 to i32
br label %61
61: ; preds = %53, %59
%62 = phi i32 [ %60, %59 ], [ %42, %53 ]
%63 = phi i64 [ %46, %59 ], [ %1, %53 ]
%64 = icmp eq i32 %62, 0
br i1 %64, label %74, label %65
65: ; preds = %61
%66 = zext i32 %62 to i64
%67 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %66
store i8 0, i8* %67
%68 = call i64 @strtol(i8* nocapture %8, i32* null, i32 16)
br label %71
69: ; preds = %34
%70 = tail call i64 @read_escape_control_char(i8 signext %9)
br label %71
71: ; preds = %65, %69, %29
%72 = phi i64 [ %33, %29 ], [ %68, %65 ], [ %70, %69 ]
%73 = phi i64 [ %17, %29 ], [ %63, %65 ], [ 1, %69 ]
store i64 %72, i64* %2
br label %74
74: ; preds = %37, %61, %71
%75 = phi i64 [ %73, %71 ], [ 0, %61 ], [ 0, %37 ]
ret i64 %75
}