#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 EACCES;
int EPERM;
int __syscall(int, char const *);
int errno;
int mq_unlink(const char *name) {
  int ret;
  if (*name == '/')
    name++;
  ret = __syscall(275, name);
  if (ret < 0) {
    if (ret == -EPERM)
      ret = -EACCES;
    errno = -ret;
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<mq_unlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1138 <mq_unlink+0x28>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x113,%edi
call   1030 <__syscall@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1191 <mq_unlink+0x81>
mov    -0x14(%rbp),%eax
xor    %ecx,%ecx
mov    0x2e69(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
jne    1177 <mq_unlink+0x67>
xor    %eax,%eax
mov    0x2e76(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
xor    %ecx,%ecx
sub    -0x14(%rbp),%ecx
mov    0x2e55(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <mq_unlink+0x87>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mq_unlink>:
push   %rax
xor    %esi,%esi
cmpb   $0x2f,(%rdi)
sete   %sil
add    %rdi,%rsi
mov    $0x113,%edi
call   1030 <__syscall@plt>
test   %eax,%eax
js     112d <mq_unlink+0x1d>
pop    %rcx
ret
mov    0x2e94(%rip),%rcx
mov    0x2ead(%rip),%rdx
xor    %esi,%esi
sub    (%rdx),%esi
mov    (%rcx),%ecx
add    %eax,%ecx
cmove  %esi,%eax
neg    %eax
mov    0x2e89(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@EPERM = global i32 0
@EACCES = global i32 0
@errno = global i32 0
define i32 @mq_unlink(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 47
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %3
br label %12
12: ; preds = %9, %1
%13 = load i8*, i8** %3
%14 = call i32 @__syscall(i32 275, i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = load i32, i32* %4
%19 = load i32, i32* @EPERM
%20 = sub nsw i32 0, %19
%21 = icmp eq i32 %18, %20
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* @EACCES
%24 = sub nsw i32 0, %23
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %17
%26 = load i32, i32* %4
%27 = sub nsw i32 0, %26
store i32 %27, i32* @errno
store i32 -1, i32* %2
br label %30
28: ; preds = %12
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %25
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@EPERM = global i32 0
@EACCES = global i32 0
@errno = global i32 0
define i32 @mq_unlink(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 47
%4 = zext i1 %3 to i64
%5 = getelementptr i8, i8* %0, i64 %4
%6 = tail call i32 @__syscall(i32 275, i8* %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %1
%9 = load i32, i32* @EPERM
%10 = sub nsw i32 0, %9
%11 = icmp eq i32 %6, %10
%12 = load i32, i32* @EACCES
%13 = sub nsw i32 0, %12
%14 = select i1 %11, i32 %13, i32 %6
%15 = sub nsw i32 0, %14
store i32 %15, i32* @errno
br label %16
16: ; preds = %1, %8
%17 = phi i32 [ -1, %8 ], [ %6, %1 ]
ret i32 %17
}