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

/* Variables and functions */
scalar_t__ DT_DIR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ cmd_status_query(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int cmd_status_overview() {
  DIR *dfd = opendir(".");
  if (dfd == NULL) {
    perror("opendir");
    return 1;
  }
  struct dirent *entry;
  while (entry = readdir(dfd)) {
    if (entry->d_type == DT_DIR && entry->d_name[0] != '.') {
      puts(entry->d_name);
      cmd_status_query(entry->d_name);
      puts("");
    }
  }
  closedir(dfd);
}


x86 assembly (clang, -O0):
<cmd_status_overview>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <cmd_status_overview+0x3b>
lea    0xe78(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1216 <cmd_status_overview+0xb6>
jmp    11a0 <cmd_status_overview+0x40>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     120d <cmd_status_overview+0xad>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
jne    1208 <cmd_status_overview+0xa8>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1208 <cmd_status_overview+0xa8>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <cmd_status_query@plt>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
jmp    11a0 <cmd_status_overview+0x40>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_status_overview>:
push   %r15
push   %r14
push   %rbx
lea    0xe84(%rip),%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     11fe <cmd_status_overview+0x8e>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11eb <cmd_status_overview+0x7b>
mov    %rax,%rbx
mov    0x2e40(%rip),%r15
jmp    11c0 <cmd_status_overview+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11eb <cmd_status_overview+0x7b>
mov    (%rbx),%rax
cmp    (%r15),%rax
jne    11b0 <cmd_status_overview+0x40>
mov    0x8(%rbx),%rdi
cmpb   $0x2e,(%rdi)
je     11b0 <cmd_status_overview+0x40>
call   1040 <puts@plt>
mov    0x8(%rbx),%rdi
call   1050 <cmd_status_query@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11b0 <cmd_status_overview+0x40>
mov    %r14,%rdi
call   1070 <closedir@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdfd(%rip),%rdi
call   1090 <perror@plt>
jmp    11f3 <cmd_status_overview+0x83>

LLVM IR (-O0):
%struct.dirent = type { i64, i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [8 x i8] c"opendir\00"
@DT_DIR = global i64 0
@.str.2 = [1 x i8] zeroinitializer
define i32 @cmd_status_overview() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %42
9: ; preds = %0
br label %10
10: ; preds = %38, %9
%11 = load i32*, i32** %2
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %3
%13 = icmp ne %struct.dirent* %12, null
br i1 %13, label %14, label %39
14: ; preds = %10
%15 = load %struct.dirent*, %struct.dirent** %3
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @DT_DIR
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %14
%21 = load %struct.dirent*, %struct.dirent** %3
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 46
br i1 %27, label %28, label %38
28: ; preds = %20
%29 = load %struct.dirent*, %struct.dirent** %3
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 1
%31 = load i8*, i8** %30
%32 = call i32 @puts(i8* %31)
%33 = load %struct.dirent*, %struct.dirent** %3
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 1
%35 = load i8*, i8** %34
%36 = call i32 @cmd_status_query(i8* %35)
%37 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %28, %20, %14
br label %10
39: ; preds = %10
%40 = load i32*, i32** %2
%41 = call i32 @closedir(i32* %40)
br label %42
42: ; preds = %39, %7
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
%struct.dirent = type { i64, i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [8 x i8] c"opendir\00"
@DT_DIR = global i64 0
define i32 @cmd_status_overview() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %27, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %29
8: ; preds = %3, %24
%9 = phi %struct.dirent* [ %25, %24 ], [ %4, %3 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @DT_DIR
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %8
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 1
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 46
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = tail call i32 @puts(i8* %16)
%21 = load i8*, i8** %15
%22 = tail call i32 @cmd_status_query(i8* %21)
%23 = tail call i32 @putchar(i32 10)
br label %24
24: ; preds = %19, %14, %8
%25 = tail call %struct.dirent* @readdir(i32* %1)
%26 = icmp eq %struct.dirent* %25, null
br i1 %26, label %27, label %8
27: ; preds = %24, %3
%28 = tail call i32 @closedir(i32* %1)
br label %29
29: ; preds = %27, %6
ret i32 1
}