#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*/ bt_add_macro_text(char *, char *, char *, int);
int /*<<< orphan*/ bt_cleanup();
int /*<<< orphan*/ bt_delete_all_macros();
int /*<<< orphan*/ bt_delete_macro(char *);
int /*<<< orphan*/ bt_initialize();
char *bt_macro_text(char *, char *, int);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ isspace(char);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(void) {
  char line[1024];
  int line_num;
  int i;
  char action;
  char *macro;
  char *text;
  bt_initialize();
  line_num = 0;
  while (!feof(stdin)) {
    if (fgets(line, 1024, stdin)) {
      line_num++;
      action = line[0];
      if (action != 'l') {
        line[1] = (char)0;
        i = 2;
        macro = line + 2;
        while (!isspace(line[i]))
          i++;
        line[i++] = (char)0;
        text = line + i;
        text[strlen(text) - 1] = (char)0;
      }
      switch (action) {
      case 'a':
        bt_add_macro_text(macro, text, "stdin", line_num);
        break;
      case 'p':
        text = bt_macro_text(macro, "stdin", line_num);
        if (text)
          printf("%s\n", text);
        break;
      case 'd':
        bt_delete_macro(macro);
        break;
      case 'l':
        bt_delete_all_macros();
        break;
      default:
        fprintf(stderr, "unknown command '%c'\n", action);
      }
    }
  }
  bt_cleanup();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10c0 <bt_initialize@plt>
movl   $0x0,-0x414(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1206 <main+0x46>
jmp    13f6 <main+0x236>
lea    -0x410(%rbp),%rdi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     13f1 <main+0x231>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
mov    -0x410(%rbp),%al
mov    %al,-0x419(%rbp)
movsbl -0x419(%rbp),%eax
cmp    $0x6c,%eax
je     1315 <main+0x155>
movb   $0x0,-0x40f(%rbp)
movl   $0x2,-0x418(%rbp)
lea    -0x410(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x428(%rbp)
movslq -0x418(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edi
ff
call   1070 <isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12a1 <main+0xe1>
jmp    12b5 <main+0xf5>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    1278 <main+0xb8>
mov    -0x418(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x418(%rbp)
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rax
movslq -0x418(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x430(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x438(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movsbl -0x419(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x440(%rbp)
sub    $0xf,%eax
ja     13d0 <main+0x210>
mov    -0x440(%rbp),%rax
lea    0xcc1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x428(%rbp),%rdi
mov    -0x430(%rbp),%rsi
mov    -0x414(%rbp),%ecx
lea    0xcdd(%rip),%rdx
call   1060 <bt_add_macro_text@plt>
jmp    13ec <main+0x22c>
mov    -0x428(%rbp),%rdi
mov    -0x414(%rbp),%edx
lea    0xcbf(%rip),%rsi
call   10d0 <bt_macro_text@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
je     13ae <main+0x1ee>
mov    -0x430(%rbp),%rsi
lea    0xc9d(%rip),%rdi
call   1050 <printf@plt>
jmp    13ec <main+0x22c>
mov    -0x428(%rbp),%rdi
call   10e0 <bt_delete_macro@plt>
jmp    13ec <main+0x22c>
mov    $0x0,%al
call   1040 <bt_delete_all_macros@plt>
jmp    13ec <main+0x22c>
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
lea    0xc6a(%rip),%rsi
movsbl -0x419(%rbp),%edx
call   1090 <fprintf@plt>
jmp    13f1 <main+0x231>
jmp    11e3 <main+0x23>
mov    $0x0,%al
call   10b0 <bt_cleanup@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
xor    %eax,%eax
call   10c0 <bt_initialize@plt>
mov    0x2e09(%rip),%r12
mov    (%r12),%edi
call   10a0 <feof@plt>
test   %eax,%eax
je     1207 <main+0x47>
xor    %eax,%eax
call   10b0 <bt_cleanup@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r14
xor    %ebp,%ebp
jmp    1224 <main+0x64>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <bt_delete_all_macros@plt>
mov    (%r12),%edi
call   10a0 <feof@plt>
test   %eax,%eax
jne    11ec <main+0x2c>
mov    (%r12),%edx
mov    %r14,%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     1217 <main+0x57>
add    $0x1,%ebp
movsbl (%rsp),%r13d
cmp    $0x6c,%r13d
je     1210 <main+0x50>
movb   $0x0,0x1(%rsp)
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%rsp,%rbx,1),%edi
call   1070 <isspace@plt>
add    $0x1,%rbx
test   %eax,%eax
je     1260 <main+0xa0>
lea    -0x1(%rbx),%eax
movb   $0x0,(%rsp,%rax,1)
mov    %ebx,%eax
lea    (%rsp,%rax,1),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
lea    -0x61(%r13),%eax
cmp    $0xf,%eax
ja     12d1 <main+0x111>
lea    0xd62(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0x2(%rsp),%rdi
mov    %r15,%rsi
lea    0xd8a(%rip),%rdx
mov    %ebp,%ecx
call   1060 <bt_add_macro_text@plt>
jmp    1217 <main+0x57>
lea    0x2(%rsp),%rdi
call   10e0 <bt_delete_macro@plt>
jmp    1217 <main+0x57>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd69(%rip),%rsi
mov    %r13d,%edx
call   1090 <fprintf@plt>
jmp    1217 <main+0x57>
lea    0x2(%rsp),%rdi
lea    0xd46(%rip),%rsi
mov    %ebp,%edx
call   10d0 <bt_macro_text@plt>
test   %rax,%rax
je     1217 <main+0x57>
lea    0xd35(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
jmp    1217 <main+0x57>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [6 x i8] c"stdin\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"unknown command '%c'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %1
%8 = call i32 (...) @bt_initialize()
store i32 0, i32* %3
br label %9
9: ; preds = %85, %0
%10 = load i32, i32* @stdin
%11 = call i32 @feof(i32 %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %86
14: ; preds = %9
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i64 @fgets(i8* %15, i32 1024, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %85
19: ; preds = %14
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%23 = load i8, i8* %22
store i8 %23, i8* %5
%24 = load i8, i8* %5
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 108
br i1 %26, label %27, label %57
27: ; preds = %19
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1
store i8 0, i8* %28
store i32 2, i32* %4
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 2
store i8* %30, i8** %6
br label %31
31: ; preds = %39, %27
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @isspace(i8 signext %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %31
42: ; preds = %31
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %45
store i8 0, i8* %46
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8* %50, i8** %7
%51 = load i8*, i8** %7
%52 = load i8*, i8** %7
%53 = call i32 @strlen(i8* %52)
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %51, i64 %55
store i8 0, i8* %56
br label %57
57: ; preds = %42, %19
%58 = load i8, i8* %5
%59 = sext i8 %58 to i32
switch i32 %59, label %80 [
i32 97, label %60
i32 112, label %65
i32 100, label %75
i32 108, label %78
]
60: ; preds = %57
%61 = load i8*, i8** %6
%62 = load i8*, i8** %7
%63 = load i32, i32* %3
%64 = call i32 @bt_add_macro_text(i8* %61, i8* %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %63)
br label %84
65: ; preds = %57
%66 = load i8*, i8** %6
%67 = load i32, i32* %3
%68 = call i8* @bt_macro_text(i8* %66, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %67)
store i8* %68, i8** %7
%69 = load i8*, i8** %7
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %65
%72 = load i8*, i8** %7
%73 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %71, %65
br label %84
75: ; preds = %57
%76 = load i8*, i8** %6
%77 = call i32 @bt_delete_macro(i8* %76)
br label %84
78: ; preds = %57
%79 = call i32 (...) @bt_delete_all_macros()
br label %84
80: ; preds = %57
%81 = load i32, i32* @stderr
%82 = load i8, i8* %5
%83 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8 signext %82)
br label %84
84: ; preds = %80, %78, %75, %74, %60
br label %85
85: ; preds = %84, %14
br label %9
86: ; preds = %9
%87 = call i32 (...) @bt_cleanup()
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [6 x i8] c"stdin\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"unknown command '%c'\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @bt_initialize()
%4 = load i32, i32* @stdin
%5 = call i32 @feof(i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %57
7: ; preds = %0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 1
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 2
br label %10
10: ; preds = %7, %52
%11 = phi i32 [ 0, %7 ], [ %53, %52 ]
%12 = load i32, i32* @stdin
%13 = call i64 @fgets(i8* %2, i32 1024, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %52, label %15
15: ; preds = %10
%16 = add nsw i32 %11, 1
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = icmp eq i8 %17, 108
br i1 %19, label %47, label %20
20: ; preds = %15
store i8 0, i8* %8
br label %21
21: ; preds = %21, %20
%22 = phi i64 [ %27, %21 ], [ 2, %20 ]
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @isspace(i8 signext %24)
%26 = icmp eq i32 %25, 0
%27 = add nuw i64 %22, 1
br i1 %26, label %21, label %28
28: ; preds = %21
%29 = and i64 %22, 4294967295
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %29
%31 = add i64 %22, 1
store i8 0, i8* %30
%32 = and i64 %31, 4294967295
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %32
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %34, -1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 0, i8* %37
switch i32 %18, label %49 [
i32 97, label %38
i32 112, label %40
i32 100, label %45
i32 108, label %47
]
38: ; preds = %28
%39 = call i32 @bt_add_macro_text(i8* %9, i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %52
40: ; preds = %28
%41 = call i8* @bt_macro_text(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %16)
%42 = icmp eq i8* %41, null
br i1 %42, label %52, label %43
43: ; preds = %40
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %41)
br label %52
45: ; preds = %28
%46 = call i32 @bt_delete_macro(i8* %9)
br label %52
47: ; preds = %15, %28
%48 = call i32 (...) @bt_delete_all_macros()
br label %52
49: ; preds = %28
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8 signext %17)
br label %52
52: ; preds = %38, %45, %47, %49, %43, %40, %10
%53 = phi i32 [ %16, %49 ], [ %16, %47 ], [ %16, %45 ], [ %16, %43 ], [ %16, %40 ], [ %16, %38 ], [ %11, %10 ]
%54 = load i32, i32* @stdin
%55 = call i32 @feof(i32 %54)
%56 = icmp eq i32 %55, 0
br i1 %56, label %10, label %57
57: ; preds = %52, %0
%58 = call i32 (...) @bt_cleanup()
ret i32 0
}