#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 {
  short l_type;
  scalar_t__ l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
};
typedef int /*<<< orphan*/ l;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int fcntl(int, short, struct flock *);
int /*<<< orphan*/ memset(struct flock *, int /*<<< orphan*/, int);
int lockit(int fd, short cmd, short type) {
  struct flock l;
  memset(&l, 0, sizeof(l));
  l.l_type = type;
  l.l_whence = SEEK_SET;
  l.l_start = 0;
  l.l_len = 0;
  return fcntl(fd, cmd, &l);
}


x86 assembly (clang, -O0):
<lockit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %si,%cx
mov    %edi,-0x4(%rbp)
mov    %cx,-0x6(%rbp)
mov    %ax,-0x8(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%ax
mov    %ax,-0x28(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rdx
movswl -0x6(%rbp),%esi
call   1030 <fcntl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lockit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    %bx,0x8(%rsp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    %ebp,%edi
mov    %r14d,%esi
mov    %r15,%rdx
call   1030 <fcntl@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.flock = type { i16, i64, i64, i32 }
@SEEK_SET = global i32 0
define i32 @lockit(i32 %0, i16 signext %1, i16 signext %2) {
%4 = alloca %struct.flock
%5 = bitcast %struct.flock* %4 to i8*
%6 = call i32 @memset(%struct.flock* %4, i32 0, i32 32)
%7 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 0
store i16 %2, i16* %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 1
%11 = bitcast i64* %10 to i8*
%12 = call i32 @fcntl(i32 %0, i16 signext %1, %struct.flock* %4)
ret i32 %12
}