#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;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ stat(char *, struct stat *);
int unlink(char *);
int rm(char *name) {
  struct stat sb;
  if (stat(name, &sb) < 0)
    return (-1);
  if (!S_ISREG(sb.st_mode)) {
    errno = EISDIR;
    return (-1);
  }
  return (unlink(name));
}


x86 assembly (clang, -O0):
<rm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    115f <rm+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <rm+0x6a>
mov    -0x18(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%eax
jne    118e <rm+0x5e>
mov    0x2e71(%rip),%rax
mov    (%rax),%ecx
mov    0x2e58(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <rm+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):
<rm>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1040 <stat@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     1172 <rm+0x42>
mov    (%rsp),%edi
call   1050 <S_ISREG@plt>
test   %eax,%eax
je     1160 <rm+0x30>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %eax,%ebp
jmp    1172 <rm+0x42>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    0x2e68(%rip),%rcx
mov    %eax,(%rcx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@EISDIR = global i32 0
@errno = global i32 0
define i32 @rm(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 @stat(i8* %5, %struct.stat* %4)
%7 = icmp slt i64 %6, 0
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 i32 @S_ISREG(i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %16, label %14
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 @rm(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
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 = call i32 @S_ISREG(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = load i32, i32* @EISDIR
store i32 %12, i32* @errno
br label %15
13: ; preds = %6
%14 = call i32 @unlink(i8* %0)
br label %15
15: ; preds = %1, %13, %11
%16 = phi i32 [ %14, %13 ], [ -1, %11 ], [ -1, %1 ]
ret i32 %16
}