#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 */
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef scalar_t__ time_t;
struct TYPE_5__ {
  scalar_t__ fts_info;
  TYPE_1__ *fts_statp;
};
struct TYPE_4__ {
  scalar_t__ st_mtime;
};
typedef TYPE_2__ FTSENT;
typedef int /*<<< orphan*/ FTS;

/* Variables and functions */
scalar_t__ FTS_F;
int /*<<< orphan*/ FTS_PHYSICAL;
scalar_t__ fts_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fts_open(char *const *, int /*<<< orphan*/,
                             int /*<<< orphan*/ *);
TYPE_2__ *fts_read(int /*<<< orphan*/ *);
time_t get_newest(char *const *path) {
  FTS *dh;
  FTSENT *entry;
  time_t newest = 0;
  dh = fts_open(path, FTS_PHYSICAL, NULL);
  if (dh == NULL) {
    return 0;
  }
  while ((entry = fts_read(dh)) != NULL) {
    if ((entry->fts_info != FTS_F) || (entry->fts_statp == NULL)) {
      continue;
    }
    if (entry->fts_statp->st_mtime > newest) {
      newest = entry->fts_statp->st_mtime;
    }
  }
  if (fts_close(dh) != 0) {
    return 0;
  }
  return newest;
}


x86 assembly (clang, -O0):
<get_newest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <fts_open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1176 <get_newest+0x46>
movq   $0x0,-0x8(%rbp)
jmp    120e <get_newest+0xde>
jmp    117b <get_newest+0x4b>
mov    -0x18(%rbp),%rdi
call   1040 <fts_read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11e6 <get_newest+0xb6>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%rax
jne    11b8 <get_newest+0x88>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11bd <get_newest+0x8d>
jmp    117b <get_newest+0x4b>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
jle    11e1 <get_newest+0xb1>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    117b <get_newest+0x4b>
mov    -0x18(%rbp),%rdi
call   1030 <fts_close@plt>
cmp    $0x0,%rax
je     1206 <get_newest+0xd6>
movq   $0x0,-0x8(%rbp)
jmp    120e <get_newest+0xde>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_newest>:
push   %r15
push   %r14
push   %rbx
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
call   1050 <fts_open@plt>
test   %rax,%rax
je     11ac <get_newest+0x7c>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fts_read@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     119a <get_newest+0x6a>
mov    0x2e79(%rip),%r14
jmp    117d <get_newest+0x4d>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <fts_read@plt>
test   %rax,%rax
je     119a <get_newest+0x6a>
mov    (%rax),%rcx
cmp    (%r14),%rcx
jne    1170 <get_newest+0x40>
mov    0x8(%rax),%rax
test   %rax,%rax
je     1170 <get_newest+0x40>
mov    (%rax),%rax
cmp    %r15,%rax
cmovg  %rax,%r15
jmp    1170 <get_newest+0x40>
mov    %rbx,%rdi
call   1030 <fts_close@plt>
xor    %r14d,%r14d
test   %rax,%rax
cmove  %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64, %struct.TYPE_4__* }
%struct.TYPE_4__ = type { i64 }
@FTS_PHYSICAL = global i32 0
@FTS_F = global i64 0
define i64 @get_newest(i8** %0) {
%2 = alloca i64
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca %struct.TYPE_5__*
%6 = alloca i64
store i8** %0, i8*** %3
store i64 0, i64* %6
%7 = load i8**, i8*** %3
%8 = load i32, i32* @FTS_PHYSICAL
%9 = call i32* @fts_open(i8** %7, i32 %8, i32* null)
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i64 0, i64* %2
br label %52
13: ; preds = %1
br label %14
14: ; preds = %44, %29, %13
%15 = load i32*, i32** %4
%16 = call %struct.TYPE_5__* @fts_read(i32* %15)
store %struct.TYPE_5__* %16, %struct.TYPE_5__** %5
%17 = icmp ne %struct.TYPE_5__* %16, null
br i1 %17, label %18, label %45
18: ; preds = %14
%19 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = load i64, i64* @FTS_F
%23 = icmp ne i64 %21, %22
br i1 %23, label %29, label %24
24: ; preds = %18
%25 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%26 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %25, i32 0, i32 1
%27 = load %struct.TYPE_4__*, %struct.TYPE_4__** %26
%28 = icmp eq %struct.TYPE_4__* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24, %18
br label %14
30: ; preds = %24
%31 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %31, i32 0, i32 1
%33 = load %struct.TYPE_4__*, %struct.TYPE_4__** %32
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = load i64, i64* %6
%37 = icmp sgt i64 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %30
%39 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%40 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %39, i32 0, i32 1
%41 = load %struct.TYPE_4__*, %struct.TYPE_4__** %40
%42 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %41, i32 0, i32 0
%43 = load i64, i64* %42
store i64 %43, i64* %6
br label %44
44: ; preds = %38, %30
br label %14
45: ; preds = %14
%46 = load i32*, i32** %4
%47 = call i64 @fts_close(i32* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %45
store i64 0, i64* %2
br label %52
50: ; preds = %45
%51 = load i64, i64* %6
store i64 %51, i64* %2
br label %52
52: ; preds = %50, %49, %12
%53 = load i64, i64* %2
ret i64 %53
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i64, %struct.TYPE_4__* }
%struct.TYPE_4__ = type { i64 }
@FTS_PHYSICAL = global i32 0
@FTS_F = global i64 0
define i64 @get_newest(i8** %0) {
%2 = load i32, i32* @FTS_PHYSICAL
%3 = tail call i32* @fts_open(i8** %0, i32 %2, i32* null)
%4 = icmp eq i32* %3, null
br i1 %4, label %36, label %5
5: ; preds = %1
%6 = tail call %struct.TYPE_5__* @fts_read(i32* %3)
%7 = icmp eq %struct.TYPE_5__* %6, null
br i1 %7, label %31, label %8
8: ; preds = %5, %24
%9 = phi %struct.TYPE_5__* [ %29, %24 ], [ %6, %5 ]
%10 = phi i64 [ %28, %24 ], [ 0, %5 ]
br label %11
11: ; preds = %8, %21
%12 = phi %struct.TYPE_5__* [ %9, %8 ], [ %22, %21 ]
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i64 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @FTS_F
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i64 0, i32 1
%19 = load %struct.TYPE_4__*, %struct.TYPE_4__** %18
%20 = icmp eq %struct.TYPE_4__* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17, %11
%22 = tail call %struct.TYPE_5__* @fts_read(i32* %3)
%23 = icmp eq %struct.TYPE_5__* %22, null
br i1 %23, label %31, label %11
24: ; preds = %17
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %19, i64 0, i32 0
%26 = load i64, i64* %25
%27 = icmp sgt i64 %26, %10
%28 = select i1 %27, i64 %26, i64 %10
%29 = tail call %struct.TYPE_5__* @fts_read(i32* %3)
%30 = icmp eq %struct.TYPE_5__* %29, null
br i1 %30, label %31, label %8
31: ; preds = %24, %21, %5
%32 = phi i64 [ 0, %5 ], [ %10, %21 ], [ %28, %24 ]
%33 = tail call i64 @fts_close(i32* %3)
%34 = icmp eq i64 %33, 0
%35 = select i1 %34, i64 %32, i64 0
br label %36
36: ; preds = %31, %1
%37 = phi i64 [ 0, %1 ], [ %35, %31 ]
ret i64 %37
}