#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 */
scalar_t__ ENOENT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ errno;
scalar_t__ lstat(char *, struct stat *);
int unlink(char *);
int /*<<< orphan*/ writestr(int, char *);
int rmfile(char *name) {
  struct stat st;
  if (lstat(name, &st)) {
    if (errno == ENOENT) {
      writestr(2, "rm: ");
      writestr(2, name);
      writestr(2, ": not found\n");
    }
    return -1;
  }
  if (S_ISDIR(st.st_mode)) {
    writestr(2, "rm: ");
    writestr(2, name);
    writestr(2, ": is dir\n");
    return -1;
  }
  return unlink(name);
}


x86 assembly (clang, -O0):
<rmfile>:
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    $0x0,%rax
je     11b9 <rmfile+0x79>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
jne    11ad <rmfile+0x6d>
mov    $0x2,%edi
lea    0xe77(%rip),%rsi
call   1060 <writestr@plt>
mov    -0x10(%rbp),%rsi
mov    $0x2,%edi
call   1060 <writestr@plt>
mov    $0x2,%edi
lea    0xe5d(%rip),%rsi
call   1060 <writestr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <rmfile+0xd3>
mov    -0x18(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1207 <rmfile+0xc7>
mov    $0x2,%edi
lea    0xe29(%rip),%rsi
call   1060 <writestr@plt>
mov    -0x10(%rbp),%rsi
mov    $0x2,%edi
call   1060 <writestr@plt>
mov    $0x2,%edi
lea    0xe1c(%rip),%rsi
call   1060 <writestr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <rmfile+0xd3>
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):
<rmfile>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <lstat@plt>
test   %rax,%rax
je     1194 <rmfile+0x54>
mov    0x2e82(%rip),%rax
mov    (%rax),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    11d1 <rmfile+0x91>
lea    0xe8c(%rip),%rsi
mov    $0x2,%edi
call   1060 <writestr@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
call   1060 <writestr@plt>
lea    0xe73(%rip),%rsi
jmp    11c7 <rmfile+0x87>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     11dc <rmfile+0x9c>
lea    0xe57(%rip),%rsi
mov    $0x2,%edi
call   1060 <writestr@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
call   1060 <writestr@plt>
lea    0xe4b(%rip),%rsi
mov    $0x2,%edi
call   1060 <writestr@plt>
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 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [5 x i8] c"rm: \00"
@.str.1 = [13 x i8] c": not found\0A\00"
@.str.2 = [10 x i8] c": is dir\0A\00"
define i32 @rmfile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @lstat(i8* %5, %struct.stat* %4)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %3
%15 = call i32 @writestr(i32 2, i8* %14)
%16 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %12, %8
store i32 -1, i32* %2
br label %31
18: ; preds = %1
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @S_ISDIR(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%25 = load i8*, i8** %3
%26 = call i32 @writestr(i32 2, i8* %25)
%27 = call i32 @writestr(i32 2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %31
28: ; preds = %18
%29 = load i8*, i8** %3
%30 = call i32 @unlink(i8* %29)
store i32 %30, i32* %2
br label %31
31: ; preds = %28, %23, %17
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@.str = [5 x i8] c"rm: \00"
@.str.1 = [13 x i8] c": not found\0A\00"
@.str.2 = [10 x i8] c": is dir\0A\00"
define i32 @rmfile(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @lstat(i8* %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOENT
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %25
10: ; preds = %6
%11 = tail call i32 @writestr(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @writestr(i32 2, i8* %0)
%13 = tail call i32 @writestr(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %25
14: ; preds = %1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i64 @S_ISDIR(i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = tail call i32 @writestr(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @writestr(i32 2, i8* %0)
%22 = tail call i32 @writestr(i32 2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %25
23: ; preds = %14
%24 = tail call i32 @unlink(i8* %0)
br label %25
25: ; preds = %6, %10, %23, %19
%26 = phi i32 [ -1, %19 ], [ %24, %23 ], [ -1, %10 ], [ -1, %6 ]
ret i32 %26
}