#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 /*<<< orphan*/ F_LOCK;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ lockf(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int pidfile_acquire(char *pidfile) {
  int pid_fd;
  if (pidfile == NULL)
    return -1;
  pid_fd = open(pidfile, O_CREAT | O_WRONLY, 0644);
  if (pid_fd < 0)
    printf("Unable to open pidfile %s\n", pidfile);
  else
    lockf(pid_fd, F_LOCK, 0);
  return pid_fd;
}


x86 assembly (clang, -O0):
<pidfile_acquire>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <pidfile_acquire+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <pidfile_acquire+0x7e>
mov    -0x10(%rbp),%rdi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
mov    0x2e61(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1195 <pidfile_acquire+0x65>
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
jmp    11a8 <pidfile_acquire+0x78>
mov    -0x14(%rbp),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <lockf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pidfile_acquire>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1171 <pidfile_acquire+0x41>
mov    %rdi,%rbx
mov    0x2eb6(%rip),%rax
mov    0x2e7f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1178 <pidfile_acquire+0x48>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <lockf@plt>
jmp    1187 <pidfile_acquire+0x57>
mov    $0xffffffff,%ebp
jmp    1187 <pidfile_acquire+0x57>
lea    0xe81(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str = [27 x i8] c"Unable to open pidfile %s\0A\00"
@F_LOCK = global i32 0
define i32 @pidfile_acquire(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %25
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_WRONLY
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %9, i32 %12, i32 420)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %23
19: ; preds = %8
%20 = load i32, i32* %4
%21 = load i32, i32* @F_LOCK
%22 = call i32 @lockf(i32 %20, i32 %21, i32 0)
br label %23
23: ; preds = %19, %16
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %7
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str = [27 x i8] c"Unable to open pidfile %s\0A\00"
@F_LOCK = global i32 0
define i32 @pidfile_acquire(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = load i32, i32* @O_CREAT
%5 = load i32, i32* @O_WRONLY
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6, i32 420)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
11: ; preds = %3
%12 = load i32, i32* @F_LOCK
%13 = tail call i32 @lockf(i32 %7, i32 %12, i32 0)
br label %14
14: ; preds = %9, %11, %1
%15 = phi i32 [ -1, %1 ], [ %7, %11 ], [ %7, %9 ]
ret i32 %15
}