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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(int /*<<< orphan*/, struct stat *);
int datesort(const struct dirent **a, const struct dirent **b) {
  struct stat st_a, st_b;
  if (stat(a[0]->d_name, &st_a)) {
    perror("stat failed");
    return 0;
  }
  if (stat(b[0]->d_name, &st_b)) {
    perror("stat failed");
    return 0;
  }
  if (st_a.st_mtime > st_b.st_mtime)
    return 1;
  if (st_a.st_mtime < st_b.st_mtime)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<datesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     1164 <datesort+0x44>
lea    0xead(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <datesort+0xb3>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     1198 <datesort+0x78>
lea    0xe79(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <datesort+0xb3>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    11b2 <datesort+0x92>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <datesort+0xb3>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    11cc <datesort+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <datesort+0xb3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<datesort>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    (%rdi),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %rax,%rax
jne    1168 <datesort+0x48>
mov    (%rbx),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <stat@plt>
test   %rax,%rax
jne    1168 <datesort+0x48>
mov    (%rsp),%rcx
mov    $0x1,%eax
cmp    %rcx,0x8(%rsp)
jg     1176 <datesort+0x56>
setl   %al
movzbl %al,%eax
neg    %eax
jmp    1176 <datesort+0x56>
lea    0xe91(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
%struct.stat = type { i64 }
@.str = [12 x i8] c"stat failed\00"
define i32 @datesort(%struct.dirent** %0, %struct.dirent** %1) {
%3 = alloca i32
%4 = alloca %struct.dirent**
%5 = alloca %struct.dirent**
%6 = alloca %struct.stat
%7 = alloca %struct.stat
store %struct.dirent** %0, %struct.dirent*** %4
store %struct.dirent** %1, %struct.dirent*** %5
%8 = load %struct.dirent**, %struct.dirent*** %4
%9 = getelementptr inbounds %struct.dirent*, %struct.dirent** %8, i64 0
%10 = load %struct.dirent*, %struct.dirent** %9
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @stat(i32 %12, %struct.stat* %6)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %42
17: ; preds = %2
%18 = load %struct.dirent**, %struct.dirent*** %5
%19 = getelementptr inbounds %struct.dirent*, %struct.dirent** %18, i64 0
%20 = load %struct.dirent*, %struct.dirent** %19
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @stat(i32 %22, %struct.stat* %7)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %42
27: ; preds = %17
%28 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%31 = load i64, i64* %30
%32 = icmp sgt i64 %29, %31
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 1, i32* %3
br label %42
34: ; preds = %27
%35 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%38 = load i64, i64* %37
%39 = icmp slt i64 %36, %38
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 -1, i32* %3
br label %42
41: ; preds = %34
store i32 0, i32* %3
br label %42
42: ; preds = %41, %40, %33, %25, %15
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
%struct.stat = type { i64 }
@.str = [12 x i8] c"stat failed\00"
define i32 @datesort(%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 = load %struct.dirent*, %struct.dirent** %0
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = call i64 @stat(i32 %9, %struct.stat* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %31
14: ; preds = %2
%15 = load %struct.dirent*, %struct.dirent** %1
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i64 @stat(i32 %17, %struct.stat* %4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %31
22: ; preds = %14
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%24 = load i64, i64* %23
%25 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%26 = load i64, i64* %25
%27 = icmp sgt i64 %24, %26
br i1 %27, label %31, label %28
28: ; preds = %22
%29 = icmp slt i64 %24, %26
%30 = sext i1 %29 to i32
br label %31
31: ; preds = %28, %22, %20, %12
%32 = phi i32 [ 0, %12 ], [ 0, %20 ], [ 1, %22 ], [ %30, %28 ]
ret i32 %32
}