#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 {
  scalar_t__ st_ctime;
};
struct dirent {
  char *d_name;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int nebula_timesort(const void *a, const void *b) {
  struct dirent **A, **B;
  struct stat sta, stb;
  memset(&sta, 0, sizeof(struct stat));
  memset(&stb, 0, sizeof(struct stat));
  A = (struct dirent **)a;
  B = (struct dirent **)b;
  if ((stat((*A)->d_name, &sta) != 0) || (stat((*B)->d_name, &stb) != 0)) {
    fprintf(stderr, "Error - Unable to get file status for %s, %s: %m.\n",
            (*A)->d_name, (*B)->d_name);
    exit(EXIT_FAILURE);
  }
  if (sta.st_ctime < stb.st_ctime)
    return (-1);
  if (sta.st_ctime > stb.st_ctime)
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<nebula_timesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    11ba <nebula_timesort+0x7a>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
je     11f1 <nebula_timesort+0xb1>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rcx
lea    0xe22(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    120b <nebula_timesort+0xcb>
movl   $0xffffffff,-0x4(%rbp)
jmp    122c <nebula_timesort+0xec>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jle    1225 <nebula_timesort+0xe5>
movl   $0x1,-0x4(%rbp)
jmp    122c <nebula_timesort+0xec>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nebula_timesort>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    (%r15),%rax
mov    (%rax),%rdi
mov    %rbx,%rsi
call   1050 <stat@plt>
test   %rax,%rax
jne    11b8 <nebula_timesort+0x78>
mov    (%r14),%rax
mov    (%rax),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %rax,%rax
jne    11b8 <nebula_timesort+0x78>
mov    0x8(%rsp),%rax
xor    %ecx,%ecx
cmp    (%rsp),%rax
setg   %cl
mov    $0xffffffff,%eax
cmovge %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rax
mov    (%rax),%rdx
mov    (%r14),%rax
mov    (%rax),%rcx
lea    0xe2c(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [51 x i8] c"Error - Unable to get file status for %s, %s: %m.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @nebula_timesort(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.dirent**
%7 = alloca %struct.dirent**
%8 = alloca %struct.stat
%9 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = call i32 @memset(%struct.stat* %8, i32 0, i32 8)
%11 = call i32 @memset(%struct.stat* %9, i32 0, i32 8)
%12 = load i8*, i8** %4
%13 = bitcast i8* %12 to %struct.dirent**
store %struct.dirent** %13, %struct.dirent*** %6
%14 = load i8*, i8** %5
%15 = bitcast i8* %14 to %struct.dirent**
store %struct.dirent** %15, %struct.dirent*** %7
%16 = load %struct.dirent**, %struct.dirent*** %6
%17 = load %struct.dirent*, %struct.dirent** %16
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = call i64 @stat(i8* %19, %struct.stat* %8)
%21 = icmp ne i64 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %2
%23 = load %struct.dirent**, %struct.dirent*** %7
%24 = load %struct.dirent*, %struct.dirent** %23
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = call i64 @stat(i8* %26, %struct.stat* %9)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %22, %2
%30 = load i32, i32* @stderr
%31 = load %struct.dirent**, %struct.dirent*** %6
%32 = load %struct.dirent*, %struct.dirent** %31
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = load %struct.dirent**, %struct.dirent*** %7
%36 = load %struct.dirent*, %struct.dirent** %35
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %22
%43 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%44 = load i64, i64* %43
%45 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%46 = load i64, i64* %45
%47 = icmp slt i64 %44, %46
br i1 %47, label %48, label %49
48: ; preds = %42
store i32 -1, i32* %3
br label %57
49: ; preds = %42
%50 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%51 = load i64, i64* %50
%52 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%53 = load i64, i64* %52
%54 = icmp sgt i64 %51, %53
br i1 %54, label %55, label %56
55: ; preds = %49
store i32 1, i32* %3
br label %57
56: ; preds = %49
store i32 0, i32* %3
br label %57
57: ; preds = %56, %55, %48
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [51 x i8] c"Error - Unable to get file status for %s, %s: %m.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @nebula_timesort(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = call i32 @memset(%struct.stat* %3, i32 0, i32 8)
%8 = call i32 @memset(%struct.stat* %4, i32 0, i32 8)
%9 = bitcast i8* %0 to %struct.dirent**
%10 = bitcast i8* %1 to %struct.dirent**
%11 = load %struct.dirent*, %struct.dirent** %9
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = call i64 @stat(i8* %13, %struct.stat* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load %struct.dirent*, %struct.dirent** %10
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = call i64 @stat(i8* %19, %struct.stat* %4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %33, label %22
22: ; preds = %16, %2
%23 = load i32, i32* @stderr
%24 = load %struct.dirent*, %struct.dirent** %9
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = load %struct.dirent*, %struct.dirent** %10
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i64 0, i32 0
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %16
%34 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%35 = load i64, i64* %34
%36 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%37 = load i64, i64* %36
%38 = icmp slt i64 %35, %37
%39 = icmp sgt i64 %35, %37
%40 = zext i1 %39 to i32
%41 = select i1 %38, i32 -1, i32 %40
ret i32 %41
}