#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 LOCK_NB;
int LOCK_UN;
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ flock(int, int);
scalar_t__ remove(char const *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
void remove_pidfile(const char *pidfile, int pidfile_fd) {
  assert(pidfile && pidfile_fd >= 3);
  if (flock(pidfile_fd, LOCK_UN | LOCK_NB))
    syslog(LOG_WARNING, "Failed to unlock the pidfile");
  close(pidfile_fd);
  if (remove(pidfile))
    syslog(LOG_WARNING, "Failed to remove the pidfile");
}


x86 assembly (clang, -O0):
<remove_pidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0xd(%rbp)
je     1179 <remove_pidfile+0x29>
cmpl   $0x3,-0xc(%rbp)
setge  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e2f(%rip),%rax
or     (%rax),%esi
call   1070 <flock@plt>
cmp    $0x0,%rax
je     11bf <remove_pidfile+0x6f>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1060 <syslog@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
je     11ef <remove_pidfile+0x9f>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1060 <syslog@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_pidfile>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
cmp    $0x3,%esi
setge  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
mov    0x2e63(%rip),%rax
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %ebp,%edi
call   1070 <flock@plt>
test   %rax,%rax
je     11a1 <remove_pidfile+0x51>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1060 <syslog@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
test   %rax,%rax
je     11d0 <remove_pidfile+0x80>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <syslog@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@LOCK_UN = global i32 0
@LOCK_NB = global i32 0
@LOG_WARNING = global i32 0
@.str = [29 x i8] c"Failed to unlock the pidfile\00"
@.str.1 = [29 x i8] c"Failed to remove the pidfile\00"
define void @remove_pidfile(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 3
br label %10
10: ; preds = %7, %2
%11 = phi i1 [ false, %2 ], [ %9, %7 ]
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %4
%15 = load i32, i32* @LOCK_UN
%16 = load i32, i32* @LOCK_NB
%17 = or i32 %15, %16
%18 = call i64 @flock(i32 %14, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %10
%21 = load i32, i32* @LOG_WARNING
%22 = call i32 @syslog(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %20, %10
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %3
%27 = call i64 @remove(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32, i32* @LOG_WARNING
%31 = call i32 @syslog(i32 %30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %29, %23
ret void
}

LLVM IR (-O2):
@LOCK_UN = global i32 0
@LOCK_NB = global i32 0
@LOG_WARNING = global i32 0
@.str = [29 x i8] c"Failed to unlock the pidfile\00"
@.str.1 = [29 x i8] c"Failed to remove the pidfile\00"
define void @remove_pidfile(i8* %0, i32 %1) {
%3 = icmp ne i8* %0, null
%4 = icmp sgt i32 %1, 2
%5 = and i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = load i32, i32* @LOCK_UN
%9 = load i32, i32* @LOCK_NB
%10 = or i32 %9, %8
%11 = tail call i64 @flock(i32 %1, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* @LOG_WARNING
%15 = tail call i32 @syslog(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %2
%17 = tail call i32 @close(i32 %1)
%18 = tail call i64 @remove(i8* %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i32, i32* @LOG_WARNING
%22 = tail call i32 @syslog(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %20, %16
ret void
}