#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 */
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ F_SETLKW;
int /*<<< orphan*/ F_WRLCK;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ lock_reg(int, int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__,
                    int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char const *, long long);
int /*<<< orphan*/ stderr;
void lockabyte(const char *name, int fd, off_t offset) {
  if (lock_reg((fd), F_SETLKW, F_WRLCK, (offset), (SEEK_SET), (1)) < 0) {
    fprintf(stderr, "%s: writew_lock error\n", name);
    exit(1);
  }
  printf("%s: got the lock, byte %lld\n", name, (long long)offset);
}


x86 assembly (clang, -O0):
<lockabyte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rcx
mov    0x2e5d(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%r9d
call   1030 <lock_reg@plt>
cmp    $0x0,%rax
jge    11ae <lockabyte+0x6e>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lockabyte>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%eax
mov    %rdi,%r14
mov    0x2e95(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%r8d
mov    %eax,%edi
mov    %rbx,%rcx
mov    $0x1,%r9d
call   1030 <lock_reg@plt>
test   %rax,%rax
js     1196 <lockabyte+0x56>
lea    0xe93(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@F_SETLKW = global i32 0
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"%s: writew_lock error\0A\00"
@.str.1 = [29 x i8] c"%s: got the lock, byte %lld\0A\00"
define void @lockabyte(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
%7 = load i32, i32* %5
%8 = load i32, i32* @F_SETLKW
%9 = load i32, i32* @F_WRLCK
%10 = load i64, i64* %6
%11 = load i32, i32* @SEEK_SET
%12 = call i64 @lock_reg(i32 %7, i32 %8, i32 %9, i64 %10, i32 %11, i32 1)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
%20 = load i8*, i8** %4
%21 = load i64, i64* %6
%22 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %20, i64 %21)
ret void
}

LLVM IR (-O2):
@F_SETLKW = global i32 0
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"%s: writew_lock error\0A\00"
@.str.1 = [29 x i8] c"%s: got the lock, byte %lld\0A\00"
define void @lockabyte(i8* %0, i32 %1, i64 %2) {
%4 = load i32, i32* @F_SETLKW
%5 = load i32, i32* @F_WRLCK
%6 = load i32, i32* @SEEK_SET
%7 = tail call i64 @lock_reg(i32 %1, i32 %4, i32 %5, i64 %2, i32 %6, i32 1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %3
%14 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0, i64 %2)
ret void
}