#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 scalar_t__ time_t;
struct stat {
  scalar_t__ st_mtime;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ EISDIR;
scalar_t__ ENOENT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
scalar_t__ errno;
int lstat(char *, struct stat *);
int /*<<< orphan*/ printf(char *, int);
int is_emacs_valid(int debugflag) {
  struct stat sb;
  int ret;
  time_t lastMod;
  ret = lstat("/usr/bin"
              "/emacs-"
              "x86_64",
              &sb);
  if (ret == -1) {
    if (errno == ENOENT) {
      return 0;
    } else {
      return -1;
    }
  }
  if (S_ISDIR(sb.st_mode)) {
    errno = EISDIR;
    return -1;
  } else if (!S_ISREG(sb.st_mode)) {
    return 0;
  }
  lastMod = sb.st_mtime;
  ret = lstat("/usr/bin"
              "/emacs",
              &sb);
  if (ret == -1) {
    return -1;
  }
  if (sb.st_mtime > lastMod) {
    return 0;
  }
  ret = lstat("/usr/libexec"
              "/dumpemacs",
              &sb);
  if (ret == -1) {
    return -1;
  }
  if (sb.st_mtime > lastMod) {
    return 0;
  }
  if (debugflag > 0) {
    printf("debugflag is %d.\n", debugflag);
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_emacs_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeae(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <lstat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    119a <is_emacs_valid+0x5a>
mov    0x2e69(%rip),%rax
mov    (%rax),%rax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
jne    118e <is_emacs_valid+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    129c <is_emacs_valid+0x15c>
movl   $0xffffffff,-0x4(%rbp)
jmp    129c <is_emacs_valid+0x15c>
mov    -0x10(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11cc <is_emacs_valid+0x8c>
mov    0x2e35(%rip),%rax
mov    (%rax),%rcx
mov    0x2e1b(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    129c <is_emacs_valid+0x15c>
mov    -0x10(%rbp),%edi
call   1060 <S_ISREG@plt>
cmp    $0x0,%eax
jne    11e9 <is_emacs_valid+0xa9>
movl   $0x0,-0x4(%rbp)
jmp    129c <is_emacs_valid+0x15c>
jmp    11ee <is_emacs_valid+0xae>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe19(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <lstat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    121f <is_emacs_valid+0xdf>
movl   $0xffffffff,-0x4(%rbp)
jmp    129c <is_emacs_valid+0x15c>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    1239 <is_emacs_valid+0xf9>
movl   $0x0,-0x4(%rbp)
jmp    129c <is_emacs_valid+0x15c>
lea    0xde5(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <lstat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1262 <is_emacs_valid+0x122>
movl   $0xffffffff,-0x4(%rbp)
jmp    129c <is_emacs_valid+0x15c>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    127c <is_emacs_valid+0x13c>
movl   $0x0,-0x4(%rbp)
jmp    129c <is_emacs_valid+0x15c>
cmpl   $0x0,-0x8(%rbp)
jle    1295 <is_emacs_valid+0x155>
mov    -0x8(%rbp),%esi
lea    0xdac(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_emacs_valid>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xeaf(%rip),%rdi
mov    %rsp,%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
je     1189 <is_emacs_valid+0x49>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     11a7 <is_emacs_valid+0x67>
mov    0x2e73(%rip),%rax
mov    (%rax),%rax
mov    0x2e59(%rip),%rcx
mov    %rax,(%rcx)
mov    $0xffffffff,%ebp
jmp    11d7 <is_emacs_valid+0x97>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    0x2e2e(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
setne  %bpl
neg    %ebp
jmp    11d7 <is_emacs_valid+0x97>
mov    %ebp,%edi
call   1060 <S_ISREG@plt>
test   %eax,%eax
je     11d5 <is_emacs_valid+0x95>
mov    (%rsp),%r14
lea    0xe59(%rip),%rdi
mov    %rsp,%rsi
call   1050 <lstat@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11d7 <is_emacs_valid+0x97>
cmp    %r14,(%rsp)
jle    11e2 <is_emacs_valid+0xa2>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe3c(%rip),%rdi
mov    %rsp,%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
je     11d7 <is_emacs_valid+0x97>
mov    $0x0,%ebp
cmp    %r14,(%rsp)
jg     11d7 <is_emacs_valid+0x97>
mov    $0x1,%ebp
test   %ebx,%ebx
jle    11d7 <is_emacs_valid+0x97>
lea    0xe2b(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
jmp    11d7 <is_emacs_valid+0x97>

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
@.str = [22 x i8] c"/usr/bin/emacs-x86_64\00"
@errno = global i64 0
@ENOENT = global i64 0
@EISDIR = global i64 0
@.str.1 = [15 x i8] c"/usr/bin/emacs\00"
@.str.2 = [23 x i8] c"/usr/libexec/dumpemacs\00"
@.str.3 = [18 x i8] c"debugflag is %d.\0A\00"
define i32 @is_emacs_valid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %3
%7 = call i32 @lstat(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %struct.stat* %4)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %1
%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 0, i32* %2
br label %61
15: ; preds = %10
store i32 -1, i32* %2
br label %61
16: ; preds = %1
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i64, i64* @EISDIR
store i64 %22, i64* @errno
store i32 -1, i32* %2
br label %61
23: ; preds = %16
%24 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%25 = load i32, i32* %24
%26 = call i32 @S_ISREG(i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %23
store i32 0, i32* %2
br label %61
29: ; preds = %23
br label %30
30: ; preds = %29
%31 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%32 = load i64, i64* %31
store i64 %32, i64* %6
%33 = call i32 @lstat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %4)
store i32 %33, i32* %5
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 -1, i32* %2
br label %61
37: ; preds = %30
%38 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%39 = load i64, i64* %38
%40 = load i64, i64* %6
%41 = icmp sgt i64 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %37
store i32 0, i32* %2
br label %61
43: ; preds = %37
%44 = call i32 @lstat(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %4)
store i32 %44, i32* %5
%45 = load i32, i32* %5
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 -1, i32* %2
br label %61
48: ; preds = %43
%49 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%50 = load i64, i64* %49
%51 = load i64, i64* %6
%52 = icmp sgt i64 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %48
store i32 0, i32* %2
br label %61
54: ; preds = %48
%55 = load i32, i32* %3
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i32, i32* %3
%59 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %57, %54
store i32 1, i32* %2
br label %61
61: ; preds = %60, %53, %47, %42, %36, %28, %21, %15, %14
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
@.str = [22 x i8] c"/usr/bin/emacs-x86_64\00"
@errno = global i64 0
@ENOENT = global i64 0
@EISDIR = global i64 0
@.str.1 = [15 x i8] c"/usr/bin/emacs\00"
@.str.2 = [23 x i8] c"/usr/libexec/dumpemacs\00"
@.str.3 = [18 x i8] c"debugflag is %d.\0A\00"
define i32 @is_emacs_valid(i32 %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @lstat(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOENT
%9 = icmp ne i64 %7, %8
%10 = sext i1 %9 to i32
br label %39
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%13 = load i32, i32* %12
%14 = tail call i64 @S_ISDIR(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = load i64, i64* @EISDIR
store i64 %17, i64* @errno
br label %39
18: ; preds = %11
%19 = tail call i32 @S_ISREG(i32 %13)
%20 = icmp eq i32 %19, 0
br i1 %20, label %39, label %21
21: ; preds = %18
%22 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%23 = load i64, i64* %22
%24 = call i32 @lstat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %2)
%25 = icmp eq i32 %24, -1
br i1 %25, label %39, label %26
26: ; preds = %21
%27 = load i64, i64* %22
%28 = icmp sgt i64 %27, %23
br i1 %28, label %39, label %29
29: ; preds = %26
%30 = call i32 @lstat(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %2)
%31 = icmp eq i32 %30, -1
br i1 %31, label %39, label %32
32: ; preds = %29
%33 = load i64, i64* %22
%34 = icmp sgt i64 %33, %23
br i1 %34, label %39, label %35
35: ; preds = %32
%36 = icmp sgt i32 %0, 0
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %39
39: ; preds = %35, %37, %32, %29, %26, %21, %18, %6, %16
%40 = phi i32 [ -1, %16 ], [ %10, %6 ], [ 0, %18 ], [ -1, %21 ], [ 0, %26 ], [ -1, %29 ], [ 0, %32 ], [ 1, %37 ], [ 1, %35 ]
ret i32 %40
}