#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*/ st_mtime;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int PATH_MAX;
int /*<<< orphan*/ _log(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int depfile_up_to_date_dir(int /*<<< orphan*/ *, int /*<<< orphan*/, size_t,
                           char *);
int /*<<< orphan*/ dirfd(int /*<<< orphan*/ *);
int errno;
scalar_t__ fstatat(int /*<<< orphan*/, char *, struct stat *,
                   int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ *opendir(char const *);
size_t strlen(char const *);
int depfile_up_to_date(const char *dirname) {
  char path[PATH_MAX];
  DIR *d = opendir(dirname);
  struct stat st;
  size_t baselen;
  int err;
  if (d == NULL) {
    err = -errno;
    _log(LOG_ERR, "could not open directory %s: %m\n", dirname);
    return err;
  }
  if (fstatat(dirfd(d), "modules.dep", &st, 0) != 0) {
    err = -errno;
    _log(LOG_ERR, "could not fstatat(%s, modules.dep): %m\n", dirname);
    closedir(d);
    return err;
  }
  baselen = strlen(dirname);
  memcpy(path, dirname, baselen);
  path[baselen] = '/';
  baselen++;
  path[baselen] = '\0';
  err = depfile_up_to_date_dir(d, st.st_mtime, baselen, path);
  closedir(d);
  return err;
}


x86 assembly (clang, -O0):
<depfile_up_to_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1209 <depfile_up_to_date+0x89>
xor    %eax,%eax
mov    0x2dff(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe0e(%rip),%rsi
call   1030 <_log@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    12d9 <depfile_up_to_date+0x159>
mov    -0x28(%rbp),%rdi
call   1070 <dirfd@plt>
mov    %eax,%edi
lea    0xe06(%rip),%rsi
lea    -0x30(%rbp),%rdx
xor    %ecx,%ecx
call   10a0 <fstatat@plt>
cmp    $0x0,%rax
je     1272 <depfile_up_to_date+0xf2>
xor    %eax,%eax
mov    0x2d9f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xddb(%rip),%rsi
call   1030 <_log@plt>
mov    -0x28(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    12d9 <depfile_up_to_date+0x159>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1080 <memcpy@plt>
mov    -0x48(%rbp),%rcx
mov    -0x38(%rbp),%rax
movb   $0x2f,(%rcx,%rax,1)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rcx,%rax,1)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x38(%rbp),%rdx
call   1090 <depfile_up_to_date_dir@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<depfile_up_to_date>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1040 <opendir@plt>
test   %rax,%rax
je     1201 <depfile_up_to_date+0x81>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <dirfd@plt>
lea    0xe59(%rip),%rsi
lea    -0x28(%rbp),%rdx
xor    %r12d,%r12d
mov    %eax,%edi
xor    %ecx,%ecx
call   10a0 <fstatat@plt>
test   %rax,%rax
je     1228 <depfile_up_to_date+0xa8>
mov    0x2df4(%rip),%rax
sub    (%rax),%r12d
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
mov    %r14,%rdx
call   1030 <_log@plt>
jmp    1260 <depfile_up_to_date+0xe0>
mov    0x2dd0(%rip),%rax
xor    %r12d,%r12d
sub    (%rax),%r12d
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
mov    %r14,%rdx
call   1030 <_log@plt>
jmp    1268 <depfile_up_to_date+0xe8>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1080 <memcpy@plt>
movw   $0x2f,(%rbx,%r12,1)
add    $0x1,%r12
mov    -0x28(%rbp),%esi
mov    %r15,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1090 <depfile_up_to_date_dir@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1060 <closedir@plt>
mov    %r12d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@errno = global i32 0
@LOG_ERR = global i32 0
@.str = [33 x i8] c"could not open directory %s: %m\0A\00"
@.str.1 = [12 x i8] c"modules.dep\00"
@.str.2 = [40 x i8] c"could not fstatat(%s, modules.dep): %m\0A\00"
define i32 @depfile_up_to_date(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca %struct.stat
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
%15 = load i8*, i8** %3
%16 = call i32* @opendir(i8* %15)
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %26
19: ; preds = %1
%20 = load i32, i32* @errno
%21 = sub nsw i32 0, %20
store i32 %21, i32* %9
%22 = load i32, i32* @LOG_ERR
%23 = load i8*, i8** %3
%24 = call i32 @_log(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %9
store i32 %25, i32* %2
store i32 1, i32* %10
br label %60
26: ; preds = %1
%27 = load i32*, i32** %6
%28 = call i32 @dirfd(i32* %27)
%29 = call i64 @fstatat(i32 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %7, i32 0)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %26
%32 = load i32, i32* @errno
%33 = sub nsw i32 0, %32
store i32 %33, i32* %9
%34 = load i32, i32* @LOG_ERR
%35 = load i8*, i8** %3
%36 = call i32 @_log(i32 %34, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %6
%38 = call i32 @closedir(i32* %37)
%39 = load i32, i32* %9
store i32 %39, i32* %2
store i32 1, i32* %10
br label %60
40: ; preds = %26
%41 = load i8*, i8** %3
%42 = call i64 @strlen(i8* %41)
store i64 %42, i64* %8
%43 = load i8*, i8** %3
%44 = load i64, i64* %8
%45 = call i32 @memcpy(i8* %14, i8* %43, i64 %44)
%46 = load i64, i64* %8
%47 = getelementptr inbounds i8, i8* %14, i64 %46
store i8 47, i8* %47
%48 = load i64, i64* %8
%49 = add i64 %48, 1
store i64 %49, i64* %8
%50 = load i64, i64* %8
%51 = getelementptr inbounds i8, i8* %14, i64 %50
store i8 0, i8* %51
%52 = load i32*, i32** %6
%53 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%54 = load i32, i32* %53
%55 = load i64, i64* %8
%56 = call i32 @depfile_up_to_date_dir(i32* %52, i32 %54, i64 %55, i8* %14)
store i32 %56, i32* %9
%57 = load i32*, i32** %6
%58 = call i32 @closedir(i32* %57)
%59 = load i32, i32* %9
store i32 %59, i32* %2
store i32 1, i32* %10
br label %60
60: ; preds = %40, %31, %19
%61 = load i8*, i8** %4
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@errno = global i32 0
@LOG_ERR = global i32 0
@.str = [33 x i8] c"could not open directory %s: %m\0A\00"
@.str.1 = [12 x i8] c"modules.dep\00"
@.str.2 = [40 x i8] c"could not fstatat(%s, modules.dep): %m\0A\00"
define i32 @depfile_up_to_date(i8* %0) {
%2 = alloca %struct.stat
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32* @opendir(i8* %0)
%7 = bitcast %struct.stat* %2 to i8*
%8 = icmp eq i32* %6, null
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = sub nsw i32 0, %10
%12 = load i32, i32* @LOG_ERR
%13 = tail call i32 @_log(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %34
14: ; preds = %1
%15 = tail call i32 @dirfd(i32* %6)
%16 = call i64 @fstatat(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %2, i32 0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = sub nsw i32 0, %19
%21 = load i32, i32* @LOG_ERR
%22 = call i32 @_log(i32 %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%23 = call i32 @closedir(i32* %6)
br label %34
24: ; preds = %14
%25 = call i64 @strlen(i8* dereferenceable(1) %0)
%26 = call i32 @memcpy(i8* %5, i8* %0, i64 %25)
%27 = getelementptr inbounds i8, i8* %5, i64 %25
store i8 47, i8* %27
%28 = add i64 %25, 1
%29 = getelementptr inbounds i8, i8* %5, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @depfile_up_to_date_dir(i32* %6, i32 %31, i64 %28, i8* %5)
%33 = call i32 @closedir(i32* %6)
br label %34
34: ; preds = %24, %18, %9
%35 = phi i32 [ %11, %9 ], [ %20, %18 ], [ %32, %24 ]
ret i32 %35
}