#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*/ err_sys(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);
void lockabyte(const char *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", name);
  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    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rcx
mov    0x2e75(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%r9d
call   1040 <lock_reg@plt>
cmp    $0x0,%rax
jge    118b <lockabyte+0x5b>
mov    -0x8(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe7c(%rip),%rdi
call   1050 <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    0x2ea5(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e84(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e83(%rip),%rcx
mov    (%rcx),%r8d
mov    %eax,%edi
mov    %rbx,%rcx
mov    $0x1,%r9d
call   1040 <lock_reg@plt>
test   %rax,%rax
jns    117c <lockabyte+0x4c>
lea    0xe8c(%rip),%rdi
mov    %r14,%rsi
call   1030 <err_sys@plt>
lea    0xe93(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

LLVM IR (-O0):
@F_SETLKW = global i32 0
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@.str = [22 x i8] c"%s: writew_lock error\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 %17
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = call i32 @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %3
%18 = load i8*, i8** %4
%19 = load i64, i64* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %18, i64 %19)
ret void
}

LLVM IR (-O2):
@F_SETLKW = global i32 0
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@.str = [22 x i8] c"%s: writew_lock error\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 %11
9: ; preds = %3
%10 = tail call i32 @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %9, %3
%12 = 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
}