#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;
  short l_whence;
  void *l_len;
  void *l_start;
};
typedef void *off_t;

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


x86 assembly (clang, -O0):
<lock_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %cx,-0xa(%rbp)
mov    %ax,-0xc(%rbp)
mov    %r8,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    -0xa(%rbp),%ax
mov    %ax,-0x38(%rbp)
mov    -0xc(%rbp),%ax
mov    %ax,-0x36(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x38(%rbp),%rdx
call   1030 <fcntl@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lock_reg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %esi,%r12d
mov    %edi,%r13d
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    %bx,(%rsp)
mov    %bp,0x2(%rsp)
mov    %r15,0x10(%rsp)
mov    %r14,0x8(%rsp)
mov    %r13d,%edi
mov    %r12d,%esi
mov    %rsp,%rdx
call   1030 <fcntl@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.flock = type { i16, i16, i8*, i8* }
define i32 @lock_reg(i32 %0, i32 %1, i16 signext %2, i16 signext %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i16
%10 = alloca i16
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca %struct.flock
store i32 %0, i32* %7
store i32 %1, i32* %8
store i16 %2, i16* %9
store i16 %3, i16* %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%14 = call i32 @memset(%struct.flock* %13, i32 0, i32 24)
%15 = load i16, i16* %9
%16 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 0
store i16 %15, i16* %16
%17 = load i16, i16* %10
%18 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 1
store i16 %17, i16* %18
%19 = load i8*, i8** %11
%20 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 3
store i8* %19, i8** %20
%21 = load i8*, i8** %12
%22 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 2
store i8* %21, i8** %22
%23 = load i32, i32* %7
%24 = load i32, i32* %8
%25 = call i32 @fcntl(i32 %23, i32 %24, %struct.flock* %13)
ret i32 %25
}

LLVM IR (-O2):
%struct.flock = type { i16, i16, i8*, i8* }
define i32 @lock_reg(i32 %0, i32 %1, i16 signext %2, i16 signext %3, i8* %4, i8* %5) {
%7 = alloca %struct.flock
%8 = bitcast %struct.flock* %7 to i8*
%9 = call i32 @memset(%struct.flock* %7, i32 0, i32 24)
%10 = getelementptr inbounds %struct.flock, %struct.flock* %7, i64 0, i32 0
store i16 %2, i16* %10
%11 = getelementptr inbounds %struct.flock, %struct.flock* %7, i64 0, i32 1
store i16 %3, i16* %11
%12 = getelementptr inbounds %struct.flock, %struct.flock* %7, i64 0, i32 3
store i8* %4, i8** %12
%13 = getelementptr inbounds %struct.flock, %struct.flock* %7, i64 0, i32 2
store i8* %5, i8** %13
%14 = call i32 @fcntl(i32 %0, i32 %1, %struct.flock* %7)
ret i32 %14
}