#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 /*<<< orphan*/ buf;

/* Variables and functions */
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int syscall(int, int, long, size_t, int, int /*<<< orphan*/);
int unlink(const char *pathname, int flags) {
  static char buf[128] __attribute__((aligned(64)));
  size_t name_size = strlen(pathname) + 1;
  if (name_size > sizeof(buf)) {
    return -1;
  }
  strncpy(buf, pathname, sizeof(buf));
  return syscall(35, -100, (long)buf, name_size, flags, 0);
}


x86 assembly (clang, -O0):
<unlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
cmpq   $0x80,-0x20(%rbp)
jbe    116b <unlink+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <unlink+0x74>
mov    -0x10(%rbp),%rsi
lea    0x2f0a(%rip),%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    $0x23,%edi
mov    $0xffffff9c,%esi
lea    0x2ee7(%rip),%rdx
xor    %r9d,%r9d
call   1050 <syscall@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unlink>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <strlen@plt>
add    $0x1,%eax
cmp    $0x80,%eax
jbe    115b <unlink+0x2b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r14d
lea    0x2f1b(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    $0x23,%edi
mov    $0xffffff9c,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %ebp,%r8d
xor    %r9d,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <syscall@plt>

LLVM IR (-O0):
@unlink.buf = internal global [128 x i8] zeroinitializer
define i32 @unlink(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = icmp ugt i64 %11, 128
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %20
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 @strncpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @unlink.buf, i64 0, i64 0), i8* %15, i32 128)
%17 = load i64, i64* %6
%18 = load i32, i32* %5
%19 = call i32 @syscall(i32 35, i32 -100, i64 ptrtoint ([128 x i8]* @unlink.buf to i64), i64 %17, i32 %18, i32 0)
store i32 %19, i32* %3
br label %20
20: ; preds = %14, %13
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@unlink.buf = internal global [128 x i8] zeroinitializer
define i32 @unlink(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = icmp ugt i32 %4, 128
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = zext i32 %4 to i64
%8 = tail call i32 @strncpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @unlink.buf, i64 0, i64 0), i8* %0, i32 128)
%9 = tail call i32 @syscall(i32 35, i32 -100, i64 ptrtoint ([128 x i8]* @unlink.buf to i64), i64 %7, i32 %1, i32 0)
br label %10
10: ; preds = %2, %6
%11 = phi i32 [ %9, %6 ], [ -1, %2 ]
ret i32 %11
}