#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 */
struct match_tree_head {
  int dummy;
};

/* Variables and functions */
unsigned int match_tree_matching(struct match_tree_head const *, char *,
                                 unsigned int, unsigned char);
__attribute((unused)) void
match_tree_translate(const struct match_tree_head *head, char *text,
                     unsigned int text_len, unsigned char is_greedy,
                     char escape) {
  unsigned int matching_count = 0;
  unsigned int i = 0;
  unsigned int j = 0;
  for (i = 0; i < text_len;) {
    matching_count =
        match_tree_matching(head, text + i, text_len - i, is_greedy);
    if (matching_count > 0) {
      for (j = i; j < i + matching_count; j++) {
        text[j] = escape;
      }
      i += matching_count;
    } else {
      i++;
    }
  }
}


x86 assembly (clang, -O0):
<match_tree_translate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %cl,-0x15(%rbp)
mov    %al,-0x16(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11cc <match_tree_translate+0xbc>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%eax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x20(%rbp),%edx
movzbl -0x15(%rbp),%ecx
call   1030 <match_tree_matching@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jbe    11be <match_tree_translate+0xae>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
jae    11b0 <match_tree_translate+0xa0>
mov    -0x16(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <match_tree_translate+0x74>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11c7 <match_tree_translate+0xb7>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1148 <match_tree_translate+0x38>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_tree_translate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
test   %edx,%edx
je     1197 <match_tree_translate+0x77>
mov    %edx,%ebx
mov    %rdi,%r15
xor    %r12d,%r12d
movzbl %cl,%r13d
movzbl %r8b,%eax
mov    %eax,0xc(%rsp)
jmp    115f <match_tree_translate+0x3f>
nopl   (%rax)
add    $0x1,%r12d
mov    %r12d,%r14d
mov    %r14d,%r12d
cmp    %ebx,%r14d
jae    1197 <match_tree_translate+0x77>
mov    %r12d,%ebp
add    0x10(%rsp),%rbp
mov    %ebx,%edx
sub    %r12d,%edx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13d,%ecx
call   1040 <match_tree_matching@plt>
test   %eax,%eax
je     1150 <match_tree_translate+0x30>
lea    (%rax,%r12,1),%r14d
cmp    %r14d,%r12d
jae    1157 <match_tree_translate+0x37>
mov    %eax,%edx
mov    %rbp,%rdi
mov    0xc(%rsp),%esi
call   1030 <memset@plt>
jmp    1157 <match_tree_translate+0x37>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.match_tree_head = type { i32 }
define void @match_tree_translate(%struct.match_tree_head* %0, i8* %1, i32 %2, i8 zeroext %3, i8 signext %4) {
%6 = alloca %struct.match_tree_head*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store %struct.match_tree_head* %0, %struct.match_tree_head** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8 %3, i8* %9
store i8 %4, i8* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %12
br label %14
14: ; preds = %55, %5
%15 = load i32, i32* %12
%16 = load i32, i32* %8
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %56
18: ; preds = %14
%19 = load %struct.match_tree_head*, %struct.match_tree_head** %6
%20 = load i8*, i8** %7
%21 = load i32, i32* %12
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i32, i32* %8
%25 = load i32, i32* %12
%26 = sub i32 %24, %25
%27 = load i8, i8* %9
%28 = call i32 @match_tree_matching(%struct.match_tree_head* %19, i8* %23, i32 %26, i8 zeroext %27)
store i32 %28, i32* %11
%29 = load i32, i32* %11
%30 = icmp ugt i32 %29, 0
br i1 %30, label %31, label %52
31: ; preds = %18
%32 = load i32, i32* %12
store i32 %32, i32* %13
br label %33
33: ; preds = %45, %31
%34 = load i32, i32* %13
%35 = load i32, i32* %12
%36 = load i32, i32* %11
%37 = add i32 %35, %36
%38 = icmp ult i32 %34, %37
br i1 %38, label %39, label %48
39: ; preds = %33
%40 = load i8, i8* %10
%41 = load i8*, i8** %7
%42 = load i32, i32* %13
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %40, i8* %44
br label %45
45: ; preds = %39
%46 = load i32, i32* %13
%47 = add i32 %46, 1
store i32 %47, i32* %13
br label %33
48: ; preds = %33
%49 = load i32, i32* %11
%50 = load i32, i32* %12
%51 = add i32 %50, %49
store i32 %51, i32* %12
br label %55
52: ; preds = %18
%53 = load i32, i32* %12
%54 = add i32 %53, 1
store i32 %54, i32* %12
br label %55
55: ; preds = %52, %48
br label %14
56: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.match_tree_head = type { i32 }
define void @match_tree_translate(%struct.match_tree_head* %0, i8* %1, i32 %2, i8 zeroext %3, i8 signext %4) {
%6 = icmp eq i32 %2, 0
br i1 %6, label %24, label %7
7: ; preds = %5, %21
%8 = phi i32 [ %22, %21 ], [ 0, %5 ]
%9 = zext i32 %8 to i64
%10 = getelementptr i8, i8* %1, i64 %9
%11 = sub i32 %2, %8
%12 = tail call i32 @match_tree_matching(%struct.match_tree_head* %0, i8* %10, i32 %11, i8 zeroext %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %7
%15 = add i32 %12, %8
%16 = icmp ult i32 %8, %15
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = zext i32 %12 to i64
br label %21
19: ; preds = %7
%20 = add nuw i32 %8, 1
br label %21
21: ; preds = %17, %14, %19
%22 = phi i32 [ %20, %19 ], [ %15, %14 ], [ %15, %17 ]
%23 = icmp ult i32 %22, %2
br i1 %23, label %7, label %24
24: ; preds = %21, %5
ret void
}