#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 */
struct flock {
  int l_start;
  int l_len;
  scalar_t__ l_pid;
  int /*<<< orphan*/ l_whence;
  int /*<<< orphan*/ l_type;
};

/* Variables and functions */
int /*<<< orphan*/ F_SETLKW;
int /*<<< orphan*/ F_WRLCK;
int /*<<< orphan*/ SEEK_SET;
int fcntl(int, int /*<<< orphan*/, struct flock *);
int lock_range(int fd, int offset, int len) {
  struct flock lock;
  lock.l_type = F_WRLCK;
  lock.l_whence = SEEK_SET;
  lock.l_start = offset;
  lock.l_len = len;
  lock.l_pid = 0;
  return fcntl(fd, F_SETLKW, &lock);
}


x86 assembly (clang, -O0):
<lock_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1030 <fcntl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lock_range>:
sub    $0x18,%rsp
mov    0x2eb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %esi,(%rsp)
mov    %edx,0x4(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <fcntl@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.flock = type { i32, i32, i64, i32, i32 }
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLKW = global i32 0
define i32 @lock_range(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.flock
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* @F_WRLCK
%9 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 4
store i32 %8, i32* %9
%10 = load i32, i32* @SEEK_SET
%11 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 3
store i32 %10, i32* %11
%12 = load i32, i32* %5
%13 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* %6
%15 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 1
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 2
store i64 0, i64* %16
%17 = load i32, i32* %4
%18 = load i32, i32* @F_SETLKW
%19 = call i32 @fcntl(i32 %17, i32 %18, %struct.flock* %7)
ret i32 %19
}

LLVM IR (-O2):
%struct.flock = type { i32, i32, i64, i32, i32 }
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLKW = global i32 0
define i32 @lock_range(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.flock
%5 = bitcast %struct.flock* %4 to i8*
%6 = load i32, i32* @F_WRLCK
%7 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 4
store i32 %6, i32* %7
%8 = load i32, i32* @SEEK_SET
%9 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 3
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 0
store i32 %1, i32* %10
%11 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 1
store i32 %2, i32* %11
%12 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 2
store i64 0, i64* %12
%13 = load i32, i32* @F_SETLKW
%14 = call i32 @fcntl(i32 %0, i32 %13, %struct.flock* %4)
ret i32 %14
}