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

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


x86 assembly (clang, -O0):
<seashell_try_and_lock_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1030 <fcntl@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seashell_try_and_lock_file>:
sub    $0x28,%rsp
movq   $0x0,0x18(%rsp)
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <fcntl@plt>
add    $0x28,%rsp
ret

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

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