#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 __S_IFMT;
int rm_dir(char *);
scalar_t__ stat(char *, struct stat *);
int unlink(char *);
int f_rm(char *fpath) {
  struct stat st;
  if (stat(fpath, &st))
    return -1;
  if (!((((st.st_mode)) & __S_IFMT) == (__S_IFDIR)))
    return unlink(fpath);
  return rm_dir(fpath);
}


x86 assembly (clang, -O0):
<f_rm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
je     115f <f_rm+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <f_rm+0x67>
mov    -0x18(%rbp),%eax
mov    0x2e77(%rip),%rcx
and    (%rcx),%eax
mov    0x2e76(%rip),%rcx
cmp    (%rcx),%eax
je     118b <f_rm+0x5b>
mov    -0x10(%rbp),%rdi
call   1040 <unlink@plt>
mov    %eax,-0x4(%rbp)
jmp    1197 <f_rm+0x67>
mov    -0x10(%rbp),%rdi
call   1030 <rm_dir@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_rm>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1179 <f_rm+0x49>
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%eax
jne    1171 <f_rm+0x41>
mov    %rbx,%rdi
call   1030 <rm_dir@plt>
jmp    1179 <f_rm+0x49>
mov    %rbx,%rdi
call   1040 <unlink@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@__S_IFMT = global i32 0
@__S_IFDIR = global i32 0
define i32 @f_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 ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %22
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @__S_IFMT
%13 = and i32 %11, %12
%14 = load i32, i32* @__S_IFDIR
%15 = icmp eq i32 %13, %14
br i1 %15, label %19, label %16
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = call i32 @unlink(i8* %17)
store i32 %18, i32* %2
br label %22
19: ; preds = %9
%20 = load i8*, i8** %3
%21 = call i32 @rm_dir(i8* %20)
store i32 %21, i32* %2
br label %22
22: ; preds = %19, %16, %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@__S_IFMT = global i32 0
@__S_IFDIR = global i32 0
define i32 @f_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 eq i64 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @__S_IFMT
%10 = and i32 %9, %8
%11 = load i32, i32* @__S_IFDIR
%12 = icmp eq i32 %10, %11
br i1 %12, label %15, label %13
13: ; preds = %6
%14 = call i32 @unlink(i8* %0)
br label %17
15: ; preds = %6
%16 = call i32 @rm_dir(i8* %0)
br label %17
17: ; preds = %1, %15, %13
%18 = phi i32 [ %16, %15 ], [ %14, %13 ], [ -1, %1 ]
ret i32 %18
}