#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*/ die(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char const *, char *);
char *tracecmd_get_tracing_file(char *);
int /*<<< orphan*/ tracecmd_put_tracing_file(char *);
void show_buffers(void) {
  struct dirent *dent;
  DIR *dir;
  char *path;
  int printed = 0;
  path = tracecmd_get_tracing_file("instances");
  dir = opendir(path);
  tracecmd_put_tracing_file(path);
  if (!dir)
    die("Can not read instance directory");
  while ((dent = readdir(dir))) {
    const char *name = dent->d_name;
    if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
      continue;
    printf("%s\n", name);
    printed = 1;
  }
  closedir(dir);
  if (!printed)
    printf("No buffer instances defined\n");
}


x86 assembly (clang, -O0):
<show_buffers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x1c(%rbp)
lea    0xe6a(%rip),%rdi
call   1070 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11cc <show_buffers+0x4c>
lea    0xe43(%rip),%rdi
call   10a0 <die@plt>
jmp    11d1 <show_buffers+0x51>
mov    -0x10(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     124a <show_buffers+0xca>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1227 <show_buffers+0xa7>
mov    -0x28(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    122c <show_buffers+0xac>
jmp    11d1 <show_buffers+0x51>
mov    -0x28(%rbp),%rsi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    11d1 <show_buffers+0x51>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    126b <show_buffers+0xeb>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_buffers>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe71(%rip),%rdi
call   1070 <tracecmd_get_tracing_file@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <opendir@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
test   %r12,%r12
jne    11bb <show_buffers+0x3b>
lea    0xe54(%rip),%rdi
call   10a0 <die@plt>
mov    %r12,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     1234 <show_buffers+0xb4>
xor    %ebp,%ebp
lea    0xe5a(%rip),%r14
lea    0xe52(%rip),%r15
jmp    11ed <show_buffers+0x6d>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     121f <show_buffers+0x9f>
mov    (%rax),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11e0 <show_buffers+0x60>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11e0 <show_buffers+0x60>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
jmp    11e0 <show_buffers+0x60>
mov    %r12,%rdi
call   1060 <closedir@plt>
test   %ebp,%ebp
je     123c <show_buffers+0xbc>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
call   1060 <closedir@plt>
lea    0xdea(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [10 x i8] c"instances\00"
@.str.1 = [32 x i8] c"Can not read instance directory\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [29 x i8] c"No buffer instances defined\0A\00"
define void @show_buffers() {
%1 = alloca %struct.dirent*
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %4
%6 = call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @opendir(i8* %7)
store i32* %8, i32** %2
%9 = load i8*, i8** %3
%10 = call i32 @tracecmd_put_tracing_file(i8* %9)
%11 = load i32*, i32** %2
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = call i32 @die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
br label %16
16: ; preds = %32, %31, %15
%17 = load i32*, i32** %2
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %1
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %1
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %20
%28 = load i8*, i8** %5
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27, %20
br label %16
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %33)
store i32 1, i32* %4
br label %16
35: ; preds = %16
%36 = load i32*, i32** %2
%37 = call i32 @closedir(i32* %36)
%38 = load i32, i32* %4
%39 = icmp ne i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [10 x i8] c"instances\00"
@.str.1 = [32 x i8] c"Can not read instance directory\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@str = [28 x i8] c"No buffer instances defined\00"
define void @show_buffers() {
%1 = tail call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32* @opendir(i8* %1)
%3 = tail call i32 @tracecmd_put_tracing_file(i8* %1)
%4 = icmp eq i32* %2, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call %struct.dirent* @readdir(i32* %2)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @closedir(i32* %2)
br label %31
12: ; preds = %7, %24
%13 = phi %struct.dirent* [ %26, %24 ], [ %8, %7 ]
%14 = phi i32 [ %25, %24 ], [ 0, %7 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %12
%20 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) %16)
br label %24
24: ; preds = %12, %19, %22
%25 = phi i32 [ 1, %22 ], [ %14, %19 ], [ %14, %12 ]
%26 = tail call %struct.dirent* @readdir(i32* %2)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %28, label %12
28: ; preds = %24
%29 = tail call i32 @closedir(i32* %2)
%30 = icmp eq i32 %25, 0
br i1 %30, label %31, label %33
31: ; preds = %10, %28
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
ret void
}