#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*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
void macroexpand(char *instr, char *exp, char *outstr) {
  while (*instr) {
    if (*instr == '$') {
      strcpy(outstr, exp);
      outstr += strlen(outstr);
      instr++;
    } else {
      *outstr++ = *instr++;
    }
  }
  *outstr = '\0';
}


x86 assembly (clang, -O0):
<macroexpand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11af <macroexpand+0x8f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    1188 <macroexpand+0x68>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <macroexpand+0x8a>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1134 <macroexpand+0x14>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<macroexpand>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
jmp    114c <macroexpand+0x2c>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%r15
movzbl (%r15),%eax
cmp    $0x24,%al
je     1130 <macroexpand+0x10>
test   %al,%al
je     1164 <macroexpand+0x44>
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0x1,%r15
jmp    114c <macroexpand+0x2c>
movb   $0x0,(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @macroexpand(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
br label %7
7: ; preds = %33, %3
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 36
br i1 %15, label %16, label %27
16: ; preds = %11
%17 = load i8*, i8** %6
%18 = load i8*, i8** %5
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
%22 = load i8*, i8** %6
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8* %24, i8** %6
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
br label %33
27: ; preds = %11
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
%30 = load i8, i8* %28
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %6
store i8 %30, i8* %31
br label %33
33: ; preds = %27, %16
br label %7
34: ; preds = %7
%35 = load i8*, i8** %6
store i8 0, i8* %35
ret void
}

LLVM IR (-O2):
define void @macroexpand(i8* nocapture %0, i8* %1, i8* %2) {
br label %4
4: ; preds = %15, %3
%5 = phi i8* [ %0, %3 ], [ %17, %15 ]
%6 = phi i8* [ %2, %3 ], [ %16, %15 ]
%7 = load i8, i8* %5
switch i8 %7, label %13 [
i8 0, label %18
i8 36, label %8
]
8: ; preds = %4
%9 = tail call i32 @strcpy(i8* %6, i8* %1)
%10 = tail call i32 @strlen(i8* %6)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %6, i64 %11
br label %15
13: ; preds = %4
%14 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %7, i8* %6
br label %15
15: ; preds = %13, %8
%16 = phi i8* [ %12, %8 ], [ %14, %13 ]
%17 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
18: ; preds = %4
store i8 0, i8* %6
ret void
}