#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 {
  int st_mode;
};

/* Variables and functions */
int S_IFDIR;
int /*<<< orphan*/ elg_warning(char *, char *, char const *);
char const *epk_archive_get_name();
scalar_t__ stat(char const *, struct stat *);
int epk_archive_verify(const char *dir) {
  struct stat statbuf;
  const char *archive_path = dir ? dir : epk_archive_get_name();
  int blocked = (stat(archive_path, &statbuf) == 0);
  if (blocked) {
    elg_warning("Abort: new measurement blocked by existing %s %s",
                (statbuf.st_mode & S_IFDIR) ? "directory" : "file",
                archive_path);
  }
  return !blocked;
}


x86 assembly (clang, -O0):
<epk_archive_verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1154 <epk_archive_verify+0x24>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    115f <epk_archive_verify+0x2f>
mov    $0x0,%al
call   1030 <epk_archive_get_name@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11be <epk_archive_verify+0x8e>
mov    -0x10(%rbp),%ecx
mov    0x2e41(%rip),%rax
and    (%rax),%ecx
lea    0xe9b(%rip),%rsi
lea    0xe8a(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x18(%rbp),%rdx
lea    0xe47(%rip),%rdi
call   1040 <elg_warning@plt>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<epk_archive_verify>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1146 <epk_archive_verify+0x16>
xor    %eax,%eax
call   1030 <epk_archive_get_name@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1186 <epk_archive_verify+0x56>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
lea    0xecf(%rip),%rax
lea    0xebe(%rip),%rsi
cmove  %rax,%rsi
lea    0xe82(%rip),%rdi
mov    %rbx,%rdx
call   1040 <elg_warning@plt>
xor    %eax,%eax
test   %r14,%r14
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [49 x i8] c"Abort: new measurement blocked by existing %s %s\00"
@S_IFDIR = global i32 0
@.str.1 = [10 x i8] c"directory\00"
@.str.2 = [5 x i8] c"file\00"
define i32 @epk_archive_verify(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i8*, i8** %2
br label %12
10: ; preds = %1
%11 = call i8* (...) @epk_archive_get_name()
br label %12
12: ; preds = %10, %8
%13 = phi i8* [ %9, %8 ], [ %11, %10 ]
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i64 @stat(i8* %14, %struct.stat* %3)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %12
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i32, i32* @S_IFDIR
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%28 = load i8*, i8** %4
%29 = call i32 @elg_warning(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %28)
br label %30
30: ; preds = %20, %12
%31 = load i32, i32* %5
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
%34 = zext i1 %33 to i32
ret i32 %34
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [49 x i8] c"Abort: new measurement blocked by existing %s %s\00"
@S_IFDIR = global i32 0
@.str.1 = [10 x i8] c"directory\00"
@.str.2 = [5 x i8] c"file\00"
define i32 @epk_archive_verify(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i8* (...) @epk_archive_get_name()
br label %7
7: ; preds = %1, %5
%8 = phi i8* [ %6, %5 ], [ %0, %1 ]
%9 = call i64 @stat(i8* %8, %struct.stat* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* @S_IFDIR
%15 = and i32 %14, %13
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0)
%18 = call i32 @elg_warning(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %8)
br label %19
19: ; preds = %11, %7
%20 = xor i1 %10, true
%21 = zext i1 %20 to i32
ret i32 %21
}