#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_GETLK;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errx(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ str_type(int);
scalar_t__ try_lock(int /*<<< orphan*/, int, int /*<<< orphan*/, long, long);
void lock_fail(int type, long int start, long int len) {
  if (try_lock(F_GETLK, type, SEEK_SET, start, len) ||
      try_lock(F_SETLK, type, SEEK_SET, start, len))
    errx(1, "setting %s succeeded unexpectedly", str_type(type));
}


x86 assembly (clang, -O0):
<lock_fail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1030 <try_lock@plt>
cmp    $0x0,%rax
jne    119b <lock_fail+0x6b>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1030 <try_lock@plt>
cmp    $0x0,%rax
je     11b6 <lock_fail+0x86>
mov    -0x4(%rbp),%edi
call   1050 <str_type@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe4f(%rip),%rsi
call   1040 <errx@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lock_fail>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%r12
mov    (%r12),%edx
mov    %ebx,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <try_lock@plt>
test   %rax,%rax
jne    1185 <lock_fail+0x55>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%edx
mov    %ebx,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <try_lock@plt>
test   %rax,%rax
je     11aa <lock_fail+0x7a>
mov    %ebx,%edi
call   1050 <str_type@plt>
lea    0xe6d(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <errx@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@F_GETLK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [34 x i8] c"setting %s succeeded unexpectedly\00"
define void @lock_fail(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%7 = load i32, i32* @F_GETLK
%8 = load i32, i32* %4
%9 = load i32, i32* @SEEK_SET
%10 = load i64, i64* %5
%11 = load i64, i64* %6
%12 = call i64 @try_lock(i32 %7, i32 %8, i32 %9, i64 %10, i64 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %3
%15 = load i32, i32* @F_SETLK
%16 = load i32, i32* %4
%17 = load i32, i32* @SEEK_SET
%18 = load i64, i64* %5
%19 = load i64, i64* %6
%20 = call i64 @try_lock(i32 %15, i32 %16, i32 %17, i64 %18, i64 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %14, %3
%23 = load i32, i32* %4
%24 = call i32 @str_type(i32 %23)
%25 = call i32 @errx(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %14
ret void
}

LLVM IR (-O2):
@F_GETLK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [34 x i8] c"setting %s succeeded unexpectedly\00"
define void @lock_fail(i32 %0, i64 %1, i64 %2) {
%4 = load i32, i32* @F_GETLK
%5 = load i32, i32* @SEEK_SET
%6 = tail call i64 @try_lock(i32 %4, i32 %0, i32 %5, i64 %1, i64 %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = load i32, i32* @F_SETLK
%10 = load i32, i32* @SEEK_SET
%11 = tail call i64 @try_lock(i32 %9, i32 %0, i32 %10, i64 %1, i64 %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8, %3
%14 = tail call i32 @str_type(i32 %0)
%15 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %8
ret void
}