#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 tnode {
  int dummy;
};
struct simroot {
  int dummy;
};

/* Variables and functions */
struct tnode *addtree(struct tnode *, char *);
int atoi(char *);
scalar_t__ isalpha(char);
char mgetword(char *, int);
struct simroot *parse(struct tnode *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ printlist(struct simroot *, int);
int /*<<< orphan*/ treeprint(struct tnode *);
int main(int argc, char *argv[]) {
  struct tnode *root;
  char word[1000];
  struct simroot *listroot;
  int len;
  root = NULL;
  while (mgetword(word, 1000) != 'x')
    if (isalpha(word[0]))
      root = addtree(root, word);
  if (argc == 1)
    len = 6;
  else if (argc == 2)
    len = atoi(argv[1]);
  else {
    printf("Incorrect number of arguments.\n");
    return 1;
  }
  listroot = NULL;
  listroot = parse(root, len);
  treeprint(root);
  printf("\nDuplicate list:\n\n");
  printlist(listroot, len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1070 <mgetword@plt>
movsbl %al,%eax
cmp    $0x78,%eax
je     11ed <main+0x6d>
movsbl -0x400(%rbp),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     11e8 <main+0x68>
mov    -0x18(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1060 <addtree@plt>
mov    %rax,-0x18(%rbp)
jmp    11a1 <main+0x21>
cmpl   $0x1,-0x8(%rbp)
jne    1206 <main+0x86>
movl   $0x6,-0x40c(%rbp)
jmp    1245 <main+0xc5>
cmpl   $0x2,-0x8(%rbp)
jne    1228 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x40c(%rbp)
jmp    1240 <main+0xc0>
lea    0xdd1(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1294 <main+0x114>
jmp    1245 <main+0xc5>
movq   $0x0,-0x408(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x40c(%rbp),%esi
call   1090 <parse@plt>
mov    %rax,-0x408(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <treeprint@plt>
lea    0xdaa(%rip),%rdi
call   1040 <printf@plt>
mov    -0x408(%rbp),%rdi
mov    -0x40c(%rbp),%esi
call   10a0 <printlist@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1070 <mgetword@plt>
xor    %ebx,%ebx
cmp    $0x78,%al
jne    11c3 <main+0x43>
cmp    $0x1,%r15d
je     11ff <main+0x7f>
cmp    $0x2,%r15d
jne    1233 <main+0xb3>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
jmp    1204 <main+0x84>
mov    %rsp,%rbp
jmp    11e1 <main+0x61>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x3e8,%esi
call   1070 <mgetword@plt>
cmp    $0x78,%al
je     11a6 <main+0x26>
movsbl (%rsp),%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     11d0 <main+0x50>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <addtree@plt>
mov    %rax,%rbx
jmp    11d0 <main+0x50>
mov    $0x6,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1090 <parse@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <treeprint@plt>
lea    0xdff(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   10a0 <printlist@plt>
xor    %eax,%eax
jmp    1244 <main+0xc4>
lea    0xdc6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tnode = type { i32 }
%struct.simroot = type { i32 }
@.str = [32 x i8] c"Incorrect number of arguments.\0A\00"
@.str.1 = [19 x i8] c"\0ADuplicate list:\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.tnode*
%7 = alloca [1000 x i8]
%8 = alloca %struct.simroot*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.tnode* null, %struct.tnode** %6
br label %10
10: ; preds = %24, %2
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%12 = call signext i8 @mgetword(i8* %11, i32 1000)
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 120
br i1 %14, label %15, label %25
15: ; preds = %10
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%17 = load i8, i8* %16
%18 = call i64 @isalpha(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load %struct.tnode*, %struct.tnode** %6
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%23 = call %struct.tnode* @addtree(%struct.tnode* %21, i8* %22)
store %struct.tnode* %23, %struct.tnode** %6
br label %24
24: ; preds = %20, %15
br label %10
25: ; preds = %10
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 6, i32* %9
br label %40
29: ; preds = %25
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %9
br label %39
37: ; preds = %29
%38 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %50
39: ; preds = %32
br label %40
40: ; preds = %39, %28
store %struct.simroot* null, %struct.simroot** %8
%41 = load %struct.tnode*, %struct.tnode** %6
%42 = load i32, i32* %9
%43 = call %struct.simroot* @parse(%struct.tnode* %41, i32 %42)
store %struct.simroot* %43, %struct.simroot** %8
%44 = load %struct.tnode*, %struct.tnode** %6
%45 = call i32 @treeprint(%struct.tnode* %44)
%46 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%47 = load %struct.simroot*, %struct.simroot** %8
%48 = load i32, i32* %9
%49 = call i32 @printlist(%struct.simroot* %47, i32 %48)
store i32 0, i32* %3
br label %50
50: ; preds = %40, %37
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
%struct.tnode = type { i32 }
%struct.simroot = type { i32 }
@str = [31 x i8] c"Incorrect number of arguments.\00"
@str.2 = [18 x i8] c"\0ADuplicate list:\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = call signext i8 @mgetword(i8* %4, i32 1000)
%6 = icmp eq i8 %5, 120
br i1 %6, label %18, label %7
7: ; preds = %2, %14
%8 = phi %struct.tnode* [ %15, %14 ], [ null, %2 ]
%9 = load i8, i8* %4
%10 = call i64 @isalpha(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = call %struct.tnode* @addtree(%struct.tnode* %8, i8* %4)
br label %14
14: ; preds = %12, %7
%15 = phi %struct.tnode* [ %13, %12 ], [ %8, %7 ]
%16 = call signext i8 @mgetword(i8* %4, i32 1000)
%17 = icmp eq i8 %16, 120
br i1 %17, label %18, label %7
18: ; preds = %14, %2
%19 = phi %struct.tnode* [ null, %2 ], [ %15, %14 ]
switch i32 %0, label %24 [
i32 1, label %26
i32 2, label %20
]
20: ; preds = %18
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
br label %26
24: ; preds = %18
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %32
26: ; preds = %18, %20
%27 = phi i32 [ %23, %20 ], [ 6, %18 ]
%28 = call %struct.simroot* @parse(%struct.tnode* %19, i32 %27)
%29 = call i32 @treeprint(%struct.tnode* %19)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
%31 = call i32 @printlist(%struct.simroot* %28, i32 %27)
br label %32
32: ; preds = %26, %24
%33 = phi i32 [ 0, %26 ], [ 1, %24 ]
ret i32 %33
}