#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;
};

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ cli_fatal(char *, char const *, int /*<<< orphan*/);
scalar_t__ errno;
int stat(char const *, struct stat *);
int /*<<< orphan*/ strerror(scalar_t__);
int cli_file_requires_build(struct stat *fst, const char *opath) {
  struct stat ost;
  if (stat(opath, &ost) == -1) {
    if (errno == ENOENT)
      return (1);
    cli_fatal("stat(%s): %s", opath, strerror(errno));
  }
  return (fst->st_mtime != ost.st_mtime);
}


x86 assembly (clang, -O0):
<cli_file_requires_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
jne    11a5 <cli_file_requires_build+0x75>
mov    0x2e83(%rip),%rax
mov    (%rax),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    117c <cli_file_requires_build+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    11bb <cli_file_requires_build+0x8b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe60(%rip),%rdi
call   1040 <cli_fatal@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_file_requires_build>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
jne    117b <cli_file_requires_build+0x4b>
mov    0x2e8f(%rip),%rax
mov    (%rax),%rdi
mov    0x2e75(%rip),%rcx
mov    $0x1,%eax
cmp    (%rcx),%rdi
je     1187 <cli_file_requires_build+0x57>
call   1050 <strerror@plt>
lea    0xe8f(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <cli_fatal@plt>
mov    (%r14),%rcx
xor    %eax,%eax
cmp    (%rsp),%rcx
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [13 x i8] c"stat(%s): %s\00"
define i32 @cli_file_requires_build(%struct.stat* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.stat*
%5 = alloca i8*
%6 = alloca %struct.stat
store %struct.stat* %0, %struct.stat** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @stat(i8* %7, %struct.stat* %6)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %20
10: ; preds = %2
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOENT
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 1, i32* %3
br label %28
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i64, i64* @errno
%18 = call i32 @strerror(i64 %17)
%19 = call i32 @cli_fatal(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %18)
br label %20
20: ; preds = %15, %2
%21 = load %struct.stat*, %struct.stat** %4
%22 = getelementptr inbounds %struct.stat, %struct.stat* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%25 = load i64, i64* %24
%26 = icmp ne i64 %23, %25
%27 = zext i1 %26 to i32
store i32 %27, i32* %3
br label %28
28: ; preds = %20, %14
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [13 x i8] c"stat(%s): %s\00"
define i32 @cli_file_requires_build(%struct.stat* nocapture %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @stat(i8* %1, %struct.stat* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOENT
%10 = icmp eq i64 %8, %9
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = tail call i32 @strerror(i64 %8)
%13 = tail call i32 @cli_fatal(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %12)
br label %14
14: ; preds = %11, %2
%15 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = load i64, i64* %17
%19 = icmp ne i64 %16, %18
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %7, %14
%22 = phi i32 [ %20, %14 ], [ 1, %7 ]
ret i32 %22
}