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

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ unlink(char *);
int unlockfile(char *filename) {
  char lockfilename[PATH_MAX + 5];
  if (!filename)
    return 0;
  if (strlen(filename) + 5 >= sizeof(lockfilename))
    return 0;
  strcpy(lockfilename, filename);
  strcat(lockfilename, ".LOCK");
  if (unlink(lockfilename))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<unlockfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
add    $0x5,%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119d <unlockfile+0x5d>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    121c <unlockfile+0xdc>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rcx
add    $0x5,%eax
cltq
cmp    %rcx,%rax
jb     11cb <unlockfile+0x8b>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    121c <unlockfile+0xdc>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     120e <unlockfile+0xce>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    121c <unlockfile+0xdc>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unlockfile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e9e(%rip),%rax
mov    (%rax),%ebx
add    $0x5,%ebx
mov    %rsp,%r12
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
xor    %r15d,%r15d
test   %rdi,%rdi
je     11ae <unlockfile+0x6e>
mov    %rdi,%r14
call   1050 <strlen@plt>
add    $0x5,%eax
cltq
cmp    %rbx,%rax
jae    11ae <unlockfile+0x6e>
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe6c(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcat@plt>
mov    %r12,%rdi
call   1030 <unlink@plt>
xor    %r15d,%r15d
test   %rax,%rax
sete   %r15b
mov    %r15d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [6 x i8] c".LOCK\00"
define i32 @unlockfile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i32, i32* @PATH_MAX
%8 = add nsw i32 %7, 5
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %1
store i32 0, i32* %2
store i32 1, i32* %6
br label %30
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, 5
%19 = sext i32 %18 to i64
%20 = icmp uge i64 %19, %9
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 0, i32* %2
store i32 1, i32* %6
br label %30
22: ; preds = %15
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %11, i8* %23)
%25 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%26 = call i64 @unlink(i8* %11)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 0, i32* %2
store i32 1, i32* %6
br label %30
29: ; preds = %22
store i32 1, i32* %2
store i32 1, i32* %6
br label %30
30: ; preds = %29, %28, %21, %14
%31 = load i8*, i8** %4
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [6 x i8] c".LOCK\00"
define i32 @unlockfile(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = add nsw i32 %2, 5
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i8* %0, null
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = tail call i32 @strlen(i8* %0)
%9 = add nsw i32 %8, 5
%10 = sext i32 %9 to i64
%11 = icmp ult i64 %10, %4
br i1 %11, label %12, label %18
12: ; preds = %7
%13 = call i32 @strcpy(i8* %5, i8* %0)
%14 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = call i64 @unlink(i8* %5)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %12, %7, %1
%19 = phi i32 [ 0, %1 ], [ 0, %7 ], [ %17, %12 ]
ret i32 %19
}