#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*/ free(char *);
char *globescape(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int main(void) {
  char *string_to_escape;
  char *string_escaped;
  string_escaped = globescape((string_to_escape = "test"));
  if (0 != strcmp(string_escaped, "test")) {
    printf("Error with escaping %s, recieved %s, expected %s\n",
           string_to_escape, string_escaped, "test");
    goto cleanup;
  }
  free(string_escaped);
  string_escaped = globescape((string_to_escape = "[]test"));
  if (0 != strcmp(string_escaped, "\\[]test")) {
    printf("Error with escaping %s, recieved %s, expected %s\n",
           string_to_escape, string_escaped, "\\[]test");
    goto cleanup;
  }
  free(string_escaped);
  string_escaped = globescape((string_to_escape = "test[]"));
  if (0 != strcmp(string_escaped, "test\\[]")) {
    printf("Error with escaping %s, recieved %s, expected %s\n",
           string_to_escape, string_escaped, "test\\[]");
    goto cleanup;
  }
  free(string_escaped);
  string_escaped = globescape((string_to_escape = "[test]"));
  if (0 != strcmp(string_escaped, "\\[test]")) {
    printf("Error with escaping %s, recieved %s, expected %s\n",
           string_to_escape, string_escaped, "\\[test]");
    goto cleanup;
  }
  free(string_escaped);
  string_escaped = globescape((string_to_escape = "\\[test\\]"));
  if (0 != strcmp(string_escaped, "\\\\[test\\]")) {
    printf("Error with escaping %s, recieved %s, expected %s\n",
           string_to_escape, string_escaped, "\\\\[test]\\");
    goto cleanup;
  }
  printf("All tests passed\n");
cleanup:
  free(string_escaped);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xedf(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xed4(%rip),%rdi
call   1060 <globescape@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xec0(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11aa <main+0x6a>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe69(%rip),%rdi
lea    0xe97(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1348 <main+0x208>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe79(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe6e(%rip),%rdi
call   1060 <globescape@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     120e <main+0xce>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe05(%rip),%rdi
lea    0xe30(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1348 <main+0x208>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe1c(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe11(%rip),%rdi
call   1060 <globescape@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1272 <main+0x132>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xda1(%rip),%rdi
lea    0xddb(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1348 <main+0x208>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xdc8(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xdbd(%rip),%rdi
call   1060 <globescape@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12d6 <main+0x196>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd3d(%rip),%rdi
lea    0xd7f(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1348 <main+0x208>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xd6c(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xd61(%rip),%rdi
call   1060 <globescape@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd4c(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     133a <main+0x1fa>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xcd9(%rip),%rdi
lea    0xd2d(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1348 <main+0x208>
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeda(%rip),%rbx
mov    %rbx,%rdi
call   1070 <globescape@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     118c <main+0x3c>
lea    0xe83(%rip),%rdi
lea    0xeb1(%rip),%rcx
mov    %rcx,%rsi
jmp    1298 <main+0x148>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe98(%rip),%rdi
call   1070 <globescape@plt>
mov    %rax,%r14
lea    0xe88(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d1 <main+0x81>
lea    0xe42(%rip),%rdi
lea    0xe6e(%rip),%rsi
lea    0xe66(%rip),%rcx
jmp    1298 <main+0x148>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe5a(%rip),%rdi
call   1070 <globescape@plt>
mov    %rax,%r14
lea    0xe52(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1216 <main+0xc6>
lea    0xdfd(%rip),%rdi
lea    0xe30(%rip),%rsi
lea    0xe30(%rip),%rcx
jmp    1298 <main+0x148>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe25(%rip),%rdi
call   1070 <globescape@plt>
mov    %rax,%r14
lea    0xe15(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1258 <main+0x108>
lea    0xdb8(%rip),%rdi
lea    0xdfb(%rip),%rsi
lea    0xdf3(%rip),%rcx
jmp    1298 <main+0x148>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xdeb(%rip),%rdi
call   1070 <globescape@plt>
mov    %rax,%r14
lea    0xddb(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12b4 <main+0x164>
lea    0xd76(%rip),%rdi
lea    0xdc1(%rip),%rsi
lea    0xdc3(%rip),%rcx
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdaa(%rip),%rdi
call   1040 <puts@plt>
jmp    12a2 <main+0x152>

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@.str.1 = [50 x i8] c"Error with escaping %s, recieved %s, expected %s\0A\00"
@.str.2 = [7 x i8] c"[]test\00"
@.str.3 = [8 x i8] c"\\[]test\00"
@.str.4 = [7 x i8] c"test[]\00"
@.str.5 = [8 x i8] c"test\\[]\00"
@.str.6 = [7 x i8] c"[test]\00"
@.str.7 = [8 x i8] c"\\[test]\00"
@.str.8 = [9 x i8] c"\\[test\\]\00"
@.str.9 = [10 x i8] c"\\\\[test\\]\00"
@.str.10 = [10 x i8] c"\\\\[test]\\\00"
@.str.11 = [18 x i8] c"All tests passed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = call i8* @globescape(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i64 0, %6
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = load i8*, i8** %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %58
12: ; preds = %0
%13 = load i8*, i8** %3
%14 = call i32 @free(i8* %13)
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %2
%15 = call i8* @globescape(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp ne i64 0, %17
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = load i8*, i8** %2
%21 = load i8*, i8** %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %58
23: ; preds = %12
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %2
%26 = call i8* @globescape(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%29 = icmp ne i64 0, %28
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = load i8*, i8** %2
%32 = load i8*, i8** %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %58
34: ; preds = %23
%35 = load i8*, i8** %3
%36 = call i32 @free(i8* %35)
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8** %2
%37 = call i8* @globescape(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
store i8* %37, i8** %3
%38 = load i8*, i8** %3
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%40 = icmp ne i64 0, %39
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = load i8*, i8** %2
%43 = load i8*, i8** %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %58
45: ; preds = %34
%46 = load i8*, i8** %3
%47 = call i32 @free(i8* %46)
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8** %2
%48 = call i8* @globescape(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
store i8* %48, i8** %3
%49 = load i8*, i8** %3
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%51 = icmp ne i64 0, %50
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = load i8*, i8** %2
%54 = load i8*, i8** %3
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* %53, i8* %54, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
br label %58
56: ; preds = %45
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
br label %58
58: ; preds = %56, %52, %41, %30, %19, %8
%59 = load i8*, i8** %3
%60 = call i32 @free(i8* %59)
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@.str.1 = [50 x i8] c"Error with escaping %s, recieved %s, expected %s\0A\00"
@.str.2 = [7 x i8] c"[]test\00"
@.str.3 = [8 x i8] c"\\[]test\00"
@.str.4 = [7 x i8] c"test[]\00"
@.str.5 = [8 x i8] c"test\\[]\00"
@.str.6 = [7 x i8] c"[test]\00"
@.str.7 = [8 x i8] c"\\[test]\00"
@.str.8 = [9 x i8] c"\\[test\\]\00"
@.str.9 = [10 x i8] c"\\\\[test\\]\00"
@.str.10 = [10 x i8] c"\\\\[test]\\\00"
@str = [17 x i8] c"All tests passed\00"
define i32 @main() {
%1 = tail call i8* @globescape(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %36
6: ; preds = %0
%7 = tail call i32 @free(i8* %1)
%8 = tail call i8* @globescape(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %36
13: ; preds = %6
%14 = tail call i32 @free(i8* %8)
%15 = tail call i8* @globescape(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %36
20: ; preds = %13
%21 = tail call i32 @free(i8* %15)
%22 = tail call i8* @globescape(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%23 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %36
27: ; preds = %20
%28 = tail call i32 @free(i8* %22)
%29 = tail call i8* @globescape(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%30 = tail call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %27
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0))
br label %36
34: ; preds = %27
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %34, %32, %25, %18, %11, %4
%37 = phi i8* [ %1, %4 ], [ %8, %11 ], [ %15, %18 ], [ %22, %25 ], [ %29, %32 ], [ %29, %34 ]
%38 = tail call i32 @free(i8* %37)
ret i32 0
}