#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 int /*<<< orphan*/ off_t;

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


x86 assembly (clang, -O0):
<lockabyte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%ecx
mov    0x2e6f(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%r9d
call   1040 <lock_reg@plt>
cmp    $0x0,%rax
jge    1192 <lockabyte+0x62>
mov    -0x8(%rbp),%rsi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    0xe73(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lockabyte>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    0x2e7c(%rip),%rax
mov    (%rax),%r8d
mov    %ebp,%edi
mov    %ebx,%ecx
mov    $0x1,%r9d
call   1040 <lock_reg@plt>
test   %rax,%rax
jns    1183 <lockabyte+0x53>
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
lea    0xe85(%rip),%rdi
mov    %r14,%rsi
call   1030 <err_sys@plt>
lea    0xe8f(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <printf@plt>

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

LLVM IR (-O2):
@F_SETLKW = global i32 0
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@.str = [25 x i8] c"%s: writew_lock error %d\00"
@errno = global i32 0
@.str.1 = [37 x i8] c"%s: got the lock on fd %d, byte %ld\0A\00"
define void @lockabyte(i8* %0, i32 %1, i32 %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, i32 %2, i32 %6, i32 1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @errno
%11 = tail call i32 @err_sys(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %10)
br label %12
12: ; preds = %9, %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1, i32 %2)
ret void
}