#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 lnode {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ applnode(char, int, struct lnode *);
struct lnode *findlnode(struct lnode *, char);
int /*<<< orphan*/ incfreq(struct lnode *);
struct lnode *mklnode(char, int);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
struct lnode *mklist(int fd) {
  int nr, i;
  char buf[8192];
  struct lnode *root = 0;
  struct lnode *result = 0;
  while ((nr = read(fd, buf, 8192)) != -1 && nr != 0) {
    printf("Read %d bytes.\n", nr);
    for (i = 0; i < nr; i++) {
      if (i == 0)
        root = mklnode(buf[i], 1);
      else if ((result = findlnode(root, buf[i])))
        incfreq(result);
      else
        applnode(buf[i], 1, root);
    }
  }
  return root;
}


x86 assembly (clang, -O0):
<mklist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x2018(%rbp)
movq   $0x0,-0x2020(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x2010(%rbp),%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x2021(%rbp)
je     11bb <mklist+0x5b>
cmpl   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0x2021(%rbp)
mov    -0x2021(%rbp),%al
test   $0x1,%al
jne    11ce <mklist+0x6e>
jmp    1292 <mklist+0x132>
mov    -0x8(%rbp),%esi
lea    0xe28(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    128d <mklist+0x12d>
cmpl   $0x0,-0xc(%rbp)
jne    121c <mklist+0xbc>
movslq -0xc(%rbp),%rax
mov    $0x1,%esi
movsbl -0x2010(%rbp,%rax,1),%edi
ff
call   1040 <mklnode@plt>
mov    %rax,-0x2018(%rbp)
jmp    127a <mklist+0x11a>
mov    -0x2018(%rbp),%rdi
movslq -0xc(%rbp),%rax
movsbl -0x2010(%rbp,%rax,1),%esi
ff
call   1080 <findlnode@plt>
mov    %rax,-0x2020(%rbp)
cmp    $0x0,%rax
je     1256 <mklist+0xf6>
mov    -0x2020(%rbp),%rdi
call   1030 <incfreq@plt>
jmp    1275 <mklist+0x115>
movslq -0xc(%rbp),%rax
mov    -0x2010(%rbp,%rax,1),%al
mov    -0x2018(%rbp),%rdx
mov    $0x1,%esi
movsbl %al,%edi
call   1050 <applnode@plt>
jmp    127a <mklist+0x11a>
jmp    127f <mklist+0x11f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e4 <mklist+0x84>
jmp    1184 <mklist+0x24>
mov    -0x2018(%rbp),%rax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mklist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %edi,%r14d
lea    0x10(%rsp),%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
mov    %eax,%ebp
lea    -0x1(%rbp),%eax
xor    %r13d,%r13d
cmp    $0xfffffffd,%eax
ja     1237 <mklist+0xd7>
lea    0xe65(%rip),%r15
lea    0x10(%rsp),%r12
mov    %r14d,0xc(%rsp)
jmp    11cf <mklist+0x6f>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%r14d
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
mov    %eax,%ebp
add    $0xffffffff,%eax
cmp    $0xfffffffd,%eax
ja     1237 <mklist+0xd7>
mov    %r15,%rdi
mov    %ebp,%esi
call   1060 <printf@plt>
test   %ebp,%ebp
jle    11b5 <mklist+0x55>
movsbl 0x10(%rsp),%edi
mov    $0x1,%esi
call   1040 <mklnode@plt>
mov    %rax,%r13
cmp    $0x1,%ebp
je     11b5 <mklist+0x55>
mov    %ebp,%ebx
mov    $0x1,%r14d
jmp    1218 <mklist+0xb8>
xchg   %ax,%ax
mov    %ebp,%edi
mov    $0x1,%esi
mov    %r13,%rdx
call   1050 <applnode@plt>
add    $0x1,%r14
cmp    %r14,%rbx
je     11b0 <mklist+0x50>
movsbl 0x10(%rsp,%r14,1),%ebp
mov    %r13,%rdi
mov    %ebp,%esi
call   1080 <findlnode@plt>
test   %rax,%rax
je     1200 <mklist+0xa0>
mov    %rax,%rdi
call   1030 <incfreq@plt>
jmp    120f <mklist+0xaf>
mov    %r13,%rax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.lnode = type { i32 }
@.str = [16 x i8] c"Read %d bytes.\0A\00"
define %struct.lnode* @mklist(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [8192 x i8]
%6 = alloca %struct.lnode*
%7 = alloca %struct.lnode*
store i32 %0, i32* %2
store %struct.lnode* null, %struct.lnode** %6
store %struct.lnode* null, %struct.lnode** %7
br label %8
8: ; preds = %57, %1
%9 = load i32, i32* %2
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 8192)
store i32 %11, i32* %3
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br label %16
16: ; preds = %13, %8
%17 = phi i1 [ false, %8 ], [ %15, %13 ]
br i1 %17, label %18, label %58
18: ; preds = %16
%19 = load i32, i32* %3
%20 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 0, i32* %4
br label %21
21: ; preds = %54, %18
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %57
25: ; preds = %21
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = call %struct.lnode* @mklnode(i8 signext %32, i32 1)
store %struct.lnode* %33, %struct.lnode** %6
br label %53
34: ; preds = %25
%35 = load %struct.lnode*, %struct.lnode** %6
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = call %struct.lnode* @findlnode(%struct.lnode* %35, i8 signext %39)
store %struct.lnode* %40, %struct.lnode** %7
%41 = icmp ne %struct.lnode* %40, null
br i1 %41, label %42, label %45
42: ; preds = %34
%43 = load %struct.lnode*, %struct.lnode** %7
%44 = call i32 @incfreq(%struct.lnode* %43)
br label %52
45: ; preds = %34
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = load %struct.lnode*, %struct.lnode** %6
%51 = call i32 @applnode(i8 signext %49, i32 1, %struct.lnode* %50)
br label %52
52: ; preds = %45, %42
br label %53
53: ; preds = %52, %28
br label %54
54: ; preds = %53
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %21
57: ; preds = %21
br label %8
58: ; preds = %16
%59 = load %struct.lnode*, %struct.lnode** %6
ret %struct.lnode* %59
}

LLVM IR (-O2):
%struct.lnode = type { i32 }
@.str = [16 x i8] c"Read %d bytes.\0A\00"
define %struct.lnode* @mklist(i32 %0) {
%2 = alloca [8192 x i8]
%3 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 8192)
%5 = add i32 %4, -1
%6 = icmp ult i32 %5, -2
br i1 %6, label %12, label %35
7: ; preds = %32, %17, %12
%8 = phi %struct.lnode* [ %14, %12 ], [ %20, %17 ], [ %20, %32 ]
%9 = call i32 @read(i32 %0, i8* %3, i32 8192)
%10 = add i32 %9, -1
%11 = icmp ult i32 %10, -2
br i1 %11, label %12, label %35
12: ; preds = %1, %7
%13 = phi i32 [ %9, %7 ], [ %4, %1 ]
%14 = phi %struct.lnode* [ %8, %7 ], [ null, %1 ]
%15 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %13)
%16 = icmp sgt i32 %13, 0
br i1 %16, label %17, label %7
17: ; preds = %12
%18 = zext i32 %13 to i64
%19 = load i8, i8* %3
%20 = tail call %struct.lnode* @mklnode(i8 signext %19, i32 1)
%21 = icmp eq i32 %13, 1
br i1 %21, label %7, label %22
22: ; preds = %17, %32
%23 = phi i64 [ %33, %32 ], [ 1, %17 ]
%24 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = tail call %struct.lnode* @findlnode(%struct.lnode* %20, i8 signext %25)
%27 = icmp eq %struct.lnode* %26, null
br i1 %27, label %30, label %28
28: ; preds = %22
%29 = tail call i32 @incfreq(%struct.lnode* %26)
br label %32
30: ; preds = %22
%31 = tail call i32 @applnode(i8 signext %25, i32 1, %struct.lnode* %20)
br label %32
32: ; preds = %30, %28
%33 = add nuw nsw i64 %23, 1
%34 = icmp eq i64 %33, %18
br i1 %34, label %7, label %22
35: ; preds = %7, %1
%36 = phi %struct.lnode* [ null, %1 ], [ %8, %7 ]
ret %struct.lnode* %36
}