#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 dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ ends_with(char *, char *);
int /*<<< orphan*/ err(int, char *, char *);
scalar_t__ errno;
int /*<<< orphan*/ *opendir(char *);
int plan_count_entries(char const *);
int plan_get_entry(char const *);
char *plandir();
int /*<<< orphan*/ printf(char *, char const *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ show(char const *, int);
void summary(const char *plan) {
  if (plan) {
    int entries = plan_count_entries(plan);
    int entry = plan_get_entry(plan);
    if (entry > entries) {
      printf("%s (end of plan)\n", plan);
    } else {
      printf("%s (%d/%d): ", plan, plan_get_entry(plan),
             plan_count_entries(plan));
      show(plan, 1);
    }
  } else {
    char *path = plandir();
    DIR *dir;
    struct dirent *file;
    if (!(dir = opendir(path)))
      err(1, "could not open plan directory (%s)", plandir());
    errno = 0;
    while ((file = readdir(dir)))
      if (file->d_name[0] != '.' && !ends_with(file->d_name, ".status"))
        summary(file->d_name);
    if (errno != 0)
      err(1, "could not read from plan directory (%s)", plandir());
    closedir(dir);
  }
}


x86 assembly (clang, -O0):
<summary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1249 <summary+0x99>
mov    -0x8(%rbp),%rdi
call   1040 <plan_count_entries@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <plan_get_entry@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1202 <summary+0x52>
mov    -0x8(%rbp),%rsi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1244 <summary+0x94>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <plan_get_entry@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <plan_count_entries@plt>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1090 <show@plt>
jmp    1320 <summary+0x170>
mov    $0x0,%al
call   1050 <plandir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1286 <summary+0xd6>
mov    $0x0,%al
call   1050 <plandir@plt>
mov    %rax,%rdx
mov    $0x1,%edi
lea    0xd9e(%rip),%rsi
call   10c0 <err@plt>
mov    0x2d53(%rip),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12eb <summary+0x13b>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     12e6 <summary+0x136>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd76(%rip),%rsi
call   10d0 <ends_with@plt>
cmp    $0x0,%eax
jne    12e6 <summary+0x136>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <summary@plt>
jmp    1294 <summary+0xe4>
mov    0x2cee(%rip),%rax
cmpq   $0x0,(%rax)
je     1317 <summary+0x167>
mov    $0x0,%al
call   1050 <plandir@plt>
mov    %rax,%rdx
mov    $0x1,%edi
lea    0xd38(%rip),%rsi
call   10c0 <err@plt>
mov    -0x20(%rbp),%rdi
call   1080 <closedir@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<summary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11f1 <summary+0x41>
mov    %rdi,%rbx
call   1040 <plan_count_entries@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <plan_get_entry@plt>
cmp    %ebp,%eax
jle    12b2 <summary+0x102>
lea    0xe23(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <printf@plt>
xor    %eax,%eax
call   1050 <plandir@plt>
mov    %rax,%rdi
call   1060 <opendir@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1223 <summary+0x73>
xor    %eax,%eax
call   1050 <plandir@plt>
lea    0xe09(%rip),%rsi
mov    $0x1,%edi
mov    %rax,%rdx
call   10c0 <err@plt>
mov    0x2db6(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %r15,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     127e <summary+0xce>
mov    %rax,%rbx
lea    0xdf9(%rip),%r14
jmp    1260 <summary+0xb0>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     127e <summary+0xce>
mov    (%rbx),%rdi
cmpb   $0x2e,(%rdi)
je     1250 <summary+0xa0>
mov    %r14,%rsi
call   10d0 <ends_with@plt>
test   %eax,%eax
jne    1250 <summary+0xa0>
mov    (%rbx),%rdi
call   10b0 <summary@plt>
jmp    1250 <summary+0xa0>
cmpq   $0x0,0x0(%rbp)
je     12a0 <summary+0xf0>
xor    %eax,%eax
call   1050 <plandir@plt>
lea    0xdb7(%rip),%rsi
mov    $0x1,%edi
mov    %rax,%rdx
call   10c0 <err@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <closedir@plt>
mov    %rbx,%rdi
call   1030 <plan_get_entry@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <plan_count_entries@plt>
lea    0xd47(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <show@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [18 x i8] c"%s (end of plan)\0A\00"
@.str.1 = [13 x i8] c"%s (%d/%d): \00"
@.str.2 = [35 x i8] c"could not open plan directory (%s)\00"
@errno = global i64 0
@.str.3 = [8 x i8] c".status\00"
@.str.4 = [40 x i8] c"could not read from plan directory (%s)\00"
define void @summary(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.dirent*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %31
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @plan_count_entries(i8* %11)
store i32 %12, i32* %3
%13 = load i8*, i8** %2
%14 = call i32 @plan_get_entry(i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i8*, i8** %2
%20 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %30
21: ; preds = %10
%22 = load i8*, i8** %2
%23 = load i8*, i8** %2
%24 = call i32 @plan_get_entry(i8* %23)
%25 = load i8*, i8** %2
%26 = call i32 @plan_count_entries(i8* %25)
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %24, i32 %26)
%28 = load i8*, i8** %2
%29 = call i32 @show(i8* %28, i32 1)
br label %30
30: ; preds = %21, %18
br label %72
31: ; preds = %1
%32 = call i8* (...) @plandir()
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = call i32* @opendir(i8* %33)
store i32* %34, i32** %6
%35 = icmp ne i32* %34, null
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = call i8* (...) @plandir()
%38 = call i32 @err(i32 1, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %36, %31
store i64 0, i64* @errno
br label %40
40: ; preds = %62, %39
%41 = load i32*, i32** %6
%42 = call %struct.dirent* @readdir(i32* %41)
store %struct.dirent* %42, %struct.dirent** %7
%43 = icmp ne %struct.dirent* %42, null
br i1 %43, label %44, label %63
44: ; preds = %40
%45 = load %struct.dirent*, %struct.dirent** %7
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 46
br i1 %51, label %52, label %62
52: ; preds = %44
%53 = load %struct.dirent*, %struct.dirent** %7
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %53, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = call i32 @ends_with(i8* %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%57 = icmp ne i32 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %52
%59 = load %struct.dirent*, %struct.dirent** %7
%60 = getelementptr inbounds %struct.dirent, %struct.dirent* %59, i32 0, i32 0
%61 = load i8*, i8** %60
br label %62
62: ; preds = %58, %52, %44
br label %40
63: ; preds = %40
%64 = load i64, i64* @errno
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = call i8* (...) @plandir()
%68 = call i32 @err(i32 1, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %66, %63
%70 = load i32*, i32** %6
%71 = call i32 @closedir(i32* %70)
br label %72
72: ; preds = %69, %30
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [18 x i8] c"%s (end of plan)\0A\00"
@.str.1 = [13 x i8] c"%s (%d/%d): \00"
@.str.2 = [35 x i8] c"could not open plan directory (%s)\00"
@errno = global i64 0
@.str.3 = [8 x i8] c".status\00"
@.str.4 = [40 x i8] c"could not read from plan directory (%s)\00"
define void @summary(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i32 @plan_count_entries(i8* %0)
%5 = tail call i32 @plan_get_entry(i8* %0)
%6 = icmp sgt i32 %5, %4
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %46
9: ; preds = %3
%10 = tail call i32 @plan_get_entry(i8* %0)
%11 = tail call i32 @plan_count_entries(i8* %0)
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %10, i32 %11)
%13 = tail call i32 @show(i8* %0, i32 1)
br label %46
14: ; preds = %1
%15 = tail call i8* (...) @plandir()
%16 = tail call i32* @opendir(i8* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = tail call i8* (...) @plandir()
%20 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %14
store i64 0, i64* @errno
%22 = tail call %struct.dirent* @readdir(i32* %16)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %38, label %24
24: ; preds = %21, %35
%25 = phi %struct.dirent* [ %36, %35 ], [ %22, %21 ]
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i64 0, i32 0
%27 = load i8*, i8** %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 46
br i1 %29, label %35, label %30
30: ; preds = %24
%31 = tail call i32 @ends_with(i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i8*, i8** %26
tail call void @summary(i8* %34)
br label %35
35: ; preds = %33, %30, %24
%36 = tail call %struct.dirent* @readdir(i32* %16)
%37 = icmp eq %struct.dirent* %36, null
br i1 %37, label %38, label %24
38: ; preds = %35, %21
%39 = load i64, i64* @errno
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = tail call i8* (...) @plandir()
%43 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %41, %38
%45 = tail call i32 @closedir(i32* %16)
br label %46
46: ; preds = %7, %9, %44
ret void
}