#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 {
  char *d_name;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ snprintf(char *, scalar_t__, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
scalar_t__ strlen(char *);
int compare_files(const void *left, const void *right) {
  struct stat lbuf, rbuf;
  struct dirent *l = *(struct dirent **)left;
  struct dirent *r = *(struct dirent **)right;
  char *filename = malloc(16 + strlen(l->d_name));
  snprintf(filename, 16 + strlen(l->d_name), "./include/blog/%s", l->d_name);
  stat(filename, &lbuf);
  free(filename);
  filename = malloc(16 + strlen(r->d_name));
  snprintf(filename, 16 + strlen(r->d_name), "./include/blog/%s", r->d_name);
  stat(filename, &rbuf);
  if (lbuf.st_mtime < rbuf.st_mtime)
    return 1;
  if (rbuf.st_mtime < lbuf.st_mtime)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<compare_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x10,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rsi
add    $0x10,%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
lea    0xe41(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x10,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
add    $0x10,%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%rcx
lea    0xddd(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    124f <compare_files+0xff>
movl   $0x1,-0x4(%rbp)
jmp    1270 <compare_files+0x120>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1269 <compare_files+0x119>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <compare_files+0x120>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_files>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%rax
mov    (%rsi),%r13
mov    (%rax),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x10(%rax),%r12
mov    %r12,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe7c(%rip),%r14
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x0(%r13),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x10(%rax),%rbx
mov    %rbx,%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <snprintf@plt>
mov    %rsp,%rsi
mov    %r12,%rdi
call   1060 <stat@plt>
mov    0x8(%rsp),%rax
mov    (%rsp),%rcx
xor    %edx,%edx
cmp    %rax,%rcx
setl   %dl
neg    %edx
cmp    %rcx,%rax
mov    $0x1,%eax
cmovge %edx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
%struct.dirent = type { i8* }
@.str = [18 x i8] c"./include/blog/%s\00"
define i32 @compare_files(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = alloca %struct.stat
%8 = alloca %struct.dirent*
%9 = alloca %struct.dirent*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to %struct.dirent**
%13 = load %struct.dirent*, %struct.dirent** %12
store %struct.dirent* %13, %struct.dirent** %8
%14 = load i8*, i8** %5
%15 = bitcast i8* %14 to %struct.dirent**
%16 = load %struct.dirent*, %struct.dirent** %15
store %struct.dirent* %16, %struct.dirent** %9
%17 = load %struct.dirent*, %struct.dirent** %8
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 16, %20
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %10
%23 = load i8*, i8** %10
%24 = load %struct.dirent*, %struct.dirent** %8
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 16, %27
%29 = load %struct.dirent*, %struct.dirent** %8
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @snprintf(i8* %23, i64 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %10
%34 = call i32 @stat(i8* %33, %struct.stat* %6)
%35 = load i8*, i8** %10
%36 = call i32 @free(i8* %35)
%37 = load %struct.dirent*, %struct.dirent** %9
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 0
%39 = load i8*, i8** %38
%40 = call i64 @strlen(i8* %39)
%41 = add nsw i64 16, %40
%42 = call i8* @malloc(i64 %41)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
%44 = load %struct.dirent*, %struct.dirent** %9
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i64 @strlen(i8* %46)
%48 = add nsw i64 16, %47
%49 = load %struct.dirent*, %struct.dirent** %9
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 @snprintf(i8* %43, i64 %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %51)
%53 = load i8*, i8** %10
%54 = call i32 @stat(i8* %53, %struct.stat* %7)
%55 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%56 = load i64, i64* %55
%57 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%58 = load i64, i64* %57
%59 = icmp slt i64 %56, %58
br i1 %59, label %60, label %61
60: ; preds = %2
store i32 1, i32* %3
br label %69
61: ; preds = %2
%62 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%63 = load i64, i64* %62
%64 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%65 = load i64, i64* %64
%66 = icmp slt i64 %63, %65
br i1 %66, label %67, label %68
67: ; preds = %61
store i32 -1, i32* %3
br label %69
68: ; preds = %61
store i32 0, i32* %3
br label %69
69: ; preds = %68, %67, %60
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.dirent = type { i8* }
@.str = [18 x i8] c"./include/blog/%s\00"
define i32 @compare_files(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 = bitcast i8* %0 to %struct.dirent**
%8 = load %struct.dirent*, %struct.dirent** %7
%9 = bitcast i8* %1 to %struct.dirent**
%10 = load %struct.dirent*, %struct.dirent** %9
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%14 = add nsw i64 %13, 16
%15 = tail call i8* @malloc(i64 %14)
%16 = tail call i32 @snprintf(i8* %15, i64 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %12)
%17 = call i32 @stat(i8* %15, %struct.stat* %3)
%18 = tail call i32 @free(i8* %15)
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = tail call i64 @strlen(i8* dereferenceable(1) %20)
%22 = add nsw i64 %21, 16
%23 = tail call i8* @malloc(i64 %22)
%24 = tail call i32 @snprintf(i8* %23, i64 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %20)
%25 = call i32 @stat(i8* %23, %struct.stat* %4)
%26 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%27 = load i64, i64* %26
%28 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%29 = load i64, i64* %28
%30 = icmp slt i64 %27, %29
%31 = icmp slt i64 %29, %27
%32 = sext i1 %31 to i32
%33 = select i1 %30, i32 1, i32 %32
ret i32 %33
}