#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 *bfm_malloc(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ is_hex_num(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ push_error(int, int, int, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int parse_escape_characters(char *str, int location) {
  char *buf = bfm_malloc(strlen(str) + 1);
  int i = 0;
  char *c = buf;
  while (str[i]) {
    if (str[i] == '\\') {
      i++;
      switch (str[i]) {
      case 't':
        *c = '\t';
        break;
      case 'n':
        *c = '\n';
        break;
      case 'b':
        *c = '\b';
        break;
      case 'f':
        *c = '\f';
        break;
      case 'r':
        *c = '\r';
        break;
      case 'x':
        if (strlen(&str[i]) < 3)
          push_error(location + i, 1, 1, "malformed escape sequence.");
        char num[3];
        strncpy(num, &str[i + 1], 2);
        num[2] = '\0';
        if (!is_hex_num(num))
          push_error(location + i, 1, 1, "malformed escape sequence.");
        *c = (char)strtol(num, NULL, 16);
        i += 2;
        break;
      default:
        *c = str[i];
        break;
      }
      c++;
    } else {
      *c = str[i];
      c++;
    }
    i++;
  }
  *c = '\0';
  memcpy(str, buf, (c - buf) + 1);
  free(buf);
  return (int)(c - buf);
}


x86 assembly (clang, -O0):
<parse_escape_characters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1070 <bfm_malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1346 <parse_escape_characters+0x1c6>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    131b <parse_escape_characters+0x19b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x16,%eax
ja     12f9 <parse_escape_characters+0x179>
mov    -0x38(%rbp),%rax
lea    0xdf2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x28(%rbp),%rax
movb   $0x9,(%rax)
jmp    130a <parse_escape_characters+0x18a>
mov    -0x28(%rbp),%rax
movb   $0xa,(%rax)
jmp    130a <parse_escape_characters+0x18a>
mov    -0x28(%rbp),%rax
movb   $0x8,(%rax)
jmp    130a <parse_escape_characters+0x18a>
mov    -0x28(%rbp),%rax
movb   $0xc,(%rax)
jmp    130a <parse_escape_characters+0x18a>
mov    -0x28(%rbp),%rax
movb   $0xd,(%rax)
jmp    130a <parse_escape_characters+0x18a>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x3,%eax
jge    1285 <parse_escape_characters+0x105>
mov    -0xc(%rbp),%edi
add    -0x1c(%rbp),%edi
mov    $0x1,%edx
lea    0xdde(%rip),%rcx
mov    %edx,%esi
call   1090 <push_error@plt>
lea    -0x2b(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rsi
mov    $0x2,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x29(%rbp)
lea    -0x2b(%rbp),%rdi
call   1060 <is_hex_num@plt>
cmp    $0x0,%eax
jne    12d1 <parse_escape_characters+0x151>
mov    -0xc(%rbp),%edi
add    -0x1c(%rbp),%edi
mov    $0x1,%edx
lea    0xd92(%rip),%rcx
mov    %edx,%esi
call   1090 <push_error@plt>
lea    -0x2b(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    130a <parse_escape_characters+0x18a>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1338 <parse_escape_characters+0x1b8>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b5 <parse_escape_characters+0x35>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_escape_characters>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <bfm_malloc@plt>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xe51(%rip),%rdx
xor    %ebp,%ebp
jmp    11cb <parse_escape_characters+0x4b>
mov    %al,(%r12,%rbx,1)
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13d
add    $0x1,%rbx
mov    %r13d,%ebp
movslq %ebp,%r15
movzbl (%r14,%r15,1),%eax
cmp    $0x5c,%al
je     11f0 <parse_escape_characters+0x70>
test   %al,%al
je     12cf <parse_escape_characters+0x14f>
mov    %al,(%r12,%rbx,1)
mov    %ebp,%r13d
jmp    11c0 <parse_escape_characters+0x40>
nopl   0x0(%rax,%rax,1)
lea    0x1(%r15),%r13
movsbl 0x1(%r14,%r15,1),%eax
lea    -0x62(%rax),%ecx
ror    %ecx
cmp    $0xb,%ecx
ja     11b3 <parse_escape_characters+0x33>
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
movb   $0x8,(%r12,%rbx,1)
jmp    11c0 <parse_escape_characters+0x40>
movb   $0xc,(%r12,%rbx,1)
jmp    11c0 <parse_escape_characters+0x40>
movb   $0xa,(%r12,%rbx,1)
jmp    11c0 <parse_escape_characters+0x40>
movb   $0xd,(%r12,%rbx,1)
jmp    11c0 <parse_escape_characters+0x40>
movb   $0x9,(%r12,%rbx,1)
jmp    11c0 <parse_escape_characters+0x40>
lea    (%r14,%r15,1),%rdi
add    $0x1,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jg     1261 <parse_escape_characters+0xe1>
mov    0x10(%rsp),%rax
lea    (%rax,%r13,1),%edi
mov    $0x1,%esi
mov    $0x1,%edx
lea    0xdd4(%rip),%rcx
call   1090 <push_error@plt>
lea    (%r15,%r14,1),%rsi
add    $0x2,%rsi
lea    0xd(%rsp),%r15
mov    %r15,%rdi
mov    $0x2,%edx
call   1040 <strncpy@plt>
movb   $0x0,0xf(%rsp)
mov    %r15,%rdi
call   1060 <is_hex_num@plt>
test   %eax,%eax
jne    12aa <parse_escape_characters+0x12a>
add    0x10(%rsp),%r13d
mov    %r13d,%edi
mov    $0x1,%esi
mov    $0x1,%edx
lea    0xd8b(%rip),%rcx
call   1090 <push_error@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %al,(%r12,%rbx,1)
add    $0x3,%ebp
mov    %ebp,%r13d
lea    0xd36(%rip),%rdx
jmp    11c0 <parse_escape_characters+0x40>
movb   $0x0,(%r12,%rbx,1)
lea    0x1(%rbx),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   10a0 <memcpy@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [27 x i8] c"malformed escape sequence.\00"
define i32 @parse_escape_characters(i8* %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = tail call i8* @bfm_malloc(i32 %5)
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
br label %9
9: ; preds = %50, %2
%10 = phi i32 [ 0, %2 ], [ %53, %50 ]
%11 = phi i8* [ %6, %2 ], [ %52, %50 ]
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %49 [
i8 0, label %54
i8 92, label %15
]
15: ; preds = %9
%16 = add nsw i32 %10, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = add nsw i32 %20, -98
%22 = call i32 @llvm.fshl.i32(i32 %21, i32 %21, i32 31)
switch i32 %22, label %48 [
i32 9, label %23
i32 6, label %24
i32 0, label %25
i32 2, label %26
i32 8, label %27
i32 11, label %28
]
23: ; preds = %15
store i8 9, i8* %11
br label %50
24: ; preds = %15
store i8 10, i8* %11
br label %50
25: ; preds = %15
store i8 8, i8* %11
br label %50
26: ; preds = %15
store i8 12, i8* %11
br label %50
27: ; preds = %15
store i8 13, i8* %11
br label %50
28: ; preds = %15
%29 = call i32 @strlen(i8* %18)
%30 = icmp slt i32 %29, 3
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = add nsw i32 %16, %1
%33 = call i32 @push_error(i32 %32, i32 1, i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %31, %28
%35 = add nsw i32 %10, 2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = call i32 @strncpy(i8* %7, i8* %37, i32 2)
store i8 0, i8* %8
%39 = call i32 @is_hex_num(i8* %7)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = add nsw i32 %16, %1
%43 = call i32 @push_error(i32 %42, i32 1, i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %41, %34
%45 = call i64 @strtol(i8* nocapture %7, i32* null, i32 16)
%46 = trunc i64 %45 to i8
store i8 %46, i8* %11
%47 = add nsw i32 %10, 3
br label %50
48: ; preds = %15
store i8 %19, i8* %11
br label %50
49: ; preds = %9
store i8 %14, i8* %11
br label %50
50: ; preds = %23, %24, %25, %26, %27, %44, %48, %49
%51 = phi i32 [ %10, %49 ], [ %16, %48 ], [ %47, %44 ], [ %16, %27 ], [ %16, %26 ], [ %16, %25 ], [ %16, %24 ], [ %16, %23 ]
%52 = getelementptr inbounds i8, i8* %11, i64 1
%53 = add nsw i32 %51, 1
br label %9
54: ; preds = %9
store i8 0, i8* %11
%55 = ptrtoint i8* %11 to i64
%56 = ptrtoint i8* %6 to i64
%57 = sub i64 %55, %56
%58 = trunc i64 %57 to i32
%59 = add i32 %58, 1
%60 = call i32 @memcpy(i8* %0, i8* %6, i32 %59)
%61 = call i32 @free(i8* %6)
ret i32 %58
}