#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ EISDIR;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int lstat(char const *, struct stat *);
int unlink(char const *);
int eunlink(const char *file) {
  struct stat st;
  if (lstat(file, &st) == -1)
    return (-1);
  if (S_ISDIR(st.st_mode)) {
    errno = EISDIR;
    return (-1);
  }
  return (unlink(file));
}


x86 assembly (clang, -O0):
<eunlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
jne    115e <eunlink+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <eunlink+0x6a>
mov    -0x18(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     118e <eunlink+0x5e>
mov    0x2e71(%rip),%rax
mov    (%rax),%ecx
mov    0x2e58(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <eunlink+0x6a>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eunlink>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
je     1167 <eunlink+0x37>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     1172 <eunlink+0x42>
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    0x2e73(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <unlink@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@EISDIR = global i32 0
@errno = global i32 0
define i32 @eunlink(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @lstat(i8* %5, %struct.stat* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %19
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i64 @S_ISDIR(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = load i32, i32* @EISDIR
store i32 %15, i32* @errno
store i32 -1, i32* %2
br label %19
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = call i32 @unlink(i8* %17)
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %14, %8
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EISDIR = global i32 0
@errno = global i32 0
define i32 @eunlink(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @lstat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @S_ISDIR(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = load i32, i32* @EISDIR
store i32 %12, i32* @errno
br label %15
13: ; preds = %6
%14 = tail call i32 @unlink(i8* %0)
br label %15
15: ; preds = %1, %13, %11
%16 = phi i32 [ -1, %11 ], [ %14, %13 ], [ -1, %1 ]
ret i32 %16
}