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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ makeDirectories(char const *, size_t const, size_t const,
                                   int, int /*<<< orphan*/ *);
int /*<<< orphan*/ readDirectories(char const *, size_t const, size_t const,
                                   int, int /*<<< orphan*/ *);
int stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
double const timedouble();
int main() {
  const size_t KB = 360;
  fprintf(stderr, "Starting test: %.1lf MB\n", KB / 1000.0);
  const size_t count = 10000;
  const char *directory = "test";
  struct stat st = {0};
  if (stat(directory, &st) == -1) {
    fprintf(stderr, "*error* please create a directory called '%s'\n",
            directory);
    exit(-1);
  }
  for (size_t r = 0; r < 10; r++) {
    const double start = timedouble();
    makeDirectories(directory, KB, count, 16384, NULL);
    const double elapsed = timedouble() - start;
    fprintf(stderr,
            "create/write: %zd in %.3lf seconds, %.2lf files per second (%zd "
            "MB, %.0lf MB/s)\n",
            count, elapsed, count / elapsed, count * KB / 1000,
            count * KB / 1000.0 / elapsed);
  }
  for (size_t r = 0; r < 10; r++) {
    const double start = timedouble();
    readDirectories(directory, KB, count, 16384, NULL);
    const double elapsed = timedouble() - start;
    fprintf(stderr,
            "read: %zd in %.3lf seconds, %.2lf files per second (%zd MB, %.0lf "
            "MB/s)\n",
            count, elapsed, count / elapsed, count * KB / 1000,
            count * KB / 1000.0 / elapsed);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x168,-0x10(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
movsd  0xe61(%rip),%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
movq   $0x2710,-0x18(%rbp)
lea    0xe7c(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    1204 <main+0x94>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movq   $0x0,-0x30(%rbp)
cmpq   $0xa,-0x30(%rbp)
jae    12a2 <main+0x132>
mov    $0x0,%al
call   1070 <timedouble@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x168,%esi
mov    $0x2710,%edx
mov    $0x4000,%ecx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <makeDirectories@plt>
mov    $0x0,%al
call   1070 <timedouble@plt>
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
movsd  -0x40(%rbp),%xmm0
movsd  0xda9(%rip),%xmm1
divsd  -0x40(%rbp),%xmm1
movsd  0xd94(%rip),%xmm2
divsd  -0x40(%rbp),%xmm2
lea    0xde5(%rip),%rsi
mov    $0x2710,%edx
mov    $0xe10,%ecx
mov    $0x3,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    120c <main+0x9c>
movq   $0x0,-0x48(%rbp)
cmpq   $0xa,-0x48(%rbp)
jae    1340 <main+0x1d0>
mov    $0x0,%al
call   1070 <timedouble@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x168,%esi
mov    $0x2710,%edx
mov    $0x4000,%ecx
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <readDirectories@plt>
mov    $0x0,%al
call   1070 <timedouble@plt>
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
movsd  -0x58(%rbp),%xmm0
movsd  0xd0b(%rip),%xmm1
divsd  -0x58(%rbp),%xmm1
movsd  0xcf6(%rip),%xmm2
divsd  -0x58(%rbp),%xmm2
lea    0xd98(%rip),%rsi
mov    $0x2710,%edx
mov    $0xe10,%ecx
mov    $0x3,%al
call   1050 <fprintf@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    12aa <main+0x13a>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e6e(%rip),%r15
mov    (%r15),%edi
lea    0xe9c(%rip),%rsi
movsd  0xe7c(%rip),%xmm0
mov    $0x1,%al
call   1040 <fprintf@plt>
movl   $0x0,0x10(%rsp)
lea    0xe97(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     12b7 <main+0x157>
mov    $0xa,%ebx
lea    0xe78(%rip),%r14
lea    0xea5(%rip),%r12
xor    %eax,%eax
call   1060 <timedouble@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x168,%esi
mov    $0x2710,%edx
mov    %r14,%rdi
mov    $0x4000,%ecx
xor    %r8d,%r8d
call   1030 <makeDirectories@plt>
xor    %eax,%eax
call   1060 <timedouble@plt>
subsd  0x8(%rsp),%xmm0
mov    (%r15),%edi
movsd  0xe09(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xe05(%rip),%xmm2
divsd  %xmm0,%xmm2
mov    $0x2710,%edx
mov    $0xe10,%ecx
mov    %r12,%rsi
mov    $0x3,%al
call   1040 <fprintf@plt>
add    $0xffffffffffffffff,%rbx
jne    11c0 <main+0x60>
mov    $0xa,%ebx
lea    0xdfc(%rip),%r14
lea    0xe7a(%rip),%r12
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <timedouble@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x168,%esi
mov    $0x2710,%edx
mov    %r14,%rdi
mov    $0x4000,%ecx
xor    %r8d,%r8d
call   1070 <readDirectories@plt>
xor    %eax,%eax
call   1060 <timedouble@plt>
subsd  0x8(%rsp),%xmm0
mov    (%r15),%edi
movsd  0xd89(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xd85(%rip),%xmm2
divsd  %xmm0,%xmm2
mov    $0x2710,%edx
mov    $0xe10,%ecx
mov    %r12,%rsi
mov    $0x3,%al
call   1040 <fprintf@plt>
add    $0xffffffffffffffff,%rbx
jne    1240 <main+0xe0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%r15),%edi
lea    0xd75(%rip),%rsi
lea    0xd69(%rip),%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"Starting test: %.1lf MB\0A\00"
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [47 x i8] c"*error* please create a directory called '%s'\0A\00"
@.str.3 = [81 x i8] c"create/write: %zd in %.3lf seconds, %.2lf files per second (%zd MB, %.0lf MB/s)\0A\00"
@.str.4 = [73 x i8] c"read: %zd in %.3lf seconds, %.2lf files per second (%zd MB, %.0lf MB/s)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca i64
%10 = alloca double
%11 = alloca double
store i32 0, i32* %1
store i64 360, i64* %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double 3.600000e-01)
store i64 10000, i64* %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %4
%14 = bitcast %struct.stat* %5 to i8*
%15 = load i8*, i8** %4
%16 = call i32 @stat(i8* %15, %struct.stat* %5)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %0
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %4
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %0
store i64 0, i64* %6
br label %24
24: ; preds = %41, %23
%25 = load i64, i64* %6
%26 = icmp ult i64 %25, 10
br i1 %26, label %27, label %44
27: ; preds = %24
%28 = call double (...) @timedouble()
store double %28, double* %7
%29 = load i8*, i8** %4
%30 = call i32 @makeDirectories(i8* %29, i64 360, i64 10000, i32 16384, i32* null)
%31 = call double (...) @timedouble()
%32 = load double, double* %7
%33 = fsub double %31, %32
store double %33, double* %8
%34 = load i32, i32* @stderr
%35 = load double, double* %8
%36 = load double, double* %8
%37 = fdiv double 1.000000e+04, %36
%38 = load double, double* %8
%39 = fdiv double 3.600000e+03, %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.3, i64 0, i64 0), i64 10000, double %35, double %37, i64 3600, double %39)
br label %41
41: ; preds = %27
%42 = load i64, i64* %6
%43 = add i64 %42, 1
store i64 %43, i64* %6
br label %24
44: ; preds = %24
store i64 0, i64* %9
br label %45
45: ; preds = %62, %44
%46 = load i64, i64* %9
%47 = icmp ult i64 %46, 10
br i1 %47, label %48, label %65
48: ; preds = %45
%49 = call double (...) @timedouble()
store double %49, double* %10
%50 = load i8*, i8** %4
%51 = call i32 @readDirectories(i8* %50, i64 360, i64 10000, i32 16384, i32* null)
%52 = call double (...) @timedouble()
%53 = load double, double* %10
%54 = fsub double %52, %53
store double %54, double* %11
%55 = load i32, i32* @stderr
%56 = load double, double* %11
%57 = load double, double* %11
%58 = fdiv double 1.000000e+04, %57
%59 = load double, double* %11
%60 = fdiv double 3.600000e+03, %59
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.4, i64 0, i64 0), i64 10000, double %56, double %58, i64 3600, double %60)
br label %62
62: ; preds = %48
%63 = load i64, i64* %9
%64 = add i64 %63, 1
store i64 %64, i64* %9
br label %45
65: ; preds = %45
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"Starting test: %.1lf MB\0A\00"
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [47 x i8] c"*error* please create a directory called '%s'\0A\00"
@.str.3 = [81 x i8] c"create/write: %zd in %.3lf seconds, %.2lf files per second (%zd MB, %.0lf MB/s)\0A\00"
@.str.4 = [73 x i8] c"read: %zd in %.3lf seconds, %.2lf files per second (%zd MB, %.0lf MB/s)\0A\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = load i32, i32* @stderr
%3 = tail call i32 (i32, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double 3.600000e-01)
%4 = bitcast %struct.stat* %1 to i8*
%5 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
store i32 0, i32* %5
%6 = call i32 @stat(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %0, %12
%13 = phi i64 [ %22, %12 ], [ 0, %0 ]
%14 = tail call double (...) @timedouble()
%15 = tail call i32 @makeDirectories(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 360, i64 10000, i32 16384, i32* null)
%16 = tail call double (...) @timedouble()
%17 = fsub double %16, %14
%18 = load i32, i32* @stderr
%19 = fdiv double 1.000000e+04, %17
%20 = fdiv double 3.600000e+03, %17
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.3, i64 0, i64 0), i64 10000, double %17, double %19, i64 3600, double %20)
%22 = add nuw nsw i64 %13, 1
%23 = icmp eq i64 %22, 10
br i1 %23, label %25, label %12
24: ; preds = %25
ret i32 0
25: ; preds = %12, %25
%26 = phi i64 [ %35, %25 ], [ 0, %12 ]
%27 = tail call double (...) @timedouble()
%28 = tail call i32 @readDirectories(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 360, i64 10000, i32 16384, i32* null)
%29 = tail call double (...) @timedouble()
%30 = fsub double %29, %27
%31 = load i32, i32* @stderr
%32 = fdiv double 1.000000e+04, %30
%33 = fdiv double 3.600000e+03, %30
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.4, i64 0, i64 0), i64 10000, double %30, double %32, i64 3600, double %33)
%35 = add nuw nsw i64 %26, 1
%36 = icmp eq i64 %35, 10
br i1 %36, label %24, label %25
}