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

/* Variables and functions */
int /*<<< orphan*/ alphasort;
int /*<<< orphan*/ ident(int /*<<< orphan*/);
int scandir(char *, struct dirent ***, int, int /*<<< orphan*/);
int ident_dir(char *fn) {
  int count, i = 0;
  struct dirent **files;
  int file_select = NULL;
  count = scandir(fn, &files, file_select, alphasort);
  if (count > 0) {
    for (i = 0; i < count; ++i) {
      ident(files[i]->d_name);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ident_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    0x2e98(%rip),%rax
mov    (%rax),%ecx
lea    -0x18(%rbp),%rsi
call   1030 <scandir@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1199 <ident_dir+0x79>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1194 <ident_dir+0x74>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1040 <ident@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1167 <ident_dir+0x47>
jmp    1199 <ident_dir+0x79>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ident_dir>:
push   %r14
push   %rbx
push   %rax
mov    0x2eb5(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <scandir@plt>
test   %eax,%eax
jle    1158 <ident_dir+0x38>
mov    %eax,%r14d
xor    %ebx,%ebx
mov    (%rsp),%rax
mov    (%rax,%rbx,8),%rax
mov    (%rax),%edi
call   1040 <ident@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <ident_dir+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@alphasort = global i32 0
define i32 @ident_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.dirent**
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %6
%7 = load i8*, i8** %2
%8 = load i32, i32* %6
%9 = load i32, i32* @alphasort
%10 = call i32 @scandir(i8* %7, %struct.dirent*** %5, i32 %8, i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %1
store i32 0, i32* %4
br label %14
14: ; preds = %27, %13
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = load %struct.dirent**, %struct.dirent*** %5
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds %struct.dirent*, %struct.dirent** %19, i64 %21
%23 = load %struct.dirent*, %struct.dirent** %22
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @ident(i32 %25)
br label %27
27: ; preds = %18
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %14
30: ; preds = %14
br label %31
31: ; preds = %30, %1
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@alphasort = global i32 0
define i32 @ident_dir(i8* %0) {
%2 = alloca %struct.dirent**
%3 = bitcast %struct.dirent*** %2 to i8*
%4 = load i32, i32* @alphasort
%5 = call i32 @scandir(i8* %0, %struct.dirent*** %2, i32 0, i32 %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %17, %9 ]
%11 = load %struct.dirent**, %struct.dirent*** %2
%12 = getelementptr inbounds %struct.dirent*, %struct.dirent** %11, i64 %10
%13 = load %struct.dirent*, %struct.dirent** %12
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @ident(i32 %15)
%17 = add nuw nsw i64 %10, 1
%18 = icmp eq i64 %17, %8
br i1 %18, label %19, label %9
19: ; preds = %9, %1
ret i32 0
}