#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*/ append_file(char **, int *, char *);
char *malloc(int);
char *strchr(char *, char);
int strlen(char *);
char *scan_file_ref(char *str) {
  char *dst, *p, *q;
  int len;
  len = strlen(str) + 1;
  dst = malloc(len);
  if (!dst)
    return 0;
  for (p = dst; p < dst + len - 1;) {
    if (*str != '=' || str[1] != '(') {
      if (*str == '\\' && str[1] == '=') {
        ++str;
      }
      *p++ = *str++;
      continue;
    }
    q = strchr(str, ')');
    if (!q)
      continue;
    *q = 0;
    *p = 0;
    append_file(&dst, &len, str + 2);
    if (!dst)
      return 0;
    p = dst + strlen(dst);
    str = q + 1;
  }
  *p = 0;
  return dst;
}


x86 assembly (clang, -O0):
<scan_file_ref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <scan_file_ref+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    12b6 <scan_file_ref+0x176>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
add    %rdx,%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jae    12a7 <scan_file_ref+0x167>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
jne    11c4 <scan_file_ref+0x84>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x28,%eax
je     1218 <scan_file_ref+0xd8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11f1 <scan_file_ref+0xb1>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3d,%eax
jne    11f1 <scan_file_ref+0xb1>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1187 <scan_file_ref+0x47>
mov    -0x10(%rbp),%rdi
mov    $0x29,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    123a <scan_file_ref+0xfa>
jmp    1187 <scan_file_ref+0x47>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdx
add    $0x2,%rdx
lea    -0x18(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <append_file@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1275 <scan_file_ref+0x135>
movq   $0x0,-0x8(%rbp)
jmp    12b6 <scan_file_ref+0x176>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1187 <scan_file_ref+0x47>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_file_ref>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,0xc(%rsp)
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     125e <scan_file_ref+0x11e>
mov    %rax,%r13
movslq %ebp,%rax
add    %r13,%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%r13
jae    1252 <scan_file_ref+0x112>
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r12
xor    %r15d,%r15d
jmp    11cf <scan_file_ref+0x8f>
nopl   0x0(%rax)
movzbl (%rbx),%eax
mov    %al,0x0(%r13)
add    $0x1,%r13
mov    %rbx,%rbp
add    $0x1,%rbp
mov    0x10(%rsp),%rax
movslq 0xc(%rsp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rbp,%rbx
cmp    %rax,%r13
jae    1252 <scan_file_ref+0x112>
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1230 <scan_file_ref+0xf0>
cmp    $0x3d,%al
jne    11a3 <scan_file_ref+0x63>
mov    $0x3d,%al
cmpb   $0x28,0x1(%rbx)
jne    11a3 <scan_file_ref+0x63>
mov    %rbx,%rdi
mov    $0x29,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1250 <scan_file_ref+0x110>
mov    %rax,%rbp
movb   $0x0,(%rax)
movb   $0x0,0x0(%r13)
add    $0x2,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <append_file@plt>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     1261 <scan_file_ref+0x121>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%r13
add    %rbx,%r13
jmp    11ae <scan_file_ref+0x6e>
nopl   0x0(%rax,%rax,1)
cmpb   $0x3d,0x1(%rbx)
jne    11a0 <scan_file_ref+0x60>
add    $0x1,%rbx
jmp    11a0 <scan_file_ref+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
jmp    1250 <scan_file_ref+0x110>
movb   $0x0,0x0(%r13)
mov    0x10(%rsp),%r15
jmp    1261 <scan_file_ref+0x121>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @scan_file_ref(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %1
store i8* null, i8** %2
br label %83
16: ; preds = %1
%17 = load i8*, i8** %4
store i8* %17, i8** %5
br label %18
18: ; preds = %72, %62, %51, %16
%19 = load i8*, i8** %5
%20 = load i8*, i8** %4
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = icmp ult i8* %19, %24
br i1 %25, label %26, label %80
26: ; preds = %18
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 61
br i1 %30, label %37, label %31
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 40
br i1 %36, label %37, label %57
37: ; preds = %31, %26
%38 = load i8*, i8** %3
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 92
br i1 %41, label %42, label %51
42: ; preds = %37
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 61
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %3
br label %51
51: ; preds = %48, %42, %37
%52 = load i8*, i8** %3
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %3
%54 = load i8, i8* %52
%55 = load i8*, i8** %5
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %5
store i8 %54, i8* %55
br label %18
57: ; preds = %31
%58 = load i8*, i8** %3
%59 = call i8* @strchr(i8* %58, i8 signext 41)
store i8* %59, i8** %6
%60 = load i8*, i8** %6
%61 = icmp ne i8* %60, null
br i1 %61, label %63, label %62
62: ; preds = %57
br label %18
63: ; preds = %57
%64 = load i8*, i8** %6
store i8 0, i8* %64
%65 = load i8*, i8** %5
store i8 0, i8* %65
%66 = load i8*, i8** %3
%67 = getelementptr inbounds i8, i8* %66, i64 2
%68 = call i32 @append_file(i8** %4, i32* %7, i8* %67)
%69 = load i8*, i8** %4
%70 = icmp ne i8* %69, null
br i1 %70, label %72, label %71
71: ; preds = %63
store i8* null, i8** %2
br label %83
72: ; preds = %63
%73 = load i8*, i8** %4
%74 = load i8*, i8** %4
%75 = call i32 @strlen(i8* %74)
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %73, i64 %76
store i8* %77, i8** %5
%78 = load i8*, i8** %6
%79 = getelementptr inbounds i8, i8* %78, i64 1
store i8* %79, i8** %3
br label %18
80: ; preds = %18
%81 = load i8*, i8** %5
store i8 0, i8* %81
%82 = load i8*, i8** %4
store i8* %82, i8** %2
br label %83
83: ; preds = %80, %71, %15
%84 = load i8*, i8** %2
ret i8* %84
}

LLVM IR (-O2):
define i8* @scan_file_ref(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = bitcast i8** %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, 1
store i32 %7, i32* %3
%8 = tail call i8* @malloc(i32 %7)
store i8* %8, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %59, label %10
10: ; preds = %1
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = icmp ult i8* %8, %13
br i1 %14, label %15, label %56
15: ; preds = %10, %37
%16 = phi i8* [ %39, %37 ], [ %8, %10 ]
%17 = phi i8* [ %40, %37 ], [ %0, %10 ]
%18 = load i8, i8* %17
switch i8 %18, label %33 [
i8 92, label %27
i8 61, label %19
]
19: ; preds = %15
%20 = getelementptr inbounds i8, i8* %17, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 40
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = call i8* @strchr(i8* %17, i8 signext 41)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %47
26: ; preds = %23, %26
br label %26
27: ; preds = %15
%28 = getelementptr inbounds i8, i8* %17, i64 1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 61
%31 = select i1 %30, i8* %28, i8* %17
%32 = load i8, i8* %31
br label %33
33: ; preds = %15, %19, %27
%34 = phi i8 [ %32, %27 ], [ %18, %15 ], [ 61, %19 ]
%35 = phi i8* [ %31, %27 ], [ %17, %15 ], [ %17, %19 ]
%36 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %34, i8* %16
br label %37
37: ; preds = %33, %52
%38 = phi i8* [ %24, %52 ], [ %35, %33 ]
%39 = phi i8* [ %55, %52 ], [ %36, %33 ]
%40 = getelementptr inbounds i8, i8* %38, i64 1
%41 = load i8*, i8** %2
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 -1
%45 = getelementptr inbounds i8, i8* %44, i64 %43
%46 = icmp ult i8* %39, %45
br i1 %46, label %15, label %56
47: ; preds = %23
store i8 0, i8* %24
store i8 0, i8* %16
%48 = getelementptr inbounds i8, i8* %17, i64 2
%49 = call i32 @append_file(i8** %2, i32* %3, i8* %48)
%50 = load i8*, i8** %2
%51 = icmp eq i8* %50, null
br i1 %51, label %59, label %52
52: ; preds = %47
%53 = call i32 @strlen(i8* %50)
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %50, i64 %54
br label %37
56: ; preds = %37, %10
%57 = phi i8* [ %8, %10 ], [ %39, %37 ]
store i8 0, i8* %57
%58 = load i8*, i8** %2
br label %59
59: ; preds = %47, %1, %56
%60 = phi i8* [ %58, %56 ], [ null, %1 ], [ null, %47 ]
ret i8* %60
}