#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*/ LOCK_EX;
int O_CREAT;
int O_WRONLY;
scalar_t__ flock(int, int /*<<< orphan*/);
int open(char const *, int, int);
int /*<<< orphan*/ warn(char *, char const *);
void attemptLock(const char *lockFileName) {
  int fd = open(lockFileName, O_CREAT | O_WRONLY, 0666);
  if (!fd || flock(fd, LOCK_EX))
    warn("Cannot lock %s", lockFileName);
}


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    0x2e78(%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     1194 <attemptLock+0x64>
mov    -0x8(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1030 <warn@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<attemptLock>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ebd(%rip),%rax
mov    0x2e86(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
call   1040 <open@plt>
test   %eax,%eax
je     1169 <attemptLock+0x39>
mov    0x2e85(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1050 <flock@plt>
test   %rax,%rax
je     1179 <attemptLock+0x49>
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <warn@plt>
pop    %rbx
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@LOCK_EX = global i32 0
@.str = [15 x i8] c"Cannot lock %s\00"
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 i8*, i8** %2
%18 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %17)
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
@.str = [15 x i8] c"Cannot lock %s\00"
define void @attemptLock(i8* %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 %13, label %11
11: ; preds = %7, %1
%12 = tail call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %11, %7
ret void
}