#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);
scalar_t__ strlen(char *);
void construct_include_directive_marker(char **include_directive_marker,
                                        char *includemarker_input) {
  int len = (int)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,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
lea    0x12(%rax),%edi
call   1050 <malloc@plt>
mov    %rbx,%rdi
mov    %rax,0x0(%r13)
mov    (%rbx),%cl
xor    %ebx,%ebx
test   %cl,%cl
je     1254 <construct_include_directive_marker+0x124>
test   %r15d,%r15d
jle    1254 <construct_include_directive_marker+0x124>
movslq %r15d,%rax
xor    %r8d,%r8d
mov    $0x1,%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
mov    %rdi,(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r15d,%r15d
jne    11f0 <construct_include_directive_marker+0xc0>
movsbl %cl,%edx
cmp    $0x3f,%edx
jg     1220 <construct_include_directive_marker+0xf0>
cmp    $0x25,%edx
je     11af <construct_include_directive_marker+0x7f>
cmp    $0x3f,%edx
jne    1244 <construct_include_directive_marker+0x114>
mov    0x0(%r13),%rcx
movslq %ebx,%rdx
movb   $0x25,(%rcx,%rdx,1)
mov    0x0(%r13),%rcx
movb   $0x73,0x1(%rdx,%rcx,1)
add    $0x2,%ebx
lea    0x1(%r8),%r14d
xor    %r15d,%r15d
cmp    $0x3,%r8d
jl     1237 <construct_include_directive_marker+0x107>
lea    0xe26(%rip),%rdi
mov    %rax,%r12
call   1030 <bug@plt>
mov    %r12,%rax
mov    (%rsp),%rdi
mov    %r14d,%r8d
jmp    1200 <construct_include_directive_marker+0xd0>
xchg   %ax,%ax
mov    0x0(%r13),%rdx
movslq %ebx,%rbx
mov    %cl,(%rdx,%rbx,1)
add    $0x1,%ebx
xor    %r15d,%r15d
movzbl (%rdi,%rbp,1),%ecx
test   %cl,%cl
je     1250 <construct_include_directive_marker+0x120>
lea    0x1(%rbp),%rdx
cmp    %rax,%rbp
mov    %rdx,%rbp
jl     1190 <construct_include_directive_marker+0x60>
jmp    1250 <construct_include_directive_marker+0x120>
nopw   0x0(%rax,%rax,1)
cmp    $0x5c,%edx
je     123c <construct_include_directive_marker+0x10c>
cmp    $0x40,%edx
jne    1244 <construct_include_directive_marker+0x114>
mov    0x0(%r13),%rcx
movslq %ebx,%rdx
movb   $0x20,(%rcx,%rdx,1)
jmp    11fa <construct_include_directive_marker+0xca>
mov    %r14d,%r8d
jmp    1200 <construct_include_directive_marker+0xd0>
mov    $0x1,%r15d
jmp    1200 <construct_include_directive_marker+0xd0>
mov    0x0(%r13),%rdx
movslq %ebx,%rsi
mov    %cl,(%rdx,%rsi,1)
jmp    11fa <construct_include_directive_marker+0xca>
mov    0x0(%r13),%rax
movslq %ebx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    0x0(%r13),%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 i64 @strlen(i8* %11)
%13 = trunc i64 %12 to i32
store i32 %13, i32* %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 18
%16 = call i8* @malloc(i32 %15)
%17 = load i8**, i8*** %3
store i8* %16, i8** %17
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
store i8 %19, i8* %6
br label %20
20: ; preds = %85, %2
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* %7
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br label %28
28: ; preds = %24, %20
%29 = phi i1 [ false, %20 ], [ %27, %24 ]
br i1 %29, label %30, label %93
30: ; preds = %28
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load i8, i8* %6
%35 = load i8**, i8*** %3
%36 = load i8*, i8** %35
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 %34, i8* %39
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
store i32 0, i32* %9
br label %85
42: ; preds = %30
%43 = load i8, i8* %6
%44 = sext i8 %43 to i32
switch i32 %44, label %75 [
i32 92, label %45
i32 64, label %46
i32 37, label %54
i32 63, label %54
]
45: ; preds = %42
store i32 1, i32* %9
br label %84
46: ; preds = %42
%47 = load i8**, i8*** %3
%48 = load i8*, i8** %47
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 32, i8* %51
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %84
54: ; preds = %42, %42
%55 = load i8**, i8*** %3
%56 = load i8*, i8** %55
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 37, i8* %59
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
%62 = load i8**, i8*** %3
%63 = load i8*, i8** %62
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 115, i8* %66
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
%71 = icmp sgt i32 %70, 3
br i1 %71, label %72, label %74
72: ; preds = %54
%73 = call i32 @bug(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %74
74: ; preds = %72, %54
br label %84
75: ; preds = %42
%76 = load i8, i8* %6
%77 = load i8**, i8*** %3
%78 = load i8*, i8** %77
%79 = load i32, i32* %8
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
store i8 %76, i8* %81
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
br label %84
84: ; preds = %75, %74, %46, %45
br label %85
85: ; preds = %84, %33
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 1
store i32 %87, i32* %7
%88 = load i8*, i8** %4
%89 = load i32, i32* %7
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8, i8* %88, i64 %90
%92 = load i8, i8* %91
store i8 %92, i8* %6
br label %20
93: ; preds = %28
%94 = load i8**, i8*** %3
%95 = load i8*, i8** %94
%96 = load i32, i32* %8
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
store i8 10, i8* %98
%99 = load i32, i32* %8
%100 = add nsw i32 %99, 1
store i32 %100, i32* %8
%101 = load i8**, i8*** %3
%102 = load i8*, i8** %101
%103 = load i32, i32* %8
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %102, i64 %104
store i8 0, i8* %105
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* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = add nsw i32 %4, 18
%6 = tail call i8* @malloc(i32 %5)
store i8* %6, i8** %0
%7 = load i8, i8* %1
%8 = icmp ne i8 %7, 0
%9 = icmp sgt i32 %4, 0
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %63
11: ; preds = %2
%12 = shl i64 %3, 32
%13 = ashr exact i64 %12, 32
br label %14
14: ; preds = %11, %51
%15 = phi i64 [ 0, %11 ], [ %55, %51 ]
%16 = phi i8 [ %7, %11 ], [ %57, %51 ]
%17 = phi i32 [ 0, %11 ], [ %54, %51 ]
%18 = phi i32 [ 0, %11 ], [ %53, %51 ]
%19 = phi i32 [ 0, %11 ], [ %52, %51 ]
%20 = icmp eq i32 %18, 0
br i1 %20, label %26, label %21
21: ; preds = %14
%22 = load i8*, i8** %0
%23 = sext i32 %19 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8 %16, i8* %24
%25 = add nsw i32 %19, 1
br label %51
26: ; preds = %14
%27 = sext i8 %16 to i32
switch i32 %27, label %46 [
i32 92, label %51
i32 64, label %28
i32 37, label %33
i32 63, label %33
]
28: ; preds = %26
%29 = load i8*, i8** %0
%30 = sext i32 %19 to i64
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8 32, i8* %31
%32 = add nsw i32 %19, 1
br label %51
33: ; preds = %26, %26
%34 = load i8*, i8** %0
%35 = sext i32 %19 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 37, i8* %36
%37 = add nsw i32 %19, 1
%38 = load i8*, i8** %0
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 115, i8* %40
%41 = add nsw i32 %19, 2
%42 = add nsw i32 %17, 1
%43 = icmp sgt i32 %17, 2
br i1 %43, label %44, label %51
44: ; preds = %33
%45 = tail call i32 @bug(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %51
46: ; preds = %26
%47 = load i8*, i8** %0
%48 = sext i32 %19 to i64
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8 %16, i8* %49
%50 = add nsw i32 %19, 1
br label %51
51: ; preds = %26, %28, %46, %44, %33, %21
%52 = phi i32 [ %25, %21 ], [ %50, %46 ], [ %41, %44 ], [ %41, %33 ], [ %32, %28 ], [ %19, %26 ]
%53 = phi i32 [ 0, %21 ], [ 0, %46 ], [ 0, %44 ], [ 0, %33 ], [ 0, %28 ], [ 1, %26 ]
%54 = phi i32 [ %17, %21 ], [ %17, %46 ], [ %42, %44 ], [ %42, %33 ], [ %17, %28 ], [ %17, %26 ]
%55 = add nuw nsw i64 %15, 1
%56 = getelementptr inbounds i8, i8* %1, i64 %55
%57 = load i8, i8* %56
%58 = icmp ne i8 %57, 0
%59 = icmp slt i64 %55, %13
%60 = select i1 %58, i1 %59, i1 false
br i1 %60, label %14, label %61
61: ; preds = %51
%62 = load i8*, i8** %0
br label %63
63: ; preds = %61, %2
%64 = phi i8* [ %6, %2 ], [ %62, %61 ]
%65 = phi i32 [ 0, %2 ], [ %52, %61 ]
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
store i8 10, i8* %67
%68 = add nsw i32 %65, 1
%69 = load i8*, i8** %0
%70 = sext i32 %68 to i64
%71 = getelementptr inbounds i8, i8* %69, i64 %70
store i8 0, i8* %71
ret void
}