#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 */
struct nlist {
  int dummy;
};

/* Variables and functions */
char EOF;
char *getword(char *, char *, int);
int /*<<< orphan*/ install(char *, char *);
scalar_t__ isdefine(char *, char *, char *);
struct nlist *lookup(char *);
int my_getline(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ replace_word(char *, char *, char *, char *);
int strlen(char *);
int main() {
  char line[100];
  char name[100];
  char defn[100];
  struct nlist *np;
  int line_length = 100;
  char word[100];
  char *wordptr, *wordendptr;
  while (line_length > 0) {
    line_length = my_getline(line, 100);
    if (isdefine(line, name, defn)) {
      install(name, defn);
    } else {
      wordptr = line;
      while (*wordptr != '\n' && *wordptr != EOF && (wordptr - line) < 100) {
        wordendptr = getword(wordptr, word, 100);
        np = lookup(word);
        if (np != NULL) {
          replace_word(line, wordptr, wordendptr, defn);
          wordendptr = wordptr + strlen(defn) + 1;
        }
        wordptr = wordendptr;
      }
    }
    printf("%s", line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x15c(%rbp)
cmpl   $0x0,-0x15c(%rbp)
jle    132d <main+0x1ad>
lea    -0x70(%rbp),%rdi
mov    $0x64,%esi
call   10a0 <my_getline@plt>
mov    %eax,-0x15c(%rbp)
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
lea    -0x150(%rbp),%rdx
call   1090 <isdefine@plt>
cmp    $0x0,%rax
je     11f6 <main+0x76>
lea    -0xe0(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   1060 <install@plt>
jmp    1318 <main+0x198>
lea    -0x70(%rbp),%rax
mov    %rax,-0x1c8(%rbp)
mov    -0x1c8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1d1(%rbp)
je     125b <main+0xdb>
mov    -0x1c8(%rbp),%rax
movsbl (%rax),%ecx
mov    0x2dbb(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1d1(%rbp)
je     125b <main+0xdb>
mov    -0x1c8(%rbp),%rax
lea    -0x70(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x64,%rax
setl   %al
mov    %al,-0x1d1(%rbp)
mov    -0x1d1(%rbp),%al
test   $0x1,%al
jne    126e <main+0xee>
jmp    1313 <main+0x193>
mov    -0x1c8(%rbp),%rdi
lea    -0x1c0(%rbp),%rsi
mov    $0x64,%edx
call   1070 <getword@plt>
mov    %rax,-0x1d0(%rbp)
lea    -0x1c0(%rbp),%rdi
call   1080 <lookup@plt>
mov    %rax,-0x158(%rbp)
cmpq   $0x0,-0x158(%rbp)
je     1300 <main+0x180>
lea    -0x70(%rbp),%rdi
mov    -0x1c8(%rbp),%rsi
mov    -0x1d0(%rbp),%rdx
lea    -0x150(%rbp),%rcx
call   1040 <replace_word@plt>
mov    -0x1c8(%rbp),%rax
mov    %rax,-0x1e0(%rbp)
lea    -0x150(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1e0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x1d0(%rbp)
mov    -0x1d0(%rbp),%rax
mov    %rax,-0x1c8(%rbp)
jmp    1201 <main+0x81>
jmp    1318 <main+0x198>
lea    -0x70(%rbp),%rsi
lea    0xcdd(%rip),%rdi
call   1050 <printf@plt>
jmp    119c <main+0x1c>
xor    %eax,%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b8,%rsp
lea    0x70(%rsp),%r13
mov    %rsp,%rbx
lea    0x150(%rsp),%r15
lea    0xe0(%rsp),%r12
jmp    11d5 <main+0x55>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <install@plt>
lea    0xe3e(%rip),%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
test   %ebp,%ebp
mov    %rsp,%rbx
jle    128e <main+0x10e>
mov    %r13,%rdi
mov    $0x64,%esi
call   10a0 <my_getline@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <isdefine@plt>
test   %rax,%rax
jne    11b0 <main+0x30>
mov    0x70(%rsp),%al
cmp    $0xa,%al
je     11bb <main+0x3b>
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%al
je     11bb <main+0x3b>
mov    %r13,%rbx
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x64,%edx
call   1070 <getword@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1080 <lookup@plt>
test   %rax,%rax
je     1260 <main+0xe0>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <replace_word@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%rbx
add    $0x1,%rbx
jmp    1263 <main+0xe3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rbx
mov    %rbx,%rax
sub    %r13,%rax
cmp    $0x63,%rax
jg     11bb <main+0x3b>
movzbl (%rbx),%eax
cmp    $0xa,%al
je     11bb <main+0x3b>
mov    0x2d63(%rip),%rcx
cmp    (%rcx),%al
jne    1210 <main+0x90>
jmp    11bb <main+0x3b>
xor    %eax,%eax
add    $0x1b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlist = type { i32 }
@EOF = global i8 0
@.str = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca %struct.nlist*
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %1
store i32 100, i32* %6
br label %10
10: ; preds = %71, %0
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %74
13: ; preds = %10
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%15 = call i32 @my_getline(i8* %14, i32 100)
store i32 %15, i32* %6
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%19 = call i64 @isdefine(i8* %16, i8* %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%24 = call i32 @install(i8* %22, i8* %23)
br label %71
25: ; preds = %13
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8* %26, i8** %8
br label %27
27: ; preds = %68, %25
%28 = load i8*, i8** %8
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 10
br i1 %31, label %32, label %46
32: ; preds = %27
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = load i8, i8* @EOF
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %35, %37
br i1 %38, label %39, label %46
39: ; preds = %32
%40 = load i8*, i8** %8
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = icmp slt i64 %44, 100
br label %46
46: ; preds = %39, %32, %27
%47 = phi i1 [ false, %32 ], [ false, %27 ], [ %45, %39 ]
br i1 %47, label %48, label %70
48: ; preds = %46
%49 = load i8*, i8** %8
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%51 = call i8* @getword(i8* %49, i8* %50, i32 100)
store i8* %51, i8** %9
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%53 = call %struct.nlist* @lookup(i8* %52)
store %struct.nlist* %53, %struct.nlist** %5
%54 = load %struct.nlist*, %struct.nlist** %5
%55 = icmp ne %struct.nlist* %54, null
br i1 %55, label %56, label %68
56: ; preds = %48
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%58 = load i8*, i8** %8
%59 = load i8*, i8** %9
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%61 = call i32 @replace_word(i8* %57, i8* %58, i8* %59, i8* %60)
%62 = load i8*, i8** %8
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
%67 = getelementptr inbounds i8, i8* %66, i64 1
store i8* %67, i8** %9
br label %68
68: ; preds = %56, %48
%69 = load i8*, i8** %9
store i8* %69, i8** %8
br label %27
70: ; preds = %46
br label %71
71: ; preds = %70, %21
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%73 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %72)
br label %10
74: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
%struct.nlist = type { i32 }
@EOF = global i8 0
@.str = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = ptrtoint [100 x i8]* %1 to i64
br label %10
10: ; preds = %0, %44
%11 = call i32 @my_getline(i8* %5, i32 100)
%12 = call i64 @isdefine(i8* %5, i8* %6, i8* %7)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i8, i8* %5
%16 = icmp ne i8 %15, 10
%17 = load i8, i8* @EOF
%18 = icmp ne i8 %15, %17
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %22, label %44
20: ; preds = %10
%21 = call i32 @install(i8* %6, i8* %7)
br label %44
22: ; preds = %14, %33
%23 = phi i8* [ %34, %33 ], [ %5, %14 ]
%24 = call i8* @getword(i8* %23, i8* %8, i32 100)
%25 = call %struct.nlist* @lookup(i8* %8)
%26 = icmp eq %struct.nlist* %25, null
br i1 %26, label %33, label %27
27: ; preds = %22
%28 = call i32 @replace_word(i8* %5, i8* %23, i8* %24, i8* %7)
%29 = call i32 @strlen(i8* %7)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %23, i64 1
%32 = getelementptr inbounds i8, i8* %31, i64 %30
br label %33
33: ; preds = %27, %22
%34 = phi i8* [ %32, %27 ], [ %24, %22 ]
%35 = load i8, i8* %34
%36 = icmp ne i8 %35, 10
%37 = load i8, i8* @EOF
%38 = icmp ne i8 %35, %37
%39 = select i1 %36, i1 %38, i1 false
%40 = ptrtoint i8* %34 to i64
%41 = sub i64 %40, %9
%42 = icmp slt i64 %41, 100
%43 = and i1 %42, %39
br i1 %43, label %22, label %44
44: ; preds = %33, %14, %20
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%46 = icmp sgt i32 %11, 0
br i1 %46, label %10, label %47
47: ; preds = %44
ret i32 0
}