#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;
};

/* Variables and functions */
scalar_t__ EOF;
struct tnode *addtree(struct tnode *, char *);
int atoi(char *);
scalar_t__ getword(char *, int);
scalar_t__ isalpha(char);
scalar_t__ isdigit(char);
int /*<<< orphan*/ print_groups(char **, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ treesort(struct tnode *, char **, int *);
int main(int argc, char *argv[]) {
  struct tnode *root;
  char word[100];
  char words[100][100];
  char c;
  int same_chars = 6;
  while (--argc > 0 && (*++argv)[0] == '-')
    while ((c = *++argv[0]))
      if (isdigit(c)) {
        same_chars = atoi(*argv);
        break;
      } else {
        printf("\nerror: specify number of head characters");
        argc = -1;
      }
  if (argc != 0) {
    printf("\nUsage: groupwords -#\n\n");
    return -1;
  }
  printf("Sorting on first %d characters\n", same_chars);
  root = NULL;
  while (getword(word, 100) != EOF)
    if (isalpha(word[0])) {
      root = addtree(root, word);
    }
  int zero = 0;
  int *numwords = &zero;
  treesort(root, words, numwords);
  print_groups(words, same_chars, *numwords);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x6,-0x2798(%rbp)
mov    -0x8(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x27a9(%rbp)
jle    11df <main+0x5f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x27a9(%rbp)
mov    -0x27a9(%rbp),%al
test   $0x1,%al
jne    11f2 <main+0x72>
jmp    1265 <main+0xe5>
jmp    11f7 <main+0x77>
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
mov    0x1(%rax),%al
mov    %al,-0x2791(%rbp)
cmp    $0x0,%al
je     1260 <main+0xe0>
movsbl -0x2791(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1246 <main+0xc6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x2798(%rbp)
jmp    1260 <main+0xe0>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x8(%rbp)
jmp    11f7 <main+0x77>
jmp    11a3 <main+0x23>
cmpl   $0x0,-0x8(%rbp)
je     1289 <main+0x109>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133d <main+0x1bd>
mov    -0x2798(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
mov    $0x64,%esi
call   1070 <getword@plt>
mov    0x2d2e(%rip),%rcx
cmp    (%rcx),%rax
je     12ec <main+0x16c>
movsbl -0x80(%rbp),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%rax
je     12e7 <main+0x167>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1090 <addtree@plt>
mov    %rax,-0x18(%rbp)
jmp    12a5 <main+0x125>
movl   $0x0,-0x279c(%rbp)
lea    -0x279c(%rbp),%rax
mov    %rax,-0x27a8(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x2790(%rbp),%rsi
mov    -0x27a8(%rbp),%rdx
call   1050 <treesort@plt>
lea    -0x2790(%rbp),%rdi
mov    -0x2798(%rbp),%esi
mov    -0x27a8(%rbp),%rax
mov    (%rax),%edx
call   1030 <print_groups@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x27b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2790,%rsp
lea    -0x1(%rdi),%ebp
mov    $0x6,%r14d
cmp    $0x2,%edi
jl     1240 <main+0xb0>
mov    %rsi,%rbx
mov    $0x6,%r14d
lea    0xe3f(%rip),%r15
jmp    11e5 <main+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
lea    -0x1(%rbp),%eax
cmp    $0x1,%ebp
mov    %eax,%ebp
jle    1242 <main+0xb2>
mov    0x8(%rbx),%rax
cmpb   $0x2d,(%rax)
jne    1246 <main+0xb6>
add    $0x8,%rbx
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
mov    0x1(%rax),%al
test   %al,%al
je     11db <main+0x4b>
movsbl %al,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
jne    11d0 <main+0x40>
nopl   (%rax)
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movzbl 0x1(%rax),%eax
test   %al,%al
je     1246 <main+0xb6>
movsbl %al,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     1210 <main+0x80>
mov    $0xffffffff,%ebp
jmp    11d0 <main+0x40>
mov    %ebp,%eax
test   %eax,%eax
je     125a <main+0xca>
lea    0xdfd(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%r15d
jmp    12bb <main+0x12b>
lea    0xdc9(%rip),%rdi
xor    %r15d,%r15d
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1080 <getword@plt>
mov    0x2d64(%rip),%r12
cmp    (%r12),%rax
jne    12ce <main+0x13e>
xor    %ebp,%ebp
movl   $0x0,0xc(%rsp)
lea    0x80(%rsp),%rbx
lea    0xc(%rsp),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <treesort@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <print_groups@plt>
mov    %r15d,%eax
add    $0x2790,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
lea    0x10(%rsp),%rbx
jmp    12f3 <main+0x163>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x64,%esi
call   1080 <getword@plt>
cmp    (%r12),%rax
je     128c <main+0xfc>
movsbl 0x10(%rsp),%edi
call   1090 <isalpha@plt>
test   %rax,%rax
je     12e0 <main+0x150>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <addtree@plt>
mov    %rax,%rbp
jmp    12e0 <main+0x150>

LLVM IR (-O0):
%struct.tnode = type { i32 }
@.str = [42 x i8] c"\0Aerror: specify number of head characters\00"
@.str.1 = [24 x i8] c"\0AUsage: groupwords -#\0A\0A\00"
@.str.2 = [32 x i8] c"Sorting on first %d characters\0A\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.tnode*
%7 = alloca [100 x i8]
%8 = alloca [100 x [100 x i8]]
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 6, i32* %10
br label %13
13: ; preds = %46, %2
%14 = load i32, i32* %4
%15 = add nsw i32 %14, -1
store i32 %15, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i32 1
store i8** %19, i8*** %5
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 45
br label %25
25: ; preds = %17, %13
%26 = phi i1 [ false, %13 ], [ %24, %17 ]
br i1 %26, label %27, label %47
27: ; preds = %25
br label %28
28: ; preds = %45, %27
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %30
%33 = load i8, i8* %32
store i8 %33, i8* %9
%34 = icmp ne i8 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %28
%36 = load i8, i8* %9
%37 = call i64 @isdigit(i8 signext %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i8**, i8*** %5
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
store i32 %42, i32* %10
br label %46
43: ; preds = %35
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %45
45: ; preds = %43
br label %28
46: ; preds = %39, %28
br label %13
47: ; preds = %25
%48 = load i32, i32* %4
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %82
52: ; preds = %47
%53 = load i32, i32* %10
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %53)
store %struct.tnode* null, %struct.tnode** %6
br label %55
55: ; preds = %69, %52
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%57 = call i64 @getword(i8* %56, i32 100)
%58 = load i64, i64* @EOF
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %70
60: ; preds = %55
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%62 = load i8, i8* %61
%63 = call i64 @isalpha(i8 signext %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %60
%66 = load %struct.tnode*, %struct.tnode** %6
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%68 = call %struct.tnode* @addtree(%struct.tnode* %66, i8* %67)
store %struct.tnode* %68, %struct.tnode** %6
br label %69
69: ; preds = %65, %60
br label %55
70: ; preds = %55
store i32 0, i32* %11
store i32* %11, i32** %12
%71 = load %struct.tnode*, %struct.tnode** %6
%72 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %8, i64 0, i64 0
%73 = bitcast [100 x i8]* %72 to i8**
%74 = load i32*, i32** %12
%75 = call i32 @treesort(%struct.tnode* %71, i8** %73, i32* %74)
%76 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %8, i64 0, i64 0
%77 = bitcast [100 x i8]* %76 to i8**
%78 = load i32, i32* %10
%79 = load i32*, i32** %12
%80 = load i32, i32* %79
%81 = call i32 @print_groups(i8** %77, i32 %78, i32 %80)
store i32 0, i32* %3
br label %82
82: ; preds = %70, %50
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
%struct.tnode = type { i32 }
@.str = [42 x i8] c"\0Aerror: specify number of head characters\00"
@.str.2 = [32 x i8] c"Sorting on first %d characters\0A\00"
@EOF = global i64 0
@str = [23 x i8] c"\0AUsage: groupwords -#\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x [100 x i8]]
%5 = alloca i32
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [100 x [100 x i8]], [100 x [100 x i8]]* %4, i64 0, i64 0, i64 0
%8 = add nsw i32 %0, -1
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %43
10: ; preds = %2, %38
%11 = phi i32 [ %41, %38 ], [ %8, %2 ]
%12 = phi i32 [ %40, %38 ], [ 6, %2 ]
%13 = phi i8** [ %14, %38 ], [ %1, %2 ]
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 45
br i1 %17, label %18, label %47
18: ; preds = %10
%19 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %19, i8** %14
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %38, label %22
22: ; preds = %18
%23 = tail call i64 @isdigit(i8 signext %20)
%24 = icmp eq i64 %23, 0
br i1 %24, label %32, label %28
25: ; preds = %32
%26 = tail call i64 @isdigit(i8 signext %36)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25, %22
%29 = phi i32 [ %11, %22 ], [ -1, %25 ]
%30 = load i8*, i8** %14
%31 = tail call i32 @atoi(i8* %30)
br label %38
32: ; preds = %22, %25
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%34 = load i8*, i8** %14
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8* %35, i8** %14
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %47, label %25
38: ; preds = %18, %28
%39 = phi i32 [ %29, %28 ], [ %11, %18 ]
%40 = phi i32 [ %31, %28 ], [ %12, %18 ]
%41 = add nsw i32 %39, -1
%42 = icmp sgt i32 %39, 1
br i1 %42, label %10, label %43
43: ; preds = %38, %2
%44 = phi i32 [ 6, %2 ], [ %40, %38 ]
%45 = phi i32 [ %8, %2 ], [ %41, %38 ]
%46 = icmp eq i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %10, %32, %43
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %73
49: ; preds = %43
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%51 = call i64 @getword(i8* %6, i32 100)
%52 = load i64, i64* @EOF
%53 = icmp eq i64 %51, %52
br i1 %53, label %66, label %54
54: ; preds = %49, %61
%55 = phi %struct.tnode* [ %62, %61 ], [ null, %49 ]
%56 = load i8, i8* %6
%57 = call i64 @isalpha(i8 signext %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %61, label %59
59: ; preds = %54
%60 = call %struct.tnode* @addtree(%struct.tnode* %55, i8* %6)
br label %61
61: ; preds = %59, %54
%62 = phi %struct.tnode* [ %60, %59 ], [ %55, %54 ]
%63 = call i64 @getword(i8* %6, i32 100)
%64 = load i64, i64* @EOF
%65 = icmp eq i64 %63, %64
br i1 %65, label %66, label %54
66: ; preds = %61, %49
%67 = phi %struct.tnode* [ null, %49 ], [ %62, %61 ]
%68 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%69 = bitcast [100 x [100 x i8]]* %4 to i8**
%70 = call i32 @treesort(%struct.tnode* %67, i8** %69, i32* %5)
%71 = load i32, i32* %5
%72 = call i32 @print_groups(i8** %69, i32 %44, i32 %71)
br label %73
73: ; preds = %66, %47
%74 = phi i32 [ -1, %47 ], [ 0, %66 ]
ret i32 %74
}