#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;
  int /*<<< orphan*/ *d_name;
  int /*<<< orphan*/ d_reclen;
  int /*<<< orphan*/ d_off;
  int /*<<< orphan*/ d_ino;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_REG;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, scalar_t__, int /*<<< orphan*/ *,
                          int);
struct dirent *readdir(int /*<<< orphan*/ *);
int strlen(int /*<<< orphan*/ *);
scalar_t__ strncmp(int /*<<< orphan*/ *, char *, int);
int main() {
  DIR *dir_info;
  struct dirent *dir_entry;
  int fname_len;
  dir_info = opendir("./data");
  if (NULL != dir_info) {
    while (dir_entry = readdir(dir_info)) {
      if (dir_entry->d_type == DT_REG) {
        fname_len = strlen(dir_entry->d_name);
        if (strncmp(&dir_entry->d_name[0], "squall_data:", 12) == 0 &&
            strncmp(&dir_entry->d_name[fname_len - 5], "00001", 5) == 0)
          printf("d_ino=%lu, d_off=%d, d_reclen=%d, d_type=%d, d_name=%s(%d)\n",
                 dir_entry->d_ino, dir_entry->d_off, dir_entry->d_reclen,
                 dir_entry->d_type, dir_entry->d_name, fname_len);
      }
    }
    closedir(dir_info);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     126c <main+0x10c>
jmp    1190 <main+0x30>
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1263 <main+0x103>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%rax
jne    125e <main+0xfe>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2a(%rip),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1259 <main+0xf9>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%eax
sub    $0x5,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
lea    0xe05(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1259 <main+0xf9>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r9
mov    -0x1c(%rbp),%eax
lea    0xdc9(%rip),%rdi
mov    %eax,(%rsp)
call   1060 <printf@plt>
jmp    125e <main+0xfe>
jmp    1190 <main+0x30>
mov    -0x10(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1234 <main+0xd4>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     122c <main+0xcc>
mov    %rax,%rbx
mov    0x2e42(%rip),%r12
lea    0xe62(%rip),%r14
lea    0xe68(%rip),%r15
jmp    11c0 <main+0x60>
xchg   %ax,%ax
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     122c <main+0xcc>
mov    (%rbx),%rax
cmp    (%r12),%rax
jne    11b0 <main+0x50>
mov    0x8(%rbx),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    0x8(%rbx),%rax
movslq %ebp,%rcx
lea    (%rax,%rcx,4),%rdi
add    $0xffffffffffffffec,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    0x18(%rbx),%esi
mov    0x14(%rbx),%edx
mov    0x10(%rbx),%ecx
mov    (%rbx),%r8
mov    0x8(%rbx),%r9
mov    %ebp,(%rsp)
lea    0xdf5(%rip),%rdi
call   1060 <printf@plt>
jmp    11b0 <main+0x50>
mov    %r13,%rdi
call   1070 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i64, i32*, i32, i32, i32 }
@.str = [7 x i8] c"./data\00"
@DT_REG = global i64 0
@.str.1 = [13 x i8] c"squall_data:\00"
@.str.2 = [6 x i8] c"00001\00"
@.str.3 = [60 x i8] c"d_ino=%lu, d_off=%d, d_reclen=%d, d_type=%d, d_name=%s(%d)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @opendir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* null, %6
br i1 %7, label %8, label %63
8: ; preds = %0
br label %9
9: ; preds = %59, %8
%10 = load i32*, i32** %2
%11 = call %struct.dirent* @readdir(i32* %10)
store %struct.dirent* %11, %struct.dirent** %3
%12 = icmp ne %struct.dirent* %11, null
br i1 %12, label %13, label %60
13: ; preds = %9
%14 = load %struct.dirent*, %struct.dirent** %3
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @DT_REG
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %59
19: ; preds = %13
%20 = load %struct.dirent*, %struct.dirent** %3
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 1
%22 = load i32*, i32** %21
%23 = call i32 @strlen(i32* %22)
store i32 %23, i32* %4
%24 = load %struct.dirent*, %struct.dirent** %3
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 1
%26 = load i32*, i32** %25
%27 = getelementptr inbounds i32, i32* %26, i64 0
%28 = call i64 @strncmp(i32* %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %58
30: ; preds = %19
%31 = load %struct.dirent*, %struct.dirent** %3
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 1
%33 = load i32*, i32** %32
%34 = load i32, i32* %4
%35 = sub nsw i32 %34, 5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %33, i64 %36
%38 = call i64 @strncmp(i32* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %58
40: ; preds = %30
%41 = load %struct.dirent*, %struct.dirent** %3
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i32 0, i32 4
%43 = load i32, i32* %42
%44 = load %struct.dirent*, %struct.dirent** %3
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 3
%46 = load i32, i32* %45
%47 = load %struct.dirent*, %struct.dirent** %3
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 2
%49 = load i32, i32* %48
%50 = load %struct.dirent*, %struct.dirent** %3
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 0
%52 = load i64, i64* %51
%53 = load %struct.dirent*, %struct.dirent** %3
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %53, i32 0, i32 1
%55 = load i32*, i32** %54
%56 = load i32, i32* %4
%57 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %46, i32 %49, i64 %52, i32* %55, i32 %56)
br label %58
58: ; preds = %40, %30, %19
br label %59
59: ; preds = %58, %13
br label %9
60: ; preds = %9
%61 = load i32*, i32** %2
%62 = call i32 @closedir(i32* %61)
br label %63
63: ; preds = %60, %0
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
%struct.dirent = type { i64, i32*, i32, i32, i32 }
@.str = [7 x i8] c"./data\00"
@DT_REG = global i64 0
@.str.1 = [13 x i8] c"squall_data:\00"
@.str.2 = [6 x i8] c"00001\00"
@.str.3 = [60 x i8] c"d_ino=%lu, d_off=%d, d_reclen=%d, d_type=%d, d_name=%s(%d)\0A\00"
define i32 @main() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %41, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %39, label %6
6: ; preds = %3, %36
%7 = phi %struct.dirent* [ %37, %36 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i64, i64* %8
%10 = load i64, i64* @DT_REG
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %36
12: ; preds = %6
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 1
%14 = load i32*, i32** %13
%15 = tail call i32 @strlen(i32* %14)
%16 = load i32*, i32** %13
%17 = tail call i64 @strncmp(i32* %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %12
%20 = load i32*, i32** %13
%21 = add nsw i32 %15, -5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = tail call i64 @strncmp(i32* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %19
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 4
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 3
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 2
%32 = load i32, i32* %31
%33 = load i64, i64* %8
%34 = load i32*, i32** %13
%35 = tail call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %30, i32 %32, i64 %33, i32* %34, i32 %15)
br label %36
36: ; preds = %12, %19, %26, %6
%37 = tail call %struct.dirent* @readdir(i32* %1)
%38 = icmp eq %struct.dirent* %37, null
br i1 %38, label %39, label %6
39: ; preds = %36, %3
%40 = tail call i32 @closedir(i32* %1)
br label %41
41: ; preds = %39, %0
ret i32 0
}