#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_EX;
int LOCK_NB;
int O_CREAT;
int O_RDWR;
scalar_t__ flock(int, int);
int open(char *, int, int);
int isDoubleStart() {
  int pidFile = open("/tmp/nx-on-wake.pid", O_CREAT | O_RDWR, 0666);
  if (pidFile && flock(pidFile, LOCK_EX | LOCK_NB))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<isDoubleStart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%esi
mov    0x2ea8(%rip),%rax
or     (%rax),%esi
lea    0xebf(%rip),%rdi
mov    $0x1b6,%edx
call   1030 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1188 <isDoubleStart+0x68>
mov    -0x8(%rbp),%edi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2e55(%rip),%rax
or     (%rax),%esi
call   1040 <flock@plt>
cmp    $0x0,%rax
je     1188 <isDoubleStart+0x68>
movl   $0x1,-0x4(%rbp)
jmp    118f <isDoubleStart+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isDoubleStart>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    0x2eb1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xec6(%rip),%rdi
mov    $0x1b6,%edx
call   1030 <open@plt>
test   %eax,%eax
je     1170 <isDoubleStart+0x50>
mov    0x2e89(%rip),%rcx
mov    0x2e6a(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %eax,%edi
call   1040 <flock@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     1170 <isDoubleStart+0x50>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/tmp/nx-on-wake.pid\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
define i32 @isDoubleStart() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_RDWR
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5, i32 438)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = load i32, i32* %2
%11 = load i32, i32* @LOCK_EX
%12 = load i32, i32* @LOCK_NB
%13 = or i32 %11, %12
%14 = call i64 @flock(i32 %10, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %9
store i32 1, i32* %1
br label %18
17: ; preds = %9, %0
store i32 0, i32* %1
br label %18
18: ; preds = %17, %16
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [20 x i8] c"/tmp/nx-on-wake.pid\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
define i32 @isDoubleStart() {
%1 = load i32, i32* @O_CREAT
%2 = load i32, i32* @O_RDWR
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %3, i32 438)
%5 = icmp eq i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = load i32, i32* @LOCK_EX
%8 = load i32, i32* @LOCK_NB
%9 = or i32 %8, %7
%10 = tail call i64 @flock(i32 %4, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %6, %0
br label %13
13: ; preds = %6, %12
%14 = phi i32 [ 0, %12 ], [ 1, %6 ]
ret i32 %14
}