#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 */

/* Variables and functions */
int AT_REMOVEDIR;
int dir_mutex_lock(int);
int /*<<< orphan*/ dir_mutex_unlock();
int rmdir(char const *);
int unlink(char const *);
int unlinkat(int dirfd, const char *pathname, int flags) {
  int rc;
  rc = dir_mutex_lock(dirfd);
  if (rc < 0)
    return rc;
  if (flags == AT_REMOVEDIR)
    rc = rmdir(pathname);
  else
    rc = unlink(pathname);
  dir_mutex_unlock();
  return rc;
}


x86 assembly (clang, -O0):
<unlinkat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <dir_mutex_lock@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1172 <unlinkat+0x32>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <unlinkat+0x6e>
mov    -0x14(%rbp),%eax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%eax
jne    1195 <unlinkat+0x55>
mov    -0x10(%rbp),%rdi
call   1050 <rmdir@plt>
mov    %eax,-0x18(%rbp)
jmp    11a1 <unlinkat+0x61>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <dir_mutex_unlock@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unlinkat>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
call   1040 <dir_mutex_lock@plt>
test   %eax,%eax
js     1167 <unlinkat+0x27>
mov    0x2e87(%rip),%rax
cmp    %ebp,(%rax)
jne    116b <unlinkat+0x2b>
mov    %r14,%rdi
call   1050 <rmdir@plt>
jmp    1173 <unlinkat+0x33>
mov    %eax,%ebx
jmp    117c <unlinkat+0x3c>
mov    %r14,%rdi
call   1030 <unlink@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <dir_mutex_unlock@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@AT_REMOVEDIR = global i32 0
define i32 @unlinkat(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = call i32 @dir_mutex_lock(i32 %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32, i32* %8
store i32 %14, i32* %4
br label %28
15: ; preds = %3
%16 = load i32, i32* %7
%17 = load i32, i32* @AT_REMOVEDIR
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = call i32 @rmdir(i8* %20)
store i32 %21, i32* %8
br label %25
22: ; preds = %15
%23 = load i8*, i8** %6
%24 = call i32 @unlink(i8* %23)
store i32 %24, i32* %8
br label %25
25: ; preds = %22, %19
%26 = call i32 (...) @dir_mutex_unlock()
%27 = load i32, i32* %8
store i32 %27, i32* %4
br label %28
28: ; preds = %25, %13
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@AT_REMOVEDIR = global i32 0
define i32 @unlinkat(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @dir_mutex_lock(i32 %0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = load i32, i32* @AT_REMOVEDIR
%8 = icmp eq i32 %7, %2
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @rmdir(i8* %1)
br label %13
11: ; preds = %6
%12 = tail call i32 @unlink(i8* %1)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ %10, %9 ], [ %12, %11 ]
%15 = tail call i32 (...) @dir_mutex_unlock()
br label %16
16: ; preds = %3, %13
%17 = phi i32 [ %14, %13 ], [ %4, %3 ]
ret i32 %17
}