#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*/ EXIT_FAILURE;
int /*<<< orphan*/ LOCK_EX;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ err(int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ flock(int, int /*<<< orphan*/);
int open(char const *, int, int);
void attemptLock(const char *lockFileName) {
  int fd = open(lockFileName, O_CREAT | O_WRONLY, 0666);
  if (!fd || flock(fd, LOCK_EX))
    err(EXIT_FAILURE, NULL);
}


x86 assembly (clang, -O0):
<attemptLock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    0x2e70(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1184 <attemptLock+0x54>
mov    -0xc(%rbp),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
call   1050 <flock@plt>
cmp    $0x0,%rax
je     1196 <attemptLock+0x66>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <err@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<attemptLock>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
call   1040 <open@plt>
test   %eax,%eax
je     1166 <attemptLock+0x36>
mov    0x2e88(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1050 <flock@plt>
test   %rax,%rax
je     1177 <attemptLock+0x47>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
pop    %rax
jmp    1030 <err@plt>
pop    %rax
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@LOCK_EX = global i32 0
@EXIT_FAILURE = global i32 0
define void @attemptLock(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_WRONLY
%7 = or i32 %5, %6
%8 = call i32 @open(i8* %4, i32 %7, i32 438)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* %3
%13 = load i32, i32* @LOCK_EX
%14 = call i64 @flock(i32 %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11, %1
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @err(i32 %17, i32* null)
br label %19
19: ; preds = %16, %11
ret void
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@LOCK_EX = global i32 0
@EXIT_FAILURE = global i32 0
define void @attemptLock(i8* nocapture %0) {
%2 = load i32, i32* @O_CREAT
%3 = load i32, i32* @O_WRONLY
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* %0, i32 %4, i32 438)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i32, i32* @LOCK_EX
%9 = tail call i64 @flock(i32 %5, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7, %1
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @err(i32 %12, i32* null)
br label %14
14: ; preds = %11, %7
ret void
}