#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_type;
  scalar_t__ l_len;
  int /*<<< orphan*/ l_whence;
  scalar_t__ l_start;
};

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int fcntl(int, int, struct flock *);
int fd_get_lock(int fd, int cmd, int type) {
  struct flock lock;
  assert(fd >= 0);
  lock.l_type = type;
  lock.l_start = 0;
  lock.l_whence = SEEK_SET;
  lock.l_len = 0;
  return (fcntl(fd, cmd, &lock));
}


x86 assembly (clang, -O0):
<fd_get_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdx
call   1030 <fcntl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_get_lock>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%ebp
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
mov    %ebx,(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdx
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <fcntl@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.flock = type { i32, i64, i32, i64 }
@SEEK_SET = global i32 0
define i32 @fd_get_lock(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* %4
%9 = icmp sge i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %6
%13 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 0
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 3
store i64 0, i64* %14
%15 = load i32, i32* @SEEK_SET
%16 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 1
store i64 0, i64* %17
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @fcntl(i32 %18, i32 %19, %struct.flock* %7)
ret i32 %20
}

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