#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*/ bug(char *);
char *malloc(int);
int strlen(char const *);
void construct_include_directive_marker(char **include_directive_marker,
                                        const char *includemarker_input) {
  int len = strlen(includemarker_input);
  char ch;
  int in_idx = 0, out_idx = 0;
  int quoted = 0, num_repl = 0;
  *include_directive_marker = malloc(len + 18);
  ch = *includemarker_input;
  while (ch != '\0' && in_idx < len) {
    if (quoted) {
      *(*include_directive_marker + out_idx) = ch;
      out_idx++;
      quoted = 0;
    } else {
      switch (ch) {
      case '\\':
        quoted = 1;
        break;
      case '@':
        *(*include_directive_marker + out_idx) = ' ';
        out_idx++;
        break;
      case '%':
      case '?':
        *(*include_directive_marker + out_idx) = '%';
        out_idx++;
        *(*include_directive_marker + out_idx) = 's';
        out_idx++;
        if (++num_repl > 3)
          bug("only 3 substitutions allowed in -includemarker");
        break;
      default:
        *(*include_directive_marker + out_idx) = ch;
        out_idx++;
      }
    }
    in_idx++;
    ch = *(includemarker_input + in_idx);
  }
  *(*include_directive_marker + out_idx) = '\n';
  out_idx++;
  *(*include_directive_marker + out_idx) = '\0';
}


x86 assembly (clang, -O0):
<construct_include_directive_marker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%edi
add    $0x12,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     11a4 <construct_include_directive_marker+0x74>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11b4 <construct_include_directive_marker+0x84>
jmp    12e3 <construct_include_directive_marker+0x1b3>
cmpl   $0x0,-0x24(%rbp)
je     11e4 <construct_include_directive_marker+0xb4>
mov    -0x15(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    12c7 <construct_include_directive_marker+0x197>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x25,%eax
je     1255 <construct_include_directive_marker+0x125>
jmp    11f9 <construct_include_directive_marker+0xc9>
mov    -0x30(%rbp),%eax
sub    $0x3f,%eax
je     1255 <construct_include_directive_marker+0x125>
jmp    120a <construct_include_directive_marker+0xda>
mov    -0x30(%rbp),%eax
sub    $0x40,%eax
je     1238 <construct_include_directive_marker+0x108>
jmp    121b <construct_include_directive_marker+0xeb>
mov    -0x30(%rbp),%eax
sub    $0x5c,%eax
jne    12a8 <construct_include_directive_marker+0x178>
jmp    122c <construct_include_directive_marker+0xfc>
movl   $0x1,-0x24(%rbp)
jmp    12c2 <construct_include_directive_marker+0x192>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x20(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12c2 <construct_include_directive_marker+0x192>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x20(%rbp),%rcx
movb   $0x25,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x20(%rbp),%rcx
movb   $0x73,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmp    $0x3,%eax
jle    12a3 <construct_include_directive_marker+0x173>
lea    0xd62(%rip),%rdi
call   1030 <bug@plt>
jmp    12c2 <construct_include_directive_marker+0x192>
mov    -0x15(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12c7 <construct_include_directive_marker+0x197>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
jmp    1186 <construct_include_directive_marker+0x56>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x20(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<construct_include_directive_marker>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0x12(%r15),%edi
call   1050 <malloc@plt>
mov    %rax,(%r12)
mov    (%r14),%cl
xor    %ebx,%ebx
test   %cl,%cl
je     1264 <construct_include_directive_marker+0x134>
test   %r15d,%r15d
jle    1264 <construct_include_directive_marker+0x134>
mov    %r15d,%edi
xor    %eax,%eax
mov    $0x1,%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
mov    %r12,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %r15d,%r15d
jne    1200 <construct_include_directive_marker+0xd0>
movsbl %cl,%edx
cmp    $0x3f,%edx
jg     1230 <construct_include_directive_marker+0x100>
cmp    $0x25,%edx
je     11af <construct_include_directive_marker+0x7f>
cmp    $0x3f,%edx
jne    1254 <construct_include_directive_marker+0x124>
mov    (%r12),%rcx
movslq %ebx,%rdx
movb   $0x25,(%rcx,%rdx,1)
mov    (%r12),%rcx
movb   $0x73,0x1(%rdx,%rcx,1)
add    $0x2,%ebx
lea    0x1(%rax),%r13d
xor    %r15d,%r15d
cmp    $0x3,%eax
jl     1247 <construct_include_directive_marker+0x117>
mov    %r14,%r12
mov    %rdi,%r14
lea    0xe21(%rip),%rdi
call   1030 <bug@plt>
mov    %r14,%rdi
mov    %r12,%r14
mov    (%rsp),%r12
mov    %r13d,%eax
jmp    1210 <construct_include_directive_marker+0xe0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%rdx
movslq %ebx,%rbx
mov    %cl,(%rdx,%rbx,1)
add    $0x1,%ebx
xor    %r15d,%r15d
movzbl (%r14,%rbp,1),%ecx
test   %cl,%cl
je     1260 <construct_include_directive_marker+0x130>
lea    0x1(%rbp),%rdx
cmp    %rdi,%rbp
mov    %rdx,%rbp
jb     1190 <construct_include_directive_marker+0x60>
jmp    1260 <construct_include_directive_marker+0x130>
nopl   0x0(%rax,%rax,1)
cmp    $0x5c,%edx
je     124c <construct_include_directive_marker+0x11c>
cmp    $0x40,%edx
jne    1254 <construct_include_directive_marker+0x124>
mov    (%r12),%rcx
movslq %ebx,%rdx
movb   $0x20,(%rcx,%rdx,1)
jmp    120a <construct_include_directive_marker+0xda>
mov    %r13d,%eax
jmp    1210 <construct_include_directive_marker+0xe0>
mov    $0x1,%r15d
jmp    1210 <construct_include_directive_marker+0xe0>
mov    (%r12),%rdx
movslq %ebx,%rsi
mov    %cl,(%rdx,%rsi,1)
jmp    120a <construct_include_directive_marker+0xda>
mov    (%r12),%rax
movslq %ebx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    (%r12),%rax
movb   $0x0,0x1(%rcx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"only 3 substitutions allowed in -includemarker\00"
define void @construct_include_directive_marker(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 18
%15 = call i8* @malloc(i32 %14)
%16 = load i8**, i8*** %3
store i8* %15, i8** %16
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
store i8 %18, i8* %6
br label %19
19: ; preds = %84, %2
%20 = load i8, i8* %6
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %7
%25 = load i32, i32* %5
%26 = icmp slt i32 %24, %25
br label %27
27: ; preds = %23, %19
%28 = phi i1 [ false, %19 ], [ %26, %23 ]
br i1 %28, label %29, label %92
29: ; preds = %27
%30 = load i32, i32* %9
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load i8, i8* %6
%34 = load i8**, i8*** %3
%35 = load i8*, i8** %34
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %33, i8* %38
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
store i32 0, i32* %9
br label %84
41: ; preds = %29
%42 = load i8, i8* %6
%43 = sext i8 %42 to i32
switch i32 %43, label %74 [
i32 92, label %44
i32 64, label %45
i32 37, label %53
i32 63, label %53
]
44: ; preds = %41
store i32 1, i32* %9
br label %83
45: ; preds = %41
%46 = load i8**, i8*** %3
%47 = load i8*, i8** %46
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 32, i8* %50
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %83
53: ; preds = %41, %41
%54 = load i8**, i8*** %3
%55 = load i8*, i8** %54
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 37, i8* %58
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
%61 = load i8**, i8*** %3
%62 = load i8*, i8** %61
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 115, i8* %65
%66 = load i32, i32* %8
%67 = add nsw i32 %66, 1
store i32 %67, i32* %8
%68 = load i32, i32* %10
%69 = add nsw i32 %68, 1
store i32 %69, i32* %10
%70 = icmp sgt i32 %69, 3
br i1 %70, label %71, label %73
71: ; preds = %53
%72 = call i32 @bug(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %73
73: ; preds = %71, %53
br label %83
74: ; preds = %41
%75 = load i8, i8* %6
%76 = load i8**, i8*** %3
%77 = load i8*, i8** %76
%78 = load i32, i32* %8
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
store i8 %75, i8* %80
%81 = load i32, i32* %8
%82 = add nsw i32 %81, 1
store i32 %82, i32* %8
br label %83
83: ; preds = %74, %73, %45, %44
br label %84
84: ; preds = %83, %32
%85 = load i32, i32* %7
%86 = add nsw i32 %85, 1
store i32 %86, i32* %7
%87 = load i8*, i8** %4
%88 = load i32, i32* %7
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
%91 = load i8, i8* %90
store i8 %91, i8* %6
br label %19
92: ; preds = %27
%93 = load i8**, i8*** %3
%94 = load i8*, i8** %93
%95 = load i32, i32* %8
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
store i8 10, i8* %97
%98 = load i32, i32* %8
%99 = add nsw i32 %98, 1
store i32 %99, i32* %8
%100 = load i8**, i8*** %3
%101 = load i8*, i8** %100
%102 = load i32, i32* %8
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %101, i64 %103
store i8 0, i8* %104
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"only 3 substitutions allowed in -includemarker\00"
define void @construct_include_directive_marker(i8** nocapture %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 18
%5 = tail call i8* @malloc(i32 %4)
store i8* %5, i8** %0
%6 = load i8, i8* %1
%7 = icmp ne i8 %6, 0
%8 = icmp sgt i32 %3, 0
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %61
10: ; preds = %2
%11 = zext i32 %3 to i64
br label %12
12: ; preds = %10, %49
%13 = phi i64 [ 0, %10 ], [ %53, %49 ]
%14 = phi i8 [ %6, %10 ], [ %55, %49 ]
%15 = phi i32 [ 0, %10 ], [ %52, %49 ]
%16 = phi i32 [ 0, %10 ], [ %51, %49 ]
%17 = phi i32 [ 0, %10 ], [ %50, %49 ]
%18 = icmp eq i32 %16, 0
br i1 %18, label %24, label %19
19: ; preds = %12
%20 = load i8*, i8** %0
%21 = sext i32 %17 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 %14, i8* %22
%23 = add nsw i32 %17, 1
br label %49
24: ; preds = %12
%25 = sext i8 %14 to i32
switch i32 %25, label %44 [
i32 92, label %49
i32 64, label %26
i32 37, label %31
i32 63, label %31
]
26: ; preds = %24
%27 = load i8*, i8** %0
%28 = sext i32 %17 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 32, i8* %29
%30 = add nsw i32 %17, 1
br label %49
31: ; preds = %24, %24
%32 = load i8*, i8** %0
%33 = sext i32 %17 to i64
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 37, i8* %34
%35 = add nsw i32 %17, 1
%36 = load i8*, i8** %0
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8 115, i8* %38
%39 = add nsw i32 %17, 2
%40 = add nsw i32 %15, 1
%41 = icmp sgt i32 %15, 2
br i1 %41, label %42, label %49
42: ; preds = %31
%43 = tail call i32 @bug(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %49
44: ; preds = %24
%45 = load i8*, i8** %0
%46 = sext i32 %17 to i64
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 %14, i8* %47
%48 = add nsw i32 %17, 1
br label %49
49: ; preds = %24, %26, %44, %42, %31, %19
%50 = phi i32 [ %23, %19 ], [ %48, %44 ], [ %39, %42 ], [ %39, %31 ], [ %30, %26 ], [ %17, %24 ]
%51 = phi i32 [ 0, %19 ], [ 0, %44 ], [ 0, %42 ], [ 0, %31 ], [ 0, %26 ], [ 1, %24 ]
%52 = phi i32 [ %15, %19 ], [ %15, %44 ], [ %40, %42 ], [ %40, %31 ], [ %15, %26 ], [ %15, %24 ]
%53 = add nuw nsw i64 %13, 1
%54 = getelementptr inbounds i8, i8* %1, i64 %53
%55 = load i8, i8* %54
%56 = icmp ne i8 %55, 0
%57 = icmp ult i64 %53, %11
%58 = select i1 %56, i1 %57, i1 false
br i1 %58, label %12, label %59
59: ; preds = %49
%60 = load i8*, i8** %0
br label %61
61: ; preds = %59, %2
%62 = phi i8* [ %5, %2 ], [ %60, %59 ]
%63 = phi i32 [ 0, %2 ], [ %50, %59 ]
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 10, i8* %65
%66 = add nsw i32 %63, 1
%67 = load i8*, i8** %0
%68 = sext i32 %66 to i64
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8 0, i8* %69
ret void
}