#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*/ memmove(char *, char *, scalar_t__);
scalar_t__ strlen(char *);
char *strstr(char *, char const *);
char *expand_digraphs(char *line) {
  static const struct {
    const char *from;
    char to;
  } map[] = {{"<:", '['}, {":>", ']'}, {"<%", '{'},
             {"%>", '}'}, {"%:", '#'}, {0, 0}};
  int i;
  for (i = 0; map[i].from; i++) {
    char *pos = line;
    while ((pos = strstr(pos, map[i].from))) {
      *pos = map[i].to;
      memmove(pos + 1, pos + 2, strlen(pos + 2) + 1);
    }
  }
  return line;
}


x86 assembly (clang, -O0):
<expand_digraphs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rcx
lea    0x2c72(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
cmpq   $0x0,(%rax)
je     11ff <expand_digraphs+0xcf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rcx
lea    0x2c4a(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ec <expand_digraphs+0xbc>
movslq -0xc(%rbp),%rcx
lea    0x2c22(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x2,%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <memmove@plt>
jmp    1167 <expand_digraphs+0x37>
jmp    11f1 <expand_digraphs+0xc1>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <expand_digraphs+0x13>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_digraphs>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0xebd(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1195 <expand_digraphs+0x65>
mov    %rax,%rbx
lea    0xea9(%rip),%r15
nopw   0x0(%rax,%rax,1)
movb   $0x5b,(%rbx)
lea    0x1(%rbx),%r12
lea    0x2(%rbx),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <memmove@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <expand_digraphs+0x30>
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     11f5 <expand_digraphs+0xc5>
mov    %rax,%rbx
lea    0xe50(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x5d,(%rbx)
lea    0x1(%rbx),%r12
lea    0x2(%rbx),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <memmove@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <expand_digraphs+0x90>
lea    0xe0a(%rip),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     1255 <expand_digraphs+0x125>
mov    %rax,%rbx
lea    0xdf3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x7b,(%rbx)
lea    0x1(%rbx),%r12
lea    0x2(%rbx),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <memmove@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1220 <expand_digraphs+0xf0>
lea    0xdad(%rip),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     12b5 <expand_digraphs+0x185>
mov    %rax,%rbx
lea    0xd96(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x7d,(%rbx)
lea    0x1(%rbx),%r12
lea    0x2(%rbx),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <memmove@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1280 <expand_digraphs+0x150>
lea    0xd50(%rip),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     1315 <expand_digraphs+0x1e5>
mov    %rax,%rbx
lea    0xd39(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x23,(%rbx)
lea    0x1(%rbx),%r12
lea    0x2(%rbx),%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <memmove@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12e0 <expand_digraphs+0x1b0>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.anon = type { i8*, i8 }
@expand_digraphs.map = internal constant [6 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8 91 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8 93 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8 123 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8 125 }, %struct.anon { i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8 35 }, %struct.anon zeroinitializer]
@.str = [3 x i8] c"<:\00"
@.str.1 = [3 x i8] c":>\00"
@.str.2 = [3 x i8] c"<%\00"
@.str.3 = [3 x i8] c"%>\00"
@.str.4 = [3 x i8] c"%:\00"
define i8* @expand_digraphs(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %40, %1
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [6 x %struct.anon], [6 x %struct.anon]* @expand_digraphs.map, i64 0, i64 %7
%9 = getelementptr inbounds %struct.anon, %struct.anon* %8, i32 0, i32 0
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %43
12: ; preds = %5
%13 = load i8*, i8** %2
store i8* %13, i8** %4
br label %14
14: ; preds = %23, %12
%15 = load i8*, i8** %4
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [6 x %struct.anon], [6 x %struct.anon]* @expand_digraphs.map, i64 0, i64 %17
%19 = getelementptr inbounds %struct.anon, %struct.anon* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i8* @strstr(i8* %15, i8* %20)
store i8* %21, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %39
23: ; preds = %14
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [6 x %struct.anon], [6 x %struct.anon]* @expand_digraphs.map, i64 0, i64 %25
%27 = getelementptr inbounds %struct.anon, %struct.anon* %26, i32 0, i32 1
%28 = load i8, i8* %27
%29 = load i8*, i8** %4
store i8 %28, i8* %29
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 2
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = call i64 @strlen(i8* %35)
%37 = add nsw i64 %36, 1
%38 = call i32 @memmove(i8* %31, i8* %33, i64 %37)
br label %14
39: ; preds = %14
br label %40
40: ; preds = %39
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %5
43: ; preds = %5
%44 = load i8*, i8** %2
ret i8* %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"<:\00"
@.str.1 = [3 x i8] c":>\00"
@.str.2 = [3 x i8] c"<%\00"
@.str.3 = [3 x i8] c"%>\00"
@.str.4 = [3 x i8] c"%:\00"
define i8* @expand_digraphs(i8* returned %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1, %4
%5 = phi i8* [ %11, %4 ], [ %2, %1 ]
store i8 91, i8* %5
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = getelementptr inbounds i8, i8* %5, i64 2
%8 = tail call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 1
%10 = tail call i32 @memmove(i8* %6, i8* %7, i64 %9)
%11 = tail call i8* @strstr(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %4
13: ; preds = %4, %1
%14 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %25, label %16
16: ; preds = %13, %16
%17 = phi i8* [ %23, %16 ], [ %14, %13 ]
store i8 93, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = getelementptr inbounds i8, i8* %17, i64 2
%20 = tail call i64 @strlen(i8* %19)
%21 = add nsw i64 %20, 1
%22 = tail call i32 @memmove(i8* %18, i8* %19, i64 %21)
%23 = tail call i8* @strstr(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %16
25: ; preds = %16, %13
%26 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %37, label %28
28: ; preds = %25, %28
%29 = phi i8* [ %35, %28 ], [ %26, %25 ]
store i8 123, i8* %29
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = getelementptr inbounds i8, i8* %29, i64 2
%32 = tail call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 1
%34 = tail call i32 @memmove(i8* %30, i8* %31, i64 %33)
%35 = tail call i8* @strstr(i8* dereferenceable(1) %29, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %28
37: ; preds = %28, %25
%38 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i8* %38, null
br i1 %39, label %49, label %40
40: ; preds = %37, %40
%41 = phi i8* [ %47, %40 ], [ %38, %37 ]
store i8 125, i8* %41
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = getelementptr inbounds i8, i8* %41, i64 2
%44 = tail call i64 @strlen(i8* %43)
%45 = add nsw i64 %44, 1
%46 = tail call i32 @memmove(i8* %42, i8* %43, i64 %45)
%47 = tail call i8* @strstr(i8* dereferenceable(1) %41, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %40
49: ; preds = %40, %37
%50 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%51 = icmp eq i8* %50, null
br i1 %51, label %61, label %52
52: ; preds = %49, %52
%53 = phi i8* [ %59, %52 ], [ %50, %49 ]
store i8 35, i8* %53
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = getelementptr inbounds i8, i8* %53, i64 2
%56 = tail call i64 @strlen(i8* %55)
%57 = add nsw i64 %56, 1
%58 = tail call i32 @memmove(i8* %54, i8* %55, i64 %57)
%59 = tail call i8* @strstr(i8* dereferenceable(1) %53, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %52
61: ; preds = %52, %49
ret i8* %0
}