#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 time_t;
struct stat {
  int st_mtime;
};

/* Variables and functions */
#define ENOENT 128
int errno;
int stat(char const *, struct stat *);
time_t file_get_mtime(const char *filename) {
  time_t mtac;
  struct stat statent;
  int statret = stat(filename, &statent);
  if (errno > 0 && statret == -1) {
    switch (errno) {
    case ENOENT:
      return 0;
    default:
      return -1;
    }
  } else {
    mtac = statent.st_mtime;
  }
  return mtac;
}


x86 assembly (clang, -O0):
<file_get_mtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2ead(%rip),%rax
cmpl   $0x0,(%rax)
jle    1177 <file_get_mtime+0x67>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1177 <file_get_mtime+0x67>
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    116b <file_get_mtime+0x5b>
jmp    115f <file_get_mtime+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1183 <file_get_mtime+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <file_get_mtime+0x73>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_get_mtime>:
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
mov    0x2ec0(%rip),%rcx
mov    (%rcx),%edx
xor    %ecx,%ecx
cmp    $0x80,%edx
setne  %cl
neg    %ecx
test   %edx,%edx
mov    (%rsp),%edx
cmovle %edx,%ecx
cmp    $0xffffffff,%eax
cmovne %edx,%ecx
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i32 0
define i32 @file_get_mtime(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @stat(i8* %7, %struct.stat* %5)
store i32 %8, i32* %6
%9 = load i32, i32* @errno
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @errno
switch i32 %15, label %17 [
i32 128, label %16
]
16: ; preds = %14
store i32 0, i32* %2
br label %23
17: ; preds = %14
store i32 -1, i32* %2
br label %23
18: ; preds = %11, %1
%19 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%20 = load i32, i32* %19
store i32 %20, i32* %4
br label %21
21: ; preds = %18
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %23
23: ; preds = %21, %17, %16
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i32 0
define i32 @file_get_mtime(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = load i32, i32* @errno
%6 = icmp sgt i32 %5, 0
%7 = icmp eq i32 %4, -1
%8 = and i1 %7, %6
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp ne i32 %5, 128
%12 = sext i1 %11 to i32
%13 = select i1 %8, i32 %12, i32 %10
ret i32 %13
}