#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *strerror(scalar_t__);
void ls_files(const char *dir) {
  printf("Scanning files from %s ... \n", dir);
  DIR *dp;
  struct dirent *de;
  struct timeval begin;
  struct timeval end;
  if ((dp = opendir(dir)) == NULL) {
    printf("[%s] ERR_opendir: %s\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/linpawslitap/mds_scaling/refs/heads/"
           "master/tests/smallfile_test.c",
           strerror(errno));
    exit(1);
  }
  gettimeofday(&begin, NULL);
  int num_ent = 0;
  while (1) {
    errno = 0;
    if ((de = readdir(dp)) == NULL) {
      break;
    }
    if ((strcmp(de->d_name, ".") == 0) || (strcmp(de->d_name, "..") == 0))
      continue;
    num_ent += 1;
  }
  gettimeofday(&end, NULL);
  if (errno != 0) {
    printf("[%s] ERR_readdir: %s\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/linpawslitap/mds_scaling/refs/heads/"
           "master/tests/smallfile_test.c",
           strerror(errno));
    exit(1);
  }
  int microsec = (end.tv_sec - begin.tv_sec) * 1000000 +
                 ((int)end.tv_usec - (int)begin.tv_usec);
  int millisec = microsec / 1000;
  printf("readdir_ret=%d in %d\n", num_ent, millisec);
  closedir(dp);
}


x86 assembly (clang, -O0):
<ls_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e6 <ls_files+0x66>
mov    0x2e24(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %rax,%rdx
lea    0xe4f(%rip),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x3c(%rbp)
mov    0x2ddf(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1224 <ls_files+0xa4>
jmp    126f <ls_files+0xef>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     125c <ls_files+0xdc>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1261 <ls_files+0xe1>
jmp    11fa <ls_files+0x7a>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11fa <ls_files+0x7a>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    0x2d5d(%rip),%rax
cmpq   $0x0,(%rax)
je     12be <ls_files+0x13e>
mov    0x2d4c(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %rax,%rdx
lea    0xe2c(%rip),%rdi
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%eax
sub    -0x28(%rbp),%eax
imul   $0xf4240,%eax,%eax
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0xe68(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     12a4 <ls_files+0x124>
mov    %rax,%r13
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x2e14(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %r13,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     123c <ls_files+0xbc>
mov    %rax,%rbx
xor    %r14d,%r14d
lea    0xee2(%rip),%r15
lea    0xeda(%rip),%r12
jmp    1218 <ls_files+0x98>
nopw   0x0(%rax,%rax,1)
movq   $0x0,0x0(%rbp)
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     123c <ls_files+0xbc>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <ls_files+0x80>
mov    (%rbx),%edi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <ls_files+0x80>
add    $0x1,%r14d
jmp    1200 <ls_files+0x80>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x0(%rbp),%rdi
test   %rdi,%rdi
jne    12bc <ls_files+0x13c>
mov    0x8(%rsp),%eax
sub    0x18(%rsp),%eax
imul   $0xf4240,%eax,%eax
add    0x10(%rsp),%eax
sub    0x20(%rsp),%eax
cltq
imul   $0x10624dd3,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x26,%rdx
add    %eax,%edx
lea    0xe64(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <closedir@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xd63(%rip),%rdi
jmp    12c8 <ls_files+0x148>
call   10a0 <strerror@plt>
lea    0xe0a(%rip),%rdi
lea    0xd64(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
%struct.timeval = type { i32, i64 }
@.str = [29 x i8] c"Scanning files from %s ... \0A\00"
@.str.1 = [22 x i8] c"[%s] ERR_opendir: %s\0A\00"
@.str.2 = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/linpawslitap/mds_scaling/refs/heads/master/tests/smallfile_test.c\00"
@errno = global i64 0
@.str.3 = [2 x i8] c".\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [22 x i8] c"[%s] ERR_readdir: %s\0A\00"
@.str.6 = [22 x i8] c"readdir_ret=%d in %d\0A\00"
define void @ls_files(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %2
%13 = call i32* @opendir(i8* %12)
store i32* %13, i32** %3
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %1
%21 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i32 0, i32* %7
br label %22
22: ; preds = %20, %39, %40
store i64 0, i64* @errno
%23 = load i32*, i32** %3
%24 = call %struct.dirent* @readdir(i32* %23)
store %struct.dirent* %24, %struct.dirent** %4
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %26, label %27
26: ; preds = %22
br label %43
27: ; preds = %22
%28 = load %struct.dirent*, %struct.dirent** %4
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i64 @strcmp(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %27
%34 = load %struct.dirent*, %struct.dirent** %4
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @strcmp(i32 %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33, %27
br label %22
40: ; preds = %33
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %22
43: ; preds = %26
%44 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%45 = load i64, i64* @errno
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i64, i64* @errno
%49 = call i8* @strerror(i64 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %43
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%56 = load i32, i32* %55
%57 = sub nsw i32 %54, %56
%58 = mul nsw i32 %57, 1000000
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%60 = load i64, i64* %59
%61 = trunc i64 %60 to i32
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%63 = load i64, i64* %62
%64 = trunc i64 %63 to i32
%65 = sub nsw i32 %61, %64
%66 = add nsw i32 %58, %65
store i32 %66, i32* %8
%67 = load i32, i32* %8
%68 = sdiv i32 %67, 1000
store i32 %68, i32* %9
%69 = load i32, i32* %7
%70 = load i32, i32* %9
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %69, i32 %70)
%72 = load i32*, i32** %3
%73 = call i32 @closedir(i32* %72)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.dirent = type { i32 }
@.str = [29 x i8] c"Scanning files from %s ... \0A\00"
@.str.1 = [22 x i8] c"[%s] ERR_opendir: %s\0A\00"
@.str.2 = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/linpawslitap/mds_scaling/refs/heads/master/tests/smallfile_test.c\00"
@errno = global i64 0
@.str.3 = [2 x i8] c".\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [22 x i8] c"[%s] ERR_readdir: %s\0A\00"
@.str.6 = [22 x i8] c"readdir_ret=%d in %d\0A\00"
define void @ls_files(i8* %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = bitcast %struct.timeval* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = tail call i32* @opendir(i8* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = tail call i8* @strerror(i64 %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
store i64 0, i64* @errno
%16 = tail call %struct.dirent* @readdir(i32* %7)
%17 = icmp eq %struct.dirent* %16, null
br i1 %17, label %38, label %18
18: ; preds = %14, %34
%19 = phi %struct.dirent* [ %36, %34 ], [ %16, %14 ]
%20 = phi i32 [ %35, %34 ], [ 0, %14 ]
br label %21
21: ; preds = %18, %31
%22 = phi %struct.dirent* [ %19, %18 ], [ %32, %31 ]
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i64 0, i32 0
%24 = load i32, i32* %23
%25 = tail call i64 @strcmp(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %21
%28 = load i32, i32* %23
%29 = tail call i64 @strcmp(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27, %21
store i64 0, i64* @errno
%32 = tail call %struct.dirent* @readdir(i32* %7)
%33 = icmp eq %struct.dirent* %32, null
br i1 %33, label %38, label %21
34: ; preds = %27
%35 = add nuw nsw i32 %20, 1
store i64 0, i64* @errno
%36 = tail call %struct.dirent* @readdir(i32* %7)
%37 = icmp eq %struct.dirent* %36, null
br i1 %37, label %38, label %18
38: ; preds = %34, %31, %14
%39 = phi i32 [ 0, %14 ], [ %20, %31 ], [ %35, %34 ]
%40 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%41 = load i64, i64* @errno
%42 = icmp eq i64 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %38
%44 = tail call i8* @strerror(i64 %41)
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %38
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%51 = load i32, i32* %50
%52 = sub nsw i32 %49, %51
%53 = mul nsw i32 %52, 1000000
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%55 = load i64, i64* %54
%56 = trunc i64 %55 to i32
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%58 = load i64, i64* %57
%59 = trunc i64 %58 to i32
%60 = add i32 %53, %56
%61 = sub i32 %60, %59
%62 = sdiv i32 %61, 1000
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %39, i32 %62)
%64 = tail call i32 @closedir(i32* %7)
ret void
}