// File: /workspace/github_c_makefile_star2_O0/AlxHnr[P]nano-backup/src/repository.c
// Function: repoLock
void repoLock(CR_Region *r, StringView repo_path,
              const RepoLockHint lock_hint)
{
  const int old_errno = errno;
  Allocator *a = allocatorWrapRegion(r);

  LockfileInfo *lockfile_info = CR_RegionAlloc(r, sizeof *lockfile_info);
  lockfile_info->is_locked = false;
  lockfile_info->file_path =
    strGetContent(strAppendPath(repo_path, str("lockfile"), a), a);
  lockfile_info->file_descriptor =
    open(lockfile_info->file_path, O_CREAT | O_WRONLY, S_IWUSR | S_IWGRP);

  if(lockfile_info->file_descriptor == -1)
  {
    if(errno == EROFS && lock_hint == RLH_readonly)
    {
      errno = old_errno;
      return;
    }
    dieErrno("failed to create lockfile: \"%s\"",
             lockfile_info->file_path);
  }
  CR_RegionAttach(r, cleanupLockfile, lockfile_info);

  if(lockf(lockfile_info->file_descriptor, F_TLOCK, 0) == 0)
  {
    lockfile_info->is_locked = true;
  }
  else if(errno == EACCES || errno == EAGAIN)
  {
    die("repository is already being used by another process");
  }
  else
  {
    dieErrno("failed to lock repository: \"%s\"",
             lockfile_info->file_path);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
callq 0x2050
movl (%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x25a0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl $0x10, %esi
callq 0x230e0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
leaq -0x50(%rbp), %rdi
leaq 0x19c52(%rip), %rsi     # 0x241c7
callq 0xf100
movq -0x58(%rbp), %rcx
movq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
callq 0xf750
movq -0x18(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xf170
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x41, %esi
movl $0x90, %edx
movb $0x0, %al
callq 0x2320
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x4(%rax)
jne 0xa65a
callq 0x2050
cmpl $0x1e, (%rax)
jne 0xa644
cmpl $0x1, -0xc(%rbp)
jne 0xa644
movl -0x10(%rbp), %eax
movl %eax, -0x5c(%rbp)
callq 0x2050
movl -0x5c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0xa6c9
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x1a2b9(%rip), %rdi     # 0x2490c
movb $0x0, %al
callq 0x4760
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x77(%rip), %rsi        # 0xa6e0
callq 0x232e0
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2160
cmpl $0x0, %eax
jne 0xa691
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
jmp 0xa6c9
callq 0x2050
cmpl $0xd, (%rax)
je 0xa6a5
callq 0x2050
cmpl $0xb, (%rax)
jne 0xa6b3
leaq 0x1a280(%rip), %rdi     # 0x2492c
movb $0x0, %al
callq 0x4680
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x1a29e(%rip), %rdi     # 0x24960
movb $0x0, %al
callq 0x4760
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)