#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 timesort(const struct dirent **a, const struct dirent **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):
<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 <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 <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 <timesort+0xcb>
movl   $0xffffffff,-0x4(%rbp)
jmp    122c <timesort+0xec>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jle    1225 <timesort+0xe5>
movl   $0x1,-0x4(%rbp)
jmp    122c <timesort+0xec>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<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 <timesort+0x78>
mov    (%r14),%rax
mov    (%rax),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %rax,%rax
jne    11b8 <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 @timesort(%struct.dirent** %0, %struct.dirent** %1) {
%3 = alloca i32
%4 = alloca %struct.dirent**
%5 = alloca %struct.dirent**
%6 = alloca %struct.dirent**
%7 = alloca %struct.dirent**
%8 = alloca %struct.stat
%9 = alloca %struct.stat
store %struct.dirent** %0, %struct.dirent*** %4
store %struct.dirent** %1, %struct.dirent*** %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 %struct.dirent**, %struct.dirent*** %4
store %struct.dirent** %12, %struct.dirent*** %6
%13 = load %struct.dirent**, %struct.dirent*** %5
store %struct.dirent** %13, %struct.dirent*** %7
%14 = load %struct.dirent**, %struct.dirent*** %6
%15 = load %struct.dirent*, %struct.dirent** %14
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = call i64 @stat(i8* %17, %struct.stat* %8)
%19 = icmp ne i64 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %2
%21 = load %struct.dirent**, %struct.dirent*** %7
%22 = load %struct.dirent*, %struct.dirent** %21
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i64 @stat(i8* %24, %struct.stat* %9)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %20, %2
%28 = load i32, i32* @stderr
%29 = load %struct.dirent**, %struct.dirent*** %6
%30 = load %struct.dirent*, %struct.dirent** %29
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = load %struct.dirent**, %struct.dirent*** %7
%34 = load %struct.dirent*, %struct.dirent** %33
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %32, i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %20
%41 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%42 = load i64, i64* %41
%43 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%44 = load i64, i64* %43
%45 = icmp slt i64 %42, %44
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 -1, i32* %3
br label %55
47: ; preds = %40
%48 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%49 = load i64, i64* %48
%50 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%51 = load i64, i64* %50
%52 = icmp sgt i64 %49, %51
br i1 %52, label %53, label %54
53: ; preds = %47
store i32 1, i32* %3
br label %55
54: ; preds = %47
store i32 0, i32* %3
br label %55
55: ; preds = %54, %53, %46
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%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 @timesort(%struct.dirent** nocapture %0, %struct.dirent** 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 = load %struct.dirent*, %struct.dirent** %0
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = call i64 @stat(i8* %11, %struct.stat* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load %struct.dirent*, %struct.dirent** %1
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = call i64 @stat(i8* %17, %struct.stat* %4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %31, label %20
20: ; preds = %14, %2
%21 = load i32, i32* @stderr
%22 = load %struct.dirent*, %struct.dirent** %0
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = load %struct.dirent*, %struct.dirent** %1
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i64 0, i32 0
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %14
%32 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%33 = load i64, i64* %32
%34 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%35 = load i64, i64* %34
%36 = icmp slt i64 %33, %35
%37 = icmp sgt i64 %33, %35
%38 = zext i1 %37 to i32
%39 = select i1 %36, i32 -1, i32 %38
ret i32 %39
}