#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 */
typedef int uint8_t;

/* Variables and functions */
int PATH_MAX;
scalar_t__ bsd_basename(char *, char *);
int /*<<< orphan*/ dirname_inplace(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ *realpath(char const *, char *);
int snapshot_ctl(char *, char *, int /*<<< orphan*/ *, int /*<<< orphan*/, int);
char *strerr(int /*<<< orphan*/);
int remove_snapshot(const char *dstname, uint8_t smode) {
  char dstpath[PATH_MAX + 1], base[PATH_MAX + 1], dir[PATH_MAX + 1];
  if (realpath(dstname, dstpath) == NULL) {
    printf("%s: realpath error on %s: %s\n", dstname, dstpath, strerr(errno));
  }
  memcpy(dir, dstpath, PATH_MAX + 1);
  dirname_inplace(dir);
  if (bsd_basename(dstpath, base) < 0) {
    printf("%s: basename error\n", dstpath);
    return -1;
  }
  return snapshot_ctl(dir, base, NULL, 0, smode | 0x80);
}


x86 assembly (clang, -O0):
<remove_snapshot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rsi
sub    %rdx,%rsi
mov    %rsi,-0x58(%rbp)
mov    %rsi,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rcx,%rdi
add    $0xf,%rdi
and    $0xfffffffffffffff0,%rdi
mov    %rsp,%rdx
sub    %rdi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <realpath@plt>
cmp    $0x0,%rax
jne    1232 <remove_snapshot+0xc2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerr@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%rdi
mov    0x2daf(%rip),%rax
mov    (%rax),%edx
add    $0x1,%edx
call   1060 <memcpy@plt>
mov    -0x48(%rbp),%rdi
call   1080 <dirname_inplace@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1030 <bsd_basename@plt>
cmp    $0x0,%rax
jge    1290 <remove_snapshot+0x120>
mov    -0x58(%rbp),%rsi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    12b8 <remove_snapshot+0x148>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%r8d
or     $0x80,%r8d
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <snapshot_ctl@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_snapshot>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r13
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %rbx,%rsi
call   1050 <realpath@plt>
test   %rax,%rax
jne    11e5 <remove_snapshot+0x75>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1090 <strerr@plt>
lea    0xe2b(%rip),%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
add    $0x1,%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <memcpy@plt>
mov    %r12,%rdi
call   1080 <dirname_inplace@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <bsd_basename@plt>
test   %rax,%rax
js     122f <remove_snapshot+0xbf>
or     $0x80,%r14d
mov    %r12,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14d,%r8d
call   1070 <snapshot_ctl@plt>
jmp    1245 <remove_snapshot+0xd5>
lea    0xde8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [30 x i8] c"%s: realpath error on %s: %s\0A\00"
@errno = global i32 0
@.str.1 = [20 x i8] c"%s: basename error\0A\00"
define i32 @remove_snapshot(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i32, i32* @PATH_MAX
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i32, i32* @PATH_MAX
%17 = add nsw i32 %16, 1
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %8
%20 = load i32, i32* @PATH_MAX
%21 = add nsw i32 %20, 1
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %9
%24 = load i8*, i8** %4
%25 = call i32* @realpath(i8* %24, i8* %15)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %32
27: ; preds = %2
%28 = load i8*, i8** %4
%29 = load i32, i32* @errno
%30 = call i8* @strerr(i32 %29)
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %15, i8* %30)
br label %32
32: ; preds = %27, %2
%33 = load i32, i32* @PATH_MAX
%34 = add nsw i32 %33, 1
%35 = call i32 @memcpy(i8* %23, i8* %15, i32 %34)
%36 = call i32 @dirname_inplace(i8* %23)
%37 = call i64 @bsd_basename(i8* %15, i8* %19)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
store i32 1, i32* %10
br label %45
41: ; preds = %32
%42 = load i32, i32* %5
%43 = or i32 %42, 128
%44 = call i32 @snapshot_ctl(i8* %23, i8* %19, i32* null, i32 0, i32 %43)
store i32 %44, i32* %3
store i32 1, i32* %10
br label %45
45: ; preds = %41, %39
%46 = load i8*, i8** %6
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [30 x i8] c"%s: realpath error on %s: %s\0A\00"
@errno = global i32 0
@.str.1 = [20 x i8] c"%s: basename error\0A\00"
define i32 @remove_snapshot(i8* %0, i32 %1) {
%3 = load i32, i32* @PATH_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = alloca i8, i64 %5
%9 = call i32* @realpath(i8* %0, i8* %6)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i8* @strerr(i32 %12)
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %6, i8* %13)
br label %15
15: ; preds = %11, %2
%16 = load i32, i32* @PATH_MAX
%17 = add nsw i32 %16, 1
%18 = call i32 @memcpy(i8* %8, i8* %6, i32 %17)
%19 = call i32 @dirname_inplace(i8* %8)
%20 = call i64 @bsd_basename(i8* %6, i8* %7)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %27
24: ; preds = %15
%25 = or i32 %1, 128
%26 = call i32 @snapshot_ctl(i8* %8, i8* %7, i32* null, i32 0, i32 %25)
br label %27
27: ; preds = %24, %22
%28 = phi i32 [ -1, %22 ], [ %26, %24 ]
ret i32 %28
}