#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 {
  scalar_t__ st_dev;
};
typedef scalar_t__ dev_t;

/* Variables and functions */
int ENOENT;
int /*<<< orphan*/ assert(int);
scalar_t__ lstat(char *, struct stat *);
int nuke(char *);
int snprintf(char *, int, char *, char const *, char const *);
int strlen(char const *);
int nuke_dirent(int len, const char *dir, const char *name, dev_t me) {
  int bytes = len + strlen(name) + 2;
  char path[bytes];
  int xlen;
  struct stat st;
  xlen = snprintf(path, bytes, "%s/%s", dir, name);
  assert(xlen < bytes);
  if (lstat(path, &st))
    return ENOENT;
  if (st.st_dev != me)
    return 0;
  return nuke(path);
}


x86 assembly (clang, -O0):
<nuke_dirent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x5c(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x2(%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe42(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x58(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
je     1208 <nuke_dirent+0xb8>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    123c <nuke_dirent+0xec>
mov    -0x48(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1229 <nuke_dirent+0xd9>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    123c <nuke_dirent+0xec>
mov    -0x58(%rbp),%rdi
call   1070 <nuke@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nuke_dirent>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebx
mov    %rdx,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%r13d
add    $0x2,%r13d
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe6f(%rip),%rdx
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r12,%rcx
mov    %r15,%r8
call   1040 <snprintf@plt>
xor    %edi,%edi
cmp    %r13d,%eax
setl   %dil
call   1060 <assert@plt>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <lstat@plt>
test   %rax,%rax
je     11cc <nuke_dirent+0x7c>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
jmp    11dc <nuke_dirent+0x8c>
xor    %eax,%eax
cmp    %r14,-0x30(%rbp)
jne    11dc <nuke_dirent+0x8c>
mov    %rbx,%rdi
call   1070 <nuke@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [6 x i8] c"%s/%s\00"
@ENOENT = global i32 0
define i32 @nuke_dirent(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca %struct.stat
%15 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%16 = load i32, i32* %6
%17 = load i8*, i8** %8
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %16, %18
%20 = add nsw i32 %19, 2
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %11
%24 = alloca i8, i64 %22
store i64 %22, i64* %12
%25 = load i32, i32* %10
%26 = load i8*, i8** %7
%27 = load i8*, i8** %8
%28 = call i32 @snprintf(i8* %24, i32 %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %26, i8* %27)
store i32 %28, i32* %13
%29 = load i32, i32* %13
%30 = load i32, i32* %10
%31 = icmp slt i32 %29, %30
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i64 @lstat(i8* %24, %struct.stat* %14)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %4
%37 = load i32, i32* @ENOENT
store i32 %37, i32* %5
store i32 1, i32* %15
br label %46
38: ; preds = %4
%39 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%40 = load i64, i64* %39
%41 = load i64, i64* %9
%42 = icmp ne i64 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 0, i32* %5
store i32 1, i32* %15
br label %46
44: ; preds = %38
%45 = call i32 @nuke(i8* %24)
store i32 %45, i32* %5
store i32 1, i32* %15
br label %46
46: ; preds = %44, %43, %36
%47 = load i8*, i8** %11
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [6 x i8] c"%s/%s\00"
@ENOENT = global i32 0
define i32 @nuke_dirent(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca %struct.stat
%6 = tail call i32 @strlen(i8* %2)
%7 = add i32 %0, 2
%8 = add i32 %7, %6
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = bitcast %struct.stat* %5 to i8*
%12 = call i32 @snprintf(i8* %10, i32 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%13 = icmp slt i32 %12, %8
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i64 @lstat(i8* %10, %struct.stat* %5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %4
%19 = load i32, i32* @ENOENT
br label %26
20: ; preds = %4
%21 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, %3
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @nuke(i8* %10)
br label %26
26: ; preds = %20, %24, %18
%27 = phi i32 [ %19, %18 ], [ %25, %24 ], [ 0, %20 ]
ret i32 %27
}