#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ diagnostics(int, char *, ...);
int /*<<< orphan*/ free(char *);
char *getBraceRawParam();
char *getBracketParam();
scalar_t__ isalpha(char);
int /*<<< orphan*/ my_strcpy(char *, char *);
char *my_strdup(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
char *expandmacro(char *macro, char *opt_param, int params) {
  int i = 0, param;
  char *args[9], *dmacro, *macro_piece, *next_piece, *expanded, *buffer = NULL,
                                                                *cs;
  int buff_size = 512;
  diagnostics(5, "expandmacro...");
  diagnostics(5, "expandmacro: contents '%s'", macro);
  diagnostics(5, "expandmacro: optional '%s'", opt_param);
  diagnostics(5, "expandmacro: num args  %d", params);
  if (params <= 0)
    return my_strdup(macro);
  if (opt_param) {
    args[0] = getBracketParam();
    if (!args[0])
      args[0] = my_strdup(opt_param);
    buff_size += (int)strlen(args[0]);
    i = 1;
  }
  for (; i < params; i++) {
    args[i] = getBraceRawParam();
    buff_size += strlen(args[i]);
    diagnostics(5, "Macro #%d --> '%s'", i + 1, args[i]);
  }
  dmacro = my_strdup(macro);
  macro_piece = dmacro;
  buff_size += (int)strlen(macro_piece);
  diagnostics(5, "expandmacro: buff_size = %d\n", buff_size);
  if (buff_size > 0)
    buffer = (char *)calloc(sizeof(char) * buff_size, sizeof(char));
  expanded = buffer;
  while ((cs = strstr(dmacro, "\\csname ")) != NULL)
    my_strcpy(cs + 1, cs + strlen("\\csname "));
  while ((cs = strstr(dmacro, "\\csname")) != NULL)
    my_strcpy(cs + 1, cs + strlen("\\csname"));
  while ((cs = strstr(dmacro, "\\endcsname ")) != NULL)
    my_strcpy(cs, cs + strlen("\\endcsname "));
  while ((cs = strstr(dmacro, "\\endcsname")) != NULL)
    my_strcpy(cs, cs + strlen("\\endcsname"));
  diagnostics(5, "expandmacro: after removing cs crap '%s'", macro_piece);
  while (macro_piece && *macro_piece) {
    param = -1;
    next_piece = strchr(macro_piece, '#');
    if (next_piece) {
      *next_piece = '\0';
      next_piece++;
      if (*next_piece == '#')
        param = 9997;
      else
        param = *next_piece - '1';
      next_piece++;
    }
    diagnostics(5, "expandmacro: next section of macro before '#' is '%s'",
                macro_piece);
    strcpy(expanded, macro_piece);
    expanded += strlen(macro_piece);
    diagnostics(5, "expandmacro: before appending next piece '%s'", buffer);
    if (param > -1) {
      if (param == 9997) {
        diagnostics(5, "expandmacro: found ##, appending # to expanded macro");
        if (expanded + 1 < buffer + buff_size) {
          *expanded = '#';
          expanded++;
        } else
          diagnostics(1, "insufficient buffer to expand macro <%s>", macro);
      } else if (param < params) {
        diagnostics(5, "expandmacro: found #%d appending '%s'", param + 1,
                    args[param]);
        if (expanded + strlen(args[param]) + 1 < buffer + buff_size) {
          char c = *(expanded - 1);
          if (isalpha(c)) {
            *expanded = ' ';
            expanded++;
          }
          strcpy(expanded, args[param]);
          expanded += strlen(args[param]);
        } else
          diagnostics(1,
                      "expandmacro: insufficient buffer to expand macro <%s>",
                      macro);
      } else
        diagnostics(1, "expandmacro: confusing definition in macro=<%s>",
                    macro);
    }
    macro_piece = next_piece;
  }
  expanded = my_strdup(buffer);
  for (i = 0; i < params; i++) {
    if (args[i])
      free(args[i]);
  }
  if (dmacro)
    free(dmacro);
  if (buffer)
    free(buffer);
  diagnostics(4, "expandmacro: result is '%s'", expanded);
  return expanded;
}


x86 assembly (clang, -O0):
<expandmacro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x98(%rbp)
movl   $0x200,-0xa4(%rbp)
mov    $0x5,%edi
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
mov    -0x10(%rbp),%rdx
mov    $0x5,%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
mov    -0x18(%rbp),%rdx
mov    $0x5,%edi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
mov    -0x1c(%rbp),%edx
mov    $0x5,%edi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
cmpl   $0x0,-0x1c(%rbp)
jg     1265 <expandmacro+0xa5>
mov    -0x10(%rbp),%rdi
call   10d0 <my_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    18f9 <expandmacro+0x739>
cmpq   $0x0,-0x18(%rbp)
je     12af <expandmacro+0xef>
mov    $0x0,%al
call   10c0 <getBracketParam@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    1293 <expandmacro+0xd3>
mov    -0x18(%rbp),%rdi
call   10d0 <my_strdup@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
add    -0xa4(%rbp),%eax
mov    %eax,-0xa4(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    12b4 <expandmacro+0xf4>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    131d <expandmacro+0x15d>
mov    $0x0,%al
call   1080 <getBraceRawParam@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
mov    %rcx,-0x70(%rbp,%rax,8)
movslq -0x20(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1060 <strlen@plt>
add    -0xa4(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x20(%rbp),%edx
add    $0x1,%edx
movslq -0x20(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rcx
mov    $0x5,%edi
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12b4 <expandmacro+0xf4>
mov    -0x10(%rbp),%rdi
call   10d0 <my_strdup@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
call   1060 <strlen@plt>
add    -0xa4(%rbp),%eax
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%edx
mov    $0x5,%edi
lea    0xd19(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
cmpl   $0x0,-0xa4(%rbp)
jle    138b <expandmacro+0x1cb>
movslq -0xa4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x78(%rbp),%rdi
lea    0xceb(%rip),%rsi
call   10e0 <strstr@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
je     1403 <expandmacro+0x243>
mov    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xb0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    0xcae(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xb8(%rbp),%rsi
mov    -0xb0(%rbp),%rdi
cltq
add    %rax,%rsi
call   1040 <my_strcpy@plt>
jmp    1399 <expandmacro+0x1d9>
jmp    1408 <expandmacro+0x248>
mov    -0x78(%rbp),%rdi
lea    0xc85(%rip),%rsi
call   10e0 <strstr@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
je     1472 <expandmacro+0x2b2>
mov    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    0xc48(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xc8(%rbp),%rsi
mov    -0xc0(%rbp),%rdi
cltq
add    %rax,%rsi
call   1040 <my_strcpy@plt>
jmp    1408 <expandmacro+0x248>
jmp    1477 <expandmacro+0x2b7>
mov    -0x78(%rbp),%rdi
lea    0xc1e(%rip),%rsi
call   10e0 <strstr@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
je     14dd <expandmacro+0x31d>
mov    -0xa0(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    0xbe5(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xd8(%rbp),%rsi
mov    -0xd0(%rbp),%rdi
cltq
add    %rax,%rsi
call   1040 <my_strcpy@plt>
jmp    1477 <expandmacro+0x2b7>
jmp    14e2 <expandmacro+0x322>
mov    -0x78(%rbp),%rdi
lea    0xbbf(%rip),%rsi
call   10e0 <strstr@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
je     1548 <expandmacro+0x388>
mov    -0xa0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    0xb86(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xe8(%rbp),%rsi
mov    -0xe0(%rbp),%rdi
cltq
add    %rax,%rsi
call   1040 <my_strcpy@plt>
jmp    14e2 <expandmacro+0x322>
mov    -0x80(%rbp),%rdx
mov    $0x5,%edi
lea    0xb5f(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
xor    %eax,%eax
cmpq   $0x0,-0x80(%rbp)
mov    %al,-0xe9(%rbp)
je     1585 <expandmacro+0x3c5>
mov    -0x80(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0xe9(%rbp)
mov    -0xe9(%rbp),%al
test   $0x1,%al
jne    1598 <expandmacro+0x3d8>
jmp    184f <expandmacro+0x68f>
movl   $0xffffffff,-0x24(%rbp)
mov    -0x80(%rbp),%rdi
mov    $0x23,%esi
call   1070 <strchr@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     161f <expandmacro+0x45f>
mov    -0x88(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    15fd <expandmacro+0x43d>
movl   $0x270d,-0x24(%rbp)
jmp    160d <expandmacro+0x44d>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
sub    $0x31,%eax
mov    %eax,-0x24(%rbp)
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
mov    -0x80(%rbp),%rdx
mov    $0x5,%edi
lea    0xab1(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
mov    -0x90(%rbp),%rdi
mov    -0x80(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x80(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x90(%rbp)
mov    -0x98(%rbp),%rdx
mov    $0x5,%edi
lea    0xa9e(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
cmpl   $0xffffffff,-0x24(%rbp)
jle    183f <expandmacro+0x67f>
cmpl   $0x270d,-0x24(%rbp)
jne    170b <expandmacro+0x54b>
mov    $0x5,%edi
lea    0xaa2(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    -0x98(%rbp),%rcx
movslq -0xa4(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    16ef <expandmacro+0x52f>
mov    -0x90(%rbp),%rax
movb   $0x23,(%rax)
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
jmp    1706 <expandmacro+0x546>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xaad(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
jmp    183a <expandmacro+0x67a>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    181e <expandmacro+0x65e>
mov    -0x24(%rbp),%edx
add    $0x1,%edx
movslq -0x24(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rcx
mov    $0x5,%edi
lea    0xa47(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
mov    -0x90(%rbp),%rax
mov    %rax,-0xf8(%rbp)
movslq -0x24(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xf8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    -0x98(%rbp),%rcx
movslq -0xa4(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    1802 <expandmacro+0x642>
mov    -0x90(%rbp),%rax
mov    -0x1(%rax),%al
mov    %al,-0xa5(%rbp)
movsbl -0xa5(%rbp),%edi
call   10b0 <isalpha@plt>
cmp    $0x0,%rax
je     17c4 <expandmacro+0x604>
mov    -0x90(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rdi
movslq -0x24(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
call   1050 <strcpy@plt>
movslq -0x24(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x90(%rbp)
jmp    1819 <expandmacro+0x659>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0x98d(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
jmp    1835 <expandmacro+0x675>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0x9a7(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
jmp    183a <expandmacro+0x67a>
jmp    183f <expandmacro+0x67f>
mov    -0x88(%rbp),%rax
mov    %rax,-0x80(%rbp)
jmp    155f <expandmacro+0x39f>
mov    -0x98(%rbp),%rdi
call   10d0 <my_strdup@plt>
mov    %rax,-0x90(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    18a6 <expandmacro+0x6e6>
movslq -0x20(%rbp),%rax
cmpq   $0x0,-0x70(%rbp,%rax,8)
je     1893 <expandmacro+0x6d3>
movslq -0x20(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1030 <free@plt>
jmp    1898 <expandmacro+0x6d8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1869 <expandmacro+0x6a9>
cmpq   $0x0,-0x78(%rbp)
je     18ba <expandmacro+0x6fa>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x98(%rbp)
je     18d4 <expandmacro+0x714>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
mov    -0x90(%rbp),%rdx
mov    $0x4,%edi
lea    0x91e(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
mov    -0x90(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expandmacro>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe23(%rip),%rsi
xor    %r14d,%r14d
mov    $0x5,%edi
xor    %eax,%eax
call   1090 <diagnostics@plt>
lea    0xe1c(%rip),%rsi
mov    $0x5,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <diagnostics@plt>
lea    0xe21(%rip),%rsi
mov    $0x5,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <diagnostics@plt>
lea    0xe26(%rip),%rsi
mov    $0x5,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <diagnostics@plt>
mov    %ebp,0x4(%rsp)
test   %ebp,%ebp
jle    1277 <expandmacro+0xb7>
mov    %rbx,0x8(%rsp)
test   %r15,%r15
je     128d <expandmacro+0xcd>
xor    %eax,%eax
call   10c0 <getBracketParam@plt>
mov    %rax,0x30(%rsp)
test   %rax,%rax
jne    125d <expandmacro+0x9d>
mov    %r15,%rdi
call   10d0 <my_strdup@plt>
mov    %rax,0x30(%rsp)
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
add    $0x200,%r15d
mov    $0x1,%r14d
jmp    1293 <expandmacro+0xd3>
mov    %rbx,%rdi
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10d0 <my_strdup@plt>
mov    $0x200,%r15d
mov    0x4(%rsp),%eax
mov    %eax,%r12d
cmp    %eax,%r14d
jae    12e7 <expandmacro+0x127>
mov    %r14d,%ebp
lea    0xdb6(%rip),%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <getBraceRawParam@plt>
mov    %rax,%rbx
mov    %rax,0x30(%rsp,%rbp,8)
mov    %rax,%rdi
call   1060 <strlen@plt>
add    %eax,%r15d
add    $0x1,%rbp
mov    $0x5,%edi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1090 <diagnostics@plt>
cmp    %rbp,%r12
jne    12b0 <expandmacro+0xf0>
mov    %r12,0x28(%rsp)
mov    0x8(%rsp),%rdi
call   10d0 <my_strdup@plt>
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,%r12d
lea    0xd65(%rip),%rsi
lea    (%r12,%r15,1),%edx
mov    $0x5,%edi
xor    %eax,%eax
call   1090 <diagnostics@plt>
add    %r15d,%r12d
jle    1331 <expandmacro+0x171>
mov    %r12d,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
jmp    1333 <expandmacro+0x173>
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%r15
lea    0xd4b(%rip),%rsi
mov    %r15,%rdi
call   10e0 <strstr@plt>
test   %rax,%rax
je     138d <expandmacro+0x1cd>
mov    %rax,%rbp
lea    0xd34(%rip),%r14
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbp),%rbx
mov    %r14,%rdi
call   1060 <strlen@plt>
movslq %eax,%rsi
add    %rbp,%rsi
mov    %rbx,%rdi
call   1040 <my_strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10e0 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1360 <expandmacro+0x1a0>
lea    0xd04(%rip),%rsi
mov    %r15,%rdi
call   10e0 <strstr@plt>
test   %rax,%rax
je     13dd <expandmacro+0x21d>
mov    %rax,%rbp
lea    0xced(%rip),%r14
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbp),%rbx
mov    %r14,%rdi
call   1060 <strlen@plt>
movslq %eax,%rsi
add    %rbp,%rsi
mov    %rbx,%rdi
call   1040 <my_strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10e0 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    13b0 <expandmacro+0x1f0>
lea    0xcbc(%rip),%rsi
mov    %r15,%rdi
call   10e0 <strstr@plt>
test   %rax,%rax
je     1429 <expandmacro+0x269>
mov    %rax,%rbp
lea    0xca5(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%rsi
add    %rbp,%rsi
mov    %rbp,%rdi
call   1040 <my_strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10e0 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1400 <expandmacro+0x240>
lea    0xc7c(%rip),%rsi
mov    %r15,%rdi
call   10e0 <strstr@plt>
test   %rax,%rax
je     1479 <expandmacro+0x2b9>
mov    %rax,%rbp
lea    0xc65(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%rsi
add    %rbp,%rsi
mov    %rbp,%rdi
call   1040 <my_strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10e0 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1450 <expandmacro+0x290>
lea    0xc37(%rip),%rsi
mov    $0x5,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <diagnostics@plt>
test   %r15,%r15
mov    0x8(%rsp),%rbp
je     1660 <expandmacro+0x4a0>
movslq %r12d,%rax
mov    0x18(%rsp),%r15
add    %r15,%rax
mov    %rax,0x20(%rsp)
mov    0x10(%rsp),%r14
jmp    14d6 <expandmacro+0x316>
mov    $0x1,%edi
lea    0xd15(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <diagnostics@plt>
mov    %r12,%r15
test   %r14,%r14
je     1660 <expandmacro+0x4a0>
cmpb   $0x0,(%r14)
je     1660 <expandmacro+0x4a0>
mov    %r14,%rbx
mov    %r14,%rdi
mov    $0x23,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1520 <expandmacro+0x360>
mov    %rax,%r14
movb   $0x0,(%rax)
movsbl 0x1(%rax),%eax
lea    -0x31(%rax),%r13d
add    $0x2,%r14
cmp    $0x23,%eax
mov    $0x270d,%eax
cmove  %eax,%r13d
jmp    1529 <expandmacro+0x369>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xffffffff,%r13d
xor    %r14d,%r14d
mov    $0x5,%edi
lea    0xbab(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <diagnostics@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%r12
add    %r15,%r12
mov    $0x5,%edi
lea    0xbb2(%rip),%rsi
mov    0x18(%rsp),%rdx
xor    %eax,%eax
call   1090 <diagnostics@plt>
test   %r13d,%r13d
js     14ca <expandmacro+0x30a>
cmp    $0x270d,%r13d
jne    15b0 <expandmacro+0x3f0>
mov    $0x5,%edi
lea    0xbb6(%rip),%rsi
xor    %eax,%eax
call   1090 <diagnostics@plt>
lea    0x1(%r12),%r15
cmp    0x20(%rsp),%r15
jae    1639 <expandmacro+0x479>
movb   $0x23,(%r12)
jmp    14cd <expandmacro+0x30d>
nop
cmp    0x4(%rsp),%r13d
jge    14b4 <expandmacro+0x2f4>
mov    %r13d,%ebp
add    $0x1,%r13d
mov    0x30(%rsp,%rbp,8),%rbx
mov    $0x5,%edi
lea    0xba6(%rip),%rsi
mov    %r13d,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1090 <diagnostics@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
add    %r12,%rax
add    $0x1,%rax
cmp    0x20(%rsp),%rax
jae    164a <expandmacro+0x48a>
movsbl -0x1(%r12),%edi
call   10b0 <isalpha@plt>
test   %rax,%rax
je     1616 <expandmacro+0x456>
movb   $0x20,(%r12)
add    $0x1,%r12
mov    0x30(%rsp,%rbp,8),%rbx
mov    0x8(%rsp),%rbp
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%r15
add    %r12,%r15
jmp    14cd <expandmacro+0x30d>
mov    $0x1,%edi
lea    0xb67(%rip),%rsi
jmp    14c0 <expandmacro+0x300>
mov    $0x1,%edi
lea    0xb49(%rip),%rsi
mov    0x8(%rsp),%rbp
jmp    14c0 <expandmacro+0x300>
mov    0x18(%rsp),%r12
mov    %r12,%rdi
call   10d0 <my_strdup@plt>
mov    %rax,%r14
cmpl   $0x0,0x4(%rsp)
mov    0x28(%rsp),%rbx
mov    0x10(%rsp),%r15
jle    16aa <expandmacro+0x4ea>
xor    %ebp,%ebp
jmp    1699 <expandmacro+0x4d9>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
cmp    %rbp,%rbx
je     16aa <expandmacro+0x4ea>
mov    0x30(%rsp,%rbp,8),%rdi
test   %rdi,%rdi
je     1690 <expandmacro+0x4d0>
call   1030 <free@plt>
jmp    1690 <expandmacro+0x4d0>
test   %r15,%r15
je     16b7 <expandmacro+0x4f7>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r12,%r12
je     16c4 <expandmacro+0x504>
mov    %r12,%rdi
call   1030 <free@plt>
lea    0xb3a(%rip),%rsi
mov    $0x4,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <diagnostics@plt>
mov    %r14,%rax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"expandmacro...\00"
@.str.1 = [27 x i8] c"expandmacro: contents '%s'\00"
@.str.2 = [27 x i8] c"expandmacro: optional '%s'\00"
@.str.3 = [26 x i8] c"expandmacro: num args %d\00"
@.str.4 = [19 x i8] c"Macro #%d --> '%s'\00"
@.str.5 = [29 x i8] c"expandmacro: buff_size = %d\0A\00"
@.str.6 = [9 x i8] c"\\csname \00"
@.str.7 = [8 x i8] c"\\csname\00"
@.str.8 = [12 x i8] c"\\endcsname \00"
@.str.9 = [11 x i8] c"\\endcsname\00"
@.str.10 = [41 x i8] c"expandmacro: after removing cs crap '%s'\00"
@.str.11 = [54 x i8] c"expandmacro: next section of macro before '#' is '%s'\00"
@.str.12 = [46 x i8] c"expandmacro: before appending next piece '%s'\00"
@.str.13 = [53 x i8] c"expandmacro: found ##, appending # to expanded macro\00"
@.str.14 = [41 x i8] c"insufficient buffer to expand macro <%s>\00"
@.str.15 = [38 x i8] c"expandmacro: found #%d appending '%s'\00"
@.str.16 = [54 x i8] c"expandmacro: insufficient buffer to expand macro <%s>\00"
@.str.17 = [48 x i8] c"expandmacro: confusing definition in macro=<%s>\00"
@.str.18 = [28 x i8] c"expandmacro: result is '%s'\00"
define i8* @expandmacro(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [9 x i8*]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i8* null, i8** %15
store i32 512, i32* %17
%19 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%20 = load i8*, i8** %5
%21 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %6
%23 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %7
%25 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %7
%27 = icmp sle i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %3
%29 = load i8*, i8** %5
%30 = call i8* @my_strdup(i8* %29)
store i8* %30, i8** %4
br label %319
31: ; preds = %3
%32 = load i8*, i8** %6
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %50
34: ; preds = %31
%35 = call i8* (...) @getBracketParam()
%36 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 0
store i8* %35, i8** %36
%37 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 0
%38 = load i8*, i8** %37
%39 = icmp ne i8* %38, null
br i1 %39, label %44, label %40
40: ; preds = %34
%41 = load i8*, i8** %6
%42 = call i8* @my_strdup(i8* %41)
%43 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 0
store i8* %42, i8** %43
br label %44
44: ; preds = %40, %34
%45 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 0
%46 = load i8*, i8** %45
%47 = call i32 @strlen(i8* %46)
%48 = load i32, i32* %17
%49 = add nsw i32 %48, %47
store i32 %49, i32* %17
store i32 1, i32* %8
br label %50
50: ; preds = %44, %31
br label %51
51: ; preds = %74, %50
%52 = load i32, i32* %8
%53 = load i32, i32* %7
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %77
55: ; preds = %51
%56 = call i8* (...) @getBraceRawParam()
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 %58
store i8* %56, i8** %59
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 @strlen(i8* %63)
%65 = load i32, i32* %17
%66 = add nsw i32 %65, %64
store i32 %66, i32* %17
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %68, i8* %72)
br label %74
74: ; preds = %55
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
store i32 %76, i32* %8
br label %51
77: ; preds = %51
%78 = load i8*, i8** %5
%79 = call i8* @my_strdup(i8* %78)
store i8* %79, i8** %11
%80 = load i8*, i8** %11
store i8* %80, i8** %12
%81 = load i8*, i8** %12
%82 = call i32 @strlen(i8* %81)
%83 = load i32, i32* %17
%84 = add nsw i32 %83, %82
store i32 %84, i32* %17
%85 = load i32, i32* %17
%86 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %85)
%87 = load i32, i32* %17
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %96
89: ; preds = %77
%90 = load i32, i32* %17
%91 = sext i32 %90 to i64
%92 = mul i64 1, %91
%93 = trunc i64 %92 to i32
%94 = call i64 @calloc(i32 %93, i32 1)
%95 = inttoptr i64 %94 to i8*
store i8* %95, i8** %15
br label %96
96: ; preds = %89, %77
%97 = load i8*, i8** %15
store i8* %97, i8** %14
br label %98
98: ; preds = %102, %96
%99 = load i8*, i8** %11
%100 = call i8* @strstr(i8* %99, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
store i8* %100, i8** %16
%101 = icmp ne i8* %100, null
br i1 %101, label %102, label %110
102: ; preds = %98
%103 = load i8*, i8** %16
%104 = getelementptr inbounds i8, i8* %103, i64 1
%105 = load i8*, i8** %16
%106 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i8, i8* %105, i64 %107
%109 = call i32 @my_strcpy(i8* %104, i8* %108)
br label %98
110: ; preds = %98
br label %111
111: ; preds = %115, %110
%112 = load i8*, i8** %11
%113 = call i8* @strstr(i8* %112, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
store i8* %113, i8** %16
%114 = icmp ne i8* %113, null
br i1 %114, label %115, label %123
115: ; preds = %111
%116 = load i8*, i8** %16
%117 = getelementptr inbounds i8, i8* %116, i64 1
%118 = load i8*, i8** %16
%119 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i8, i8* %118, i64 %120
%122 = call i32 @my_strcpy(i8* %117, i8* %121)
br label %111
123: ; preds = %111
br label %124
124: ; preds = %128, %123
%125 = load i8*, i8** %11
%126 = call i8* @strstr(i8* %125, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
store i8* %126, i8** %16
%127 = icmp ne i8* %126, null
br i1 %127, label %128, label %135
128: ; preds = %124
%129 = load i8*, i8** %16
%130 = load i8*, i8** %16
%131 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i8, i8* %130, i64 %132
%134 = call i32 @my_strcpy(i8* %129, i8* %133)
br label %124
135: ; preds = %124
br label %136
136: ; preds = %140, %135
%137 = load i8*, i8** %11
%138 = call i8* @strstr(i8* %137, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
store i8* %138, i8** %16
%139 = icmp ne i8* %138, null
br i1 %139, label %140, label %147
140: ; preds = %136
%141 = load i8*, i8** %16
%142 = load i8*, i8** %16
%143 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds i8, i8* %142, i64 %144
%146 = call i32 @my_strcpy(i8* %141, i8* %145)
br label %136
147: ; preds = %136
%148 = load i8*, i8** %12
%149 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i8* %148)
br label %150
150: ; preds = %278, %147
%151 = load i8*, i8** %12
%152 = icmp ne i8* %151, null
br i1 %152, label %153, label %158
153: ; preds = %150
%154 = load i8*, i8** %12
%155 = load i8, i8* %154
%156 = sext i8 %155 to i32
%157 = icmp ne i32 %156, 0
br label %158
158: ; preds = %153, %150
%159 = phi i1 [ false, %150 ], [ %157, %153 ]
br i1 %159, label %160, label %280
160: ; preds = %158
store i32 -1, i32* %9
%161 = load i8*, i8** %12
%162 = call i8* @strchr(i8* %161, i8 signext 35)
store i8* %162, i8** %13
%163 = load i8*, i8** %13
%164 = icmp ne i8* %163, null
br i1 %164, label %165, label %182
165: ; preds = %160
%166 = load i8*, i8** %13
store i8 0, i8* %166
%167 = load i8*, i8** %13
%168 = getelementptr inbounds i8, i8* %167, i32 1
store i8* %168, i8** %13
%169 = load i8*, i8** %13
%170 = load i8, i8* %169
%171 = sext i8 %170 to i32
%172 = icmp eq i32 %171, 35
br i1 %172, label %173, label %174
173: ; preds = %165
store i32 9997, i32* %9
br label %179
174: ; preds = %165
%175 = load i8*, i8** %13
%176 = load i8, i8* %175
%177 = sext i8 %176 to i32
%178 = sub nsw i32 %177, 49
store i32 %178, i32* %9
br label %179
179: ; preds = %174, %173
%180 = load i8*, i8** %13
%181 = getelementptr inbounds i8, i8* %180, i32 1
store i8* %181, i8** %13
br label %182
182: ; preds = %179, %160
%183 = load i8*, i8** %12
%184 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.11, i64 0, i64 0), i8* %183)
%185 = load i8*, i8** %14
%186 = load i8*, i8** %12
%187 = call i32 @strcpy(i8* %185, i8* %186)
%188 = load i8*, i8** %12
%189 = call i32 @strlen(i8* %188)
%190 = load i8*, i8** %14
%191 = sext i32 %189 to i64
%192 = getelementptr inbounds i8, i8* %190, i64 %191
store i8* %192, i8** %14
%193 = load i8*, i8** %15
%194 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.12, i64 0, i64 0), i8* %193)
%195 = load i32, i32* %9
%196 = icmp sgt i32 %195, -1
br i1 %196, label %197, label %278
197: ; preds = %182
%198 = load i32, i32* %9
%199 = icmp eq i32 %198, 9997
br i1 %199, label %200, label %217
200: ; preds = %197
%201 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.13, i64 0, i64 0))
%202 = load i8*, i8** %14
%203 = getelementptr inbounds i8, i8* %202, i64 1
%204 = load i8*, i8** %15
%205 = load i32, i32* %17
%206 = sext i32 %205 to i64
%207 = getelementptr inbounds i8, i8* %204, i64 %206
%208 = icmp ult i8* %203, %207
br i1 %208, label %209, label %213
209: ; preds = %200
%210 = load i8*, i8** %14
store i8 35, i8* %210
%211 = load i8*, i8** %14
%212 = getelementptr inbounds i8, i8* %211, i32 1
store i8* %212, i8** %14
br label %216
213: ; preds = %200
%214 = load i8*, i8** %5
%215 = call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.14, i64 0, i64 0), i8* %214)
br label %216
216: ; preds = %213, %209
br label %277
217: ; preds = %197
%218 = load i32, i32* %9
%219 = load i32, i32* %7
%220 = icmp slt i32 %218, %219
br i1 %220, label %221, label %273
221: ; preds = %217
%222 = load i32, i32* %9
%223 = add nsw i32 %222, 1
%224 = load i32, i32* %9
%225 = sext i32 %224 to i64
%226 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 %225
%227 = load i8*, i8** %226
%228 = call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.15, i64 0, i64 0), i32 %223, i8* %227)
%229 = load i8*, i8** %14
%230 = load i32, i32* %9
%231 = sext i32 %230 to i64
%232 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 %231
%233 = load i8*, i8** %232
%234 = call i32 @strlen(i8* %233)
%235 = sext i32 %234 to i64
%236 = getelementptr inbounds i8, i8* %229, i64 %235
%237 = getelementptr inbounds i8, i8* %236, i64 1
%238 = load i8*, i8** %15
%239 = load i32, i32* %17
%240 = sext i32 %239 to i64
%241 = getelementptr inbounds i8, i8* %238, i64 %240
%242 = icmp ult i8* %237, %241
br i1 %242, label %243, label %269
243: ; preds = %221
%244 = load i8*, i8** %14
%245 = getelementptr inbounds i8, i8* %244, i64 -1
%246 = load i8, i8* %245
store i8 %246, i8* %18
%247 = load i8, i8* %18
%248 = call i64 @isalpha(i8 signext %247)
%249 = icmp ne i64 %248, 0
br i1 %249, label %250, label %254
250: ; preds = %243
%251 = load i8*, i8** %14
store i8 32, i8* %251
%252 = load i8*, i8** %14
%253 = getelementptr inbounds i8, i8* %252, i32 1
store i8* %253, i8** %14
br label %254
254: ; preds = %250, %243
%255 = load i8*, i8** %14
%256 = load i32, i32* %9
%257 = sext i32 %256 to i64
%258 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 %257
%259 = load i8*, i8** %258
%260 = call i32 @strcpy(i8* %255, i8* %259)
%261 = load i32, i32* %9
%262 = sext i32 %261 to i64
%263 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 %262
%264 = load i8*, i8** %263
%265 = call i32 @strlen(i8* %264)
%266 = load i8*, i8** %14
%267 = sext i32 %265 to i64
%268 = getelementptr inbounds i8, i8* %266, i64 %267
store i8* %268, i8** %14
br label %272
269: ; preds = %221
%270 = load i8*, i8** %5
%271 = call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.16, i64 0, i64 0), i8* %270)
br label %272
272: ; preds = %269, %254
br label %276
273: ; preds = %217
%274 = load i8*, i8** %5
%275 = call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.17, i64 0, i64 0), i8* %274)
br label %276
276: ; preds = %273, %272
br label %277
277: ; preds = %276, %216
br label %278
278: ; preds = %277, %182
%279 = load i8*, i8** %13
store i8* %279, i8** %12
br label %150
280: ; preds = %158
%281 = load i8*, i8** %15
%282 = call i8* @my_strdup(i8* %281)
store i8* %282, i8** %14
store i32 0, i32* %8
br label %283
283: ; preds = %300, %280
%284 = load i32, i32* %8
%285 = load i32, i32* %7
%286 = icmp slt i32 %284, %285
br i1 %286, label %287, label %303
287: ; preds = %283
%288 = load i32, i32* %8
%289 = sext i32 %288 to i64
%290 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 %289
%291 = load i8*, i8** %290
%292 = icmp ne i8* %291, null
br i1 %292, label %293, label %299
293: ; preds = %287
%294 = load i32, i32* %8
%295 = sext i32 %294 to i64
%296 = getelementptr inbounds [9 x i8*], [9 x i8*]* %10, i64 0, i64 %295
%297 = load i8*, i8** %296
%298 = call i32 @free(i8* %297)
br label %299
299: ; preds = %293, %287
br label %300
300: ; preds = %299
%301 = load i32, i32* %8
%302 = add nsw i32 %301, 1
store i32 %302, i32* %8
br label %283
303: ; preds = %283
%304 = load i8*, i8** %11
%305 = icmp ne i8* %304, null
br i1 %305, label %306, label %309
306: ; preds = %303
%307 = load i8*, i8** %11
%308 = call i32 @free(i8* %307)
br label %309
309: ; preds = %306, %303
%310 = load i8*, i8** %15
%311 = icmp ne i8* %310, null
br i1 %311, label %312, label %315
312: ; preds = %309
%313 = load i8*, i8** %15
%314 = call i32 @free(i8* %313)
br label %315
315: ; preds = %312, %309
%316 = load i8*, i8** %14
%317 = call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.18, i64 0, i64 0), i8* %316)
%318 = load i8*, i8** %14
store i8* %318, i8** %4
br label %319
319: ; preds = %315, %28
%320 = load i8*, i8** %4
ret i8* %320
}

LLVM IR (-O2):
@.str = [15 x i8] c"expandmacro...\00"
@.str.1 = [27 x i8] c"expandmacro: contents '%s'\00"
@.str.2 = [27 x i8] c"expandmacro: optional '%s'\00"
@.str.3 = [26 x i8] c"expandmacro: num args %d\00"
@.str.4 = [19 x i8] c"Macro #%d --> '%s'\00"
@.str.5 = [29 x i8] c"expandmacro: buff_size = %d\0A\00"
@.str.6 = [9 x i8] c"\\csname \00"
@.str.7 = [8 x i8] c"\\csname\00"
@.str.8 = [12 x i8] c"\\endcsname \00"
@.str.9 = [11 x i8] c"\\endcsname\00"
@.str.10 = [41 x i8] c"expandmacro: after removing cs crap '%s'\00"
@.str.11 = [54 x i8] c"expandmacro: next section of macro before '#' is '%s'\00"
@.str.12 = [46 x i8] c"expandmacro: before appending next piece '%s'\00"
@.str.13 = [53 x i8] c"expandmacro: found ##, appending # to expanded macro\00"
@.str.14 = [41 x i8] c"insufficient buffer to expand macro <%s>\00"
@.str.15 = [38 x i8] c"expandmacro: found #%d appending '%s'\00"
@.str.16 = [54 x i8] c"expandmacro: insufficient buffer to expand macro <%s>\00"
@.str.17 = [48 x i8] c"expandmacro: confusing definition in macro=<%s>\00"
@.str.18 = [28 x i8] c"expandmacro: result is '%s'\00"
define i8* @expandmacro(i8* %0, i8* %1, i32 %2) {
%4 = alloca [9 x i8*]
%5 = bitcast [9 x i8*]* %4 to i8*
%6 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%9 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %2)
%10 = icmp slt i32 %2, 1
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i8* @my_strdup(i8* %0)
br label %200
13: ; preds = %3
%14 = icmp eq i8* %1, null
br i1 %14, label %25, label %15
15: ; preds = %13
%16 = tail call i8* (...) @getBracketParam()
%17 = getelementptr inbounds [9 x i8*], [9 x i8*]* %4, i64 0, i64 0
store i8* %16, i8** %17
%18 = icmp eq i8* %16, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i8* @my_strdup(i8* %1)
store i8* %20, i8** %17
br label %21
21: ; preds = %19, %15
%22 = phi i8* [ %20, %19 ], [ %16, %15 ]
%23 = tail call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, 512
br label %25
25: ; preds = %21, %13
%26 = phi i32 [ 1, %21 ], [ 0, %13 ]
%27 = phi i32 [ %24, %21 ], [ 512, %13 ]
%28 = icmp ult i32 %26, %2
br i1 %28, label %29, label %43
29: ; preds = %25
%30 = zext i32 %26 to i64
%31 = zext i32 %2 to i64
br label %32
32: ; preds = %29, %32
%33 = phi i64 [ %30, %29 ], [ %39, %32 ]
%34 = phi i32 [ %27, %29 ], [ %38, %32 ]
%35 = tail call i8* (...) @getBraceRawParam()
%36 = getelementptr inbounds [9 x i8*], [9 x i8*]* %4, i64 0, i64 %33
store i8* %35, i8** %36
%37 = tail call i32 @strlen(i8* %35)
%38 = add nsw i32 %37, %34
%39 = add nuw nsw i64 %33, 1
%40 = trunc i64 %39 to i32
%41 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %40, i8* %35)
%42 = icmp eq i64 %39, %31
br i1 %42, label %43, label %32
43: ; preds = %32, %25
%44 = phi i32 [ %27, %25 ], [ %38, %32 ]
%45 = tail call i8* @my_strdup(i8* %0)
%46 = tail call i32 @strlen(i8* %45)
%47 = add nsw i32 %46, %44
%48 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = icmp sgt i32 %47, 0
br i1 %49, label %50, label %53
50: ; preds = %43
%51 = tail call i64 @calloc(i32 %47, i32 1)
%52 = inttoptr i64 %51 to i8*
br label %53
53: ; preds = %50, %43
%54 = phi i8* [ %52, %50 ], [ null, %43 ]
%55 = tail call i8* @strstr(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %60
57: ; preds = %60, %53
%58 = tail call i8* @strstr(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%59 = icmp eq i8* %58, null
br i1 %59, label %69, label %72
60: ; preds = %53, %60
%61 = phi i8* [ %67, %60 ], [ %55, %53 ]
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %61, i64 %64
%66 = tail call i32 @my_strcpy(i8* %62, i8* %65)
%67 = tail call i8* @strstr(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%68 = icmp eq i8* %67, null
br i1 %68, label %57, label %60
69: ; preds = %72, %57
%70 = tail call i8* @strstr(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%71 = icmp eq i8* %70, null
br i1 %71, label %81, label %84
72: ; preds = %57, %72
%73 = phi i8* [ %79, %72 ], [ %58, %57 ]
%74 = getelementptr inbounds i8, i8* %73, i64 1
%75 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %73, i64 %76
%78 = tail call i32 @my_strcpy(i8* %74, i8* %77)
%79 = tail call i8* @strstr(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%80 = icmp eq i8* %79, null
br i1 %80, label %69, label %72
81: ; preds = %84, %69
%82 = tail call i8* @strstr(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%83 = icmp eq i8* %82, null
br i1 %83, label %100, label %92
84: ; preds = %69, %84
%85 = phi i8* [ %90, %84 ], [ %70, %69 ]
%86 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
%89 = tail call i32 @my_strcpy(i8* %85, i8* %88)
%90 = tail call i8* @strstr(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%91 = icmp eq i8* %90, null
br i1 %91, label %81, label %84
92: ; preds = %81, %92
%93 = phi i8* [ %98, %92 ], [ %82, %81 ]
%94 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %93, i64 %95
%97 = tail call i32 @my_strcpy(i8* %93, i8* %96)
%98 = tail call i8* @strstr(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%99 = icmp eq i8* %98, null
br i1 %99, label %100, label %92
100: ; preds = %92, %81
%101 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i8* %45)
%102 = icmp eq i8* %45, null
br i1 %102, label %176, label %103
103: ; preds = %100
%104 = sext i32 %47 to i64
%105 = getelementptr inbounds i8, i8* %54, i64 %104
br label %106
106: ; preds = %103, %173
%107 = phi i8* [ %54, %103 ], [ %174, %173 ]
%108 = phi i8* [ %45, %103 ], [ %124, %173 ]
%109 = load i8, i8* %108
%110 = icmp eq i8 %109, 0
br i1 %110, label %176, label %111
111: ; preds = %106
%112 = tail call i8* @strchr(i8* %108, i8 signext 35)
%113 = icmp eq i8* %112, null
br i1 %113, label %122, label %114
114: ; preds = %111
store i8 0, i8* %112
%115 = getelementptr inbounds i8, i8* %112, i64 1
%116 = load i8, i8* %115
%117 = icmp eq i8 %116, 35
%118 = sext i8 %116 to i32
%119 = add nsw i32 %118, -49
%120 = getelementptr inbounds i8, i8* %112, i64 2
%121 = select i1 %117, i32 9997, i32 %119
br label %122
122: ; preds = %114, %111
%123 = phi i32 [ -1, %111 ], [ %121, %114 ]
%124 = phi i8* [ null, %111 ], [ %120, %114 ]
%125 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.11, i64 0, i64 0), i8* %108)
%126 = tail call i32 @strcpy(i8* %107, i8* %108)
%127 = tail call i32 @strlen(i8* %108)
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i8, i8* %107, i64 %128
%130 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.12, i64 0, i64 0), i8* %54)
%131 = icmp sgt i32 %123, -1
br i1 %131, label %132, label %173
132: ; preds = %122
%133 = icmp eq i32 %123, 9997
br i1 %133, label %134, label %141
134: ; preds = %132
%135 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.13, i64 0, i64 0))
%136 = getelementptr inbounds i8, i8* %129, i64 1
%137 = icmp ult i8* %136, %105
br i1 %137, label %138, label %139
138: ; preds = %134
store i8 35, i8* %129
br label %173
139: ; preds = %134
%140 = tail call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.14, i64 0, i64 0), i8* %0)
br label %173
141: ; preds = %132
%142 = icmp slt i32 %123, %2
br i1 %142, label %143, label %171
143: ; preds = %141
%144 = add nuw nsw i32 %123, 1
%145 = zext i32 %123 to i64
%146 = getelementptr inbounds [9 x i8*], [9 x i8*]* %4, i64 0, i64 %145
%147 = load i8*, i8** %146
%148 = tail call i32 (i32, i8*, ...) @diagnostics(i32 5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.15, i64 0, i64 0), i32 %144, i8* %147)
%149 = tail call i32 @strlen(i8* %147)
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8, i8* %129, i64 1
%152 = getelementptr inbounds i8, i8* %151, i64 %150
%153 = icmp ult i8* %152, %105
br i1 %153, label %154, label %169
154: ; preds = %143
%155 = getelementptr inbounds i8, i8* %129, i64 -1
%156 = load i8, i8* %155
%157 = tail call i64 @isalpha(i8 signext %156)
%158 = icmp eq i64 %157, 0
br i1 %158, label %162, label %159
159: ; preds = %154
store i8 32, i8* %129
%160 = getelementptr inbounds i8, i8* %129, i64 1
%161 = load i8*, i8** %146
br label %162
162: ; preds = %159, %154
%163 = phi i8* [ %161, %159 ], [ %147, %154 ]
%164 = phi i8* [ %160, %159 ], [ %129, %154 ]
%165 = tail call i32 @strcpy(i8* %164, i8* %163)
%166 = tail call i32 @strlen(i8* %163)
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds i8, i8* %164, i64 %167
br label %173
169: ; preds = %143
%170 = tail call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.16, i64 0, i64 0), i8* %0)
br label %173
171: ; preds = %141
%172 = tail call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.17, i64 0, i64 0), i8* %0)
br label %173
173: ; preds = %139, %138, %162, %169, %171, %122
%174 = phi i8* [ %136, %138 ], [ %129, %139 ], [ %168, %162 ], [ %129, %169 ], [ %129, %171 ], [ %129, %122 ]
%175 = icmp eq i8* %124, null
br i1 %175, label %176, label %106
176: ; preds = %106, %173, %100
%177 = tail call i8* @my_strdup(i8* %54)
%178 = icmp sgt i32 %2, 0
br i1 %178, label %179, label %191
179: ; preds = %176
%180 = zext i32 %2 to i64
br label %181
181: ; preds = %179, %188
%182 = phi i64 [ 0, %179 ], [ %189, %188 ]
%183 = getelementptr inbounds [9 x i8*], [9 x i8*]* %4, i64 0, i64 %182
%184 = load i8*, i8** %183
%185 = icmp eq i8* %184, null
br i1 %185, label %188, label %186
186: ; preds = %181
%187 = tail call i32 @free(i8* %184)
br label %188
188: ; preds = %181, %186
%189 = add nuw nsw i64 %182, 1
%190 = icmp eq i64 %189, %180
br i1 %190, label %191, label %181
191: ; preds = %188, %176
br i1 %102, label %194, label %192
192: ; preds = %191
%193 = tail call i32 @free(i8* %45)
br label %194
194: ; preds = %192, %191
%195 = icmp eq i8* %54, null
br i1 %195, label %198, label %196
196: ; preds = %194
%197 = tail call i32 @free(i8* %54)
br label %198
198: ; preds = %196, %194
%199 = tail call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.18, i64 0, i64 0), i8* %177)
br label %200
200: ; preds = %198, %11
%201 = phi i8* [ %12, %11 ], [ %177, %198 ]
ret i8* %201
}