#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 */
typedef int /*<<< orphan*/ time_t;
struct stat {
  int /*<<< orphan*/ st_mode;
  int /*<<< orphan*/ st_mtime;
};
struct dirent {
  char const *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ smells_like_module(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strcmp(char const *, char *);
scalar_t__ strlen(char const *);
int any_modules_newer(const char *dirname, time_t mtime) {
  DIR *dir;
  struct dirent *dirent;
  dir = opendir(dirname);
  if (!dir)
    return 1;
  while ((dirent = readdir(dir)) != NULL) {
    struct stat st;
    char file[strlen(dirname) + 1 + strlen(dirent->d_name) + 1];
    if ((strcmp((dirent->d_name), (".")) == 0) ||
        (strcmp((dirent->d_name), ("..")) == 0))
      continue;
    sprintf(file, "%s/%s", dirname, dirent->d_name);
    if (lstat(file, &st) != 0)
      return 1;
    if (smells_like_module(dirent->d_name)) {
      if (st.st_mtime > mtime)
        return 1;
    } else if (S_ISDIR(st.st_mode)) {
      if (any_modules_newer(file, mtime))
        return 1;
    }
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<any_modules_newer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d3 <any_modules_newer+0x33>
movl   $0x1,-0x4(%rbp)
jmp    138a <any_modules_newer+0x1ea>
jmp    11d8 <any_modules_newer+0x38>
mov    -0x20(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     137a <any_modules_newer+0x1da>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rcx
mov    %rax,%rdx
lea    0x2(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x38(%rbp)
lea    0x11(%rcx,%rdx,1),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xdbe(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     126f <any_modules_newer+0xcf>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xda0(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    127b <any_modules_newer+0xdb>
movl   $0x2,-0x44(%rbp)
jmp    1345 <any_modules_newer+0x1a5>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
lea    0xd72(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <lstat@plt>
cmp    $0x0,%rax
je     12c0 <any_modules_newer+0x120>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1345 <any_modules_newer+0x1a5>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1030 <smells_like_module@plt>
cmp    $0x0,%rax
je     12fa <any_modules_newer+0x15a>
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12f5 <any_modules_newer+0x155>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1345 <any_modules_newer+0x1a5>
jmp    133e <any_modules_newer+0x19e>
mov    -0x30(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1339 <any_modules_newer+0x199>
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <any_modules_newer@plt>
cmp    $0x0,%eax
je     1334 <any_modules_newer+0x194>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1345 <any_modules_newer+0x1a5>
jmp    1339 <any_modules_newer+0x199>
jmp    133e <any_modules_newer+0x19e>
movl   $0x0,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x44(%rbp),%eax
mov    %eax,-0x5c(%rbp)
test   %eax,%eax
je     1375 <any_modules_newer+0x1d5>
jmp    135f <any_modules_newer+0x1bf>
mov    -0x5c(%rbp),%eax
sub    $0x1,%eax
je     138a <any_modules_newer+0x1ea>
jmp    1370 <any_modules_newer+0x1d0>
jmp    11d8 <any_modules_newer+0x38>
jmp    11d8 <any_modules_newer+0x38>
mov    -0x20(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<any_modules_newer>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,-0x2c(%rbp)
mov    %rdi,-0x38(%rbp)
call   1040 <opendir@plt>
mov    %rax,%r13
mov    $0x1,%eax
test   %r13,%r13
je     12d6 <any_modules_newer+0x136>
mov    %r13,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     12cc <any_modules_newer+0x12c>
mov    %rax,%r14
jmp    1213 <any_modules_newer+0x73>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    -0x2c(%rbp),%eax
cmp    %eax,-0x3c(%rbp)
jg     12c2 <any_modules_newer+0x122>
mov    %r12,%rsp
mov    %r13,%rdi
call   10b0 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     12cc <any_modules_newer+0x12c>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    (%r14),%rdi
call   1050 <strlen@plt>
mov    %rsp,%r12
add    %rbx,%rax
add    $0x11,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    (%r14),%rdi
lea    0xdb9(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     11fc <any_modules_newer+0x5c>
mov    (%r14),%rdi
lea    0xda4(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     11fc <any_modules_newer+0x5c>
mov    (%r14),%rcx
mov    %r15,%rdi
lea    0xd90(%rip),%rsi
mov    -0x38(%rbp),%rdx
call   10c0 <sprintf@plt>
mov    %r15,%rdi
lea    -0x40(%rbp),%rsi
call   1090 <lstat@plt>
test   %rax,%rax
jne    12c2 <any_modules_newer+0x122>
mov    (%r14),%rdi
call   1030 <smells_like_module@plt>
test   %rax,%rax
jne    11f0 <any_modules_newer+0x50>
mov    -0x40(%rbp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     11fc <any_modules_newer+0x5c>
mov    %r15,%rdi
mov    -0x2c(%rbp),%esi
call   1070 <any_modules_newer@plt>
test   %eax,%eax
je     11fc <any_modules_newer+0x5c>
mov    %r12,%rsp
mov    $0x1,%eax
jmp    12d6 <any_modules_newer+0x136>
mov    %r13,%rdi
call   1080 <closedir@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32, i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @any_modules_newer(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca %struct.stat
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%12 = load i8*, i8** %4
%13 = call i32* @opendir(i8* %12)
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
store i32 1, i32* %3
br label %88
17: ; preds = %2
br label %18
18: ; preds = %84, %81, %17
%19 = load i32*, i32** %6
%20 = call %struct.dirent* @readdir(i32* %19)
store %struct.dirent* %20, %struct.dirent** %7
%21 = icmp ne %struct.dirent* %20, null
br i1 %21, label %22, label %85
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %24, 1
%26 = load %struct.dirent*, %struct.dirent** %7
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i64 @strlen(i8* %28)
%30 = add nsw i64 %25, %29
%31 = add nsw i64 %30, 1
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %9
%33 = alloca i8, i64 %31
store i64 %31, i64* %10
%34 = load %struct.dirent*, %struct.dirent** %7
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %22
%40 = load %struct.dirent*, %struct.dirent** %7
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39, %22
store i32 2, i32* %11
br label %81
46: ; preds = %39
%47 = load i8*, i8** %4
%48 = load %struct.dirent*, %struct.dirent** %7
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i8*, i8** %49
%51 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %47, i8* %50)
%52 = call i64 @lstat(i8* %33, %struct.stat* %8)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %46
store i32 1, i32* %3
store i32 1, i32* %11
br label %81
55: ; preds = %46
%56 = load %struct.dirent*, %struct.dirent** %7
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %56, i32 0, i32 0
%58 = load i8*, i8** %57
%59 = call i64 @smells_like_module(i8* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %55
%62 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%63 = load i32, i32* %62
%64 = load i32, i32* %5
%65 = icmp sgt i32 %63, %64
br i1 %65, label %66, label %67
66: ; preds = %61
store i32 1, i32* %3
store i32 1, i32* %11
br label %81
67: ; preds = %61
br label %80
68: ; preds = %55
%69 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i64 @S_ISDIR(i32 %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %68
%74 = load i32, i32* %5
%75 = call i32 @any_modules_newer(i8* %33, i32 %74)
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %73
store i32 1, i32* %3
store i32 1, i32* %11
br label %81
78: ; preds = %73
br label %79
79: ; preds = %78, %68
br label %80
80: ; preds = %79, %67
store i32 0, i32* %11
br label %81
81: ; preds = %80, %77, %66, %54, %45
%82 = load i8*, i8** %9
%83 = load i32, i32* %11
switch i32 %83, label %90 [
i32 0, label %84
i32 2, label %18
i32 1, label %88
]
84: ; preds = %81
br label %18
85: ; preds = %18
%86 = load i32*, i32** %6
%87 = call i32 @closedir(i32* %86)
store i32 0, i32* %3
br label %88
88: ; preds = %85, %81, %16
%89 = load i32, i32* %3
ret i32 %89
90: ; preds = %81
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @any_modules_newer(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = tail call i32* @opendir(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %55, label %6
6: ; preds = %2
%7 = call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %53, label %9
9: ; preds = %6
%10 = bitcast %struct.stat* %3 to i8*
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %13
13: ; preds = %9, %50
%14 = phi %struct.dirent* [ %7, %9 ], [ %51, %50 ]
%15 = call i64 @strlen(i8* dereferenceable(1) %0)
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = call i64 @strlen(i8* dereferenceable(1) %17)
%19 = add i64 %15, 2
%20 = add i64 %19, %18
%21 = call i8* @llvm.stacksave()
%22 = alloca i8, i64 %20
%23 = load i8*, i8** %16
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %50, label %26
26: ; preds = %13
%27 = load i8*, i8** %16
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %50, label %30
30: ; preds = %26
%31 = load i8*, i8** %16
%32 = call i32 @sprintf(i8* %22, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %31)
%33 = call i64 @lstat(i8* %22, %struct.stat* %3)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %49
35: ; preds = %30
%36 = load i8*, i8** %16
%37 = call i64 @smells_like_module(i8* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = load i32, i32* %11
%41 = icmp sgt i32 %40, %1
br i1 %41, label %49, label %50
42: ; preds = %35
%43 = load i32, i32* %12
%44 = call i64 @S_ISDIR(i32 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = call i32 @any_modules_newer(i8* %22, i32 %1)
%48 = icmp eq i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %30, %39, %46
br label %55
50: ; preds = %39, %46, %42, %13, %26
%51 = call %struct.dirent* @readdir(i32* %4)
%52 = icmp eq %struct.dirent* %51, null
br i1 %52, label %53, label %13
53: ; preds = %50, %6
%54 = call i32 @closedir(i32* %4)
br label %55
55: ; preds = %49, %2, %53
%56 = phi i32 [ 0, %53 ], [ 1, %2 ], [ 1, %49 ]
ret i32 %56
}