// File: /workspace/github_c_makefile_star2_O3/otrtool[P]otrtool/src/main.c
// Function: keycache_open
void keycache_open() {
  char *home = NULL, *data_home = NULL, *pch;
  char *filenames[2] = { NULL, NULL };
  const int n_filenames = 2;
  int i;

  /* Build home and data home strings */
  if ((pch = getenv("HOME")) != NULL && strlen(pch) > 0)
    home = strdup(pch);
  if ((pch = getenv("XDG_DATA_HOME")) != NULL && strlen(pch) > 0)
    data_home = strdup(pch);
  if (data_home == NULL && home != NULL
      && (data_home = malloc(strlen(home) + 14)) != NULL) {
    strcpy(data_home, home);
    strcat(data_home, "/.local/share");
  }
  if (!home && !data_home)
    fputs("warning: neither HOME nor XDG_DATA_HOME is set\n", stderr);

  /* Make array of file name alternatives */
  if (home && (filenames[0] = malloc(strlen(home) + 15)) != NULL) {
    strcpy(filenames[0], home);
    strcat(filenames[0], "/.otrkey_cache");
  }
  if (data_home && (filenames[1] = malloc(strlen(data_home) + 22)) != NULL) {
    strcpy(filenames[1], data_home);
    strcat(filenames[1], "/otrtool/otrkey_cache");
  }

  /* Choose the first existing cache file alternative */
  keyfilename = NULL;
  for (i=0; i < n_filenames; ++i) {
    if (filenames[i] && access(filenames[i], F_OK) == 0) break;
  }
  if (i == n_filenames) i = 0; /* choose default */
  if (filenames[i]) keyfilename = strdup(filenames[i]);

  if (keyfilename) {
    /* Construct abbreviated key file name (replace HOME with ~) */
    if (home && strncmp(keyfilename, home, strlen(home)) == 0) {
      if ((pch = malloc(strlen(keyfilename)-strlen(home)+2)) == NULL)
        PERROR("malloc");
      strcpy(pch, "~");
      strcat(pch, keyfilename+strlen(home));
      keyfileshortname = pch;
    }
    else {
      if ((keyfileshortname = strdup(keyfilename)) == NULL) PERROR("strdup");
    }
    if(opts.verbosity >= VERB_DEBUG)
      fprintf(stderr, "key cache is at %s\n", keyfileshortname);

    /* Open key cache */
    keyfile = fopen(keyfilename, "a+");
    if (keyfile == NULL && opts.verbosity >= VERB_DEBUG)
      perrorf("cannot open key cache: %s", keyfilename);
  }

  for (i=0; i < n_filenames; ++i) free(filenames[i]);
  free(home);
  free(data_home);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
leaq 0x3ca1(%rip), %rdi      # 0x964c
callq 0x22b0
testq %rax, %rax
je 0x59c7
cmpb $0x0, (%rax)
je 0x59c7
movq %rax, %rdi
callq 0x2450
movq %rax, %rbx
jmp 0x59c9
xorl %ebx, %ebx
leaq 0x3c73(%rip), %rdi      # 0x9643
callq 0x22b0
testq %rax, %rax
je 0x59ec
cmpb $0x0, (%rax)
je 0x59ec
movq %rax, %rdi
callq 0x2450
movq %rax, %r14
jmp 0x59ef
xorl %r14d, %r14d
testq %r14, %r14
sete %al
testq %rbx, %rbx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x5a54
movq %rbx, %rdi
callq 0x20c0
leaq 0xe(%rax), %rdi
callq 0x2310
movq %rax, %r14
testq %rax, %rax
je 0x5a4b
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r14, %rdi
callq 0x20c0
movabsq $0x2f6c61636f6c2e2f, %rcx # imm = 0x2F6C61636F6C2E2F
movq %rcx, (%r14,%rax)
movabsq $0x65726168732f6c, %rcx # imm = 0x65726168732F6C
movq %rcx, 0x6(%r14,%rax)
testq %r14, %r14
setne %bpl
jmp 0x5a6c
testq %r14, %r14
setne %bpl
movq %rbx, %rax
orq %r14, %rax
je 0x5c99
testq %rbx, %rbx
je 0x5ab9
movq %rbx, %rdi
callq 0x20c0
leaq 0xf(%rax), %rdi
callq 0x2310
movq %rax, (%rsp)
testq %rax, %rax
je 0x5ab9
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
callq 0x20c0
movabsq $0x79656b72746f2e2f, %rcx # imm = 0x79656B72746F2E2F
movq %rcx, (%r15,%rax)
movabsq $0x65686361635f79, %rcx # imm = 0x65686361635F79
movq %rcx, 0x7(%r15,%rax)
testb %bpl, %bpl
je 0x5b0a
movq %r14, %rdi
callq 0x20c0
leaq 0x16(%rax), %rdi
callq 0x2310
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x5b0a
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x21e0
movq %r15, %rdi
callq 0x20c0
movabsq $0x65686361635f79, %rcx # imm = 0x65686361635F79
movq %rcx, 0xe(%r15,%rax)
movups 0x3b99(%rip), %xmm0     # 0x969e
movups %xmm0, (%r15,%rax)
leaq 0x8(%rsp), %r12
movq $0x0, 0x77e6(%rip) # 0xd300
movq %rsp, %rdx
movb $0x1, %bpl
xorl %ecx, %ecx
movq (%rdx), %rdi
testq %rdi, %rdi
je 0x5b4e
movq %rcx, %r15
xorl %esi, %esi
callq 0x23f0
testl %eax, %eax
setne %sil
movl $0x1, %ecx
movq %r12, %rdx
testb %bpl, %sil
movl $0x0, %ebp
jne 0x5b22
jmp 0x5b66
movl $0x1, %ecx
xorl %r15d, %r15d
movq %r12, %rdx
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x5b22
jmp 0x5b6e
xorl %ecx, %ecx
testl %eax, %eax
cmovneq %rcx, %r15
movq (%rsp,%r15,8), %rdi
testq %rdi, %rdi
je 0x5b88
callq 0x2450
movq %rax, %r15
movq %rax, 0x777a(%rip)      # 0xd300
jmp 0x5b8f
movq 0x7771(%rip), %r15      # 0xd300
testq %r15, %r15
je 0x5c3d
testq %rbx, %rbx
je 0x5bba
movq %rbx, %rdi
callq 0x20c0
movq %rax, %r13
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x20e0
testl %eax, %eax
je 0x5bd6
movq %r15, %rdi
callq 0x2450
movq %rax, %r12
movq %rax, 0x773c(%rip)      # 0xd308
testq %rax, %rax
jne 0x5c10
callq 0x3079
movq %r15, %rdi
callq 0x20c0
subq %r13, %rax
leaq 0x2(%rax), %rdi
callq 0x2310
testq %rax, %rax
je 0x5ca6
movq %rax, %r12
movw $0x7e, (%rax)
addq %r15, %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x2430
movq %r12, 0x76f8(%rip)      # 0xd308
cmpb $0x1, 0x7681(%rip)      # 0xd298
je 0x5c75
leaq 0x3ab6(%rip), %rsi      # 0x96d6
movq %r15, %rdi
callq 0x2280
movq %rax, 0x76e1(%rip)      # 0xd310
testq %rax, %rax
jne 0x5c3d
testb $0x1, 0x765d(%rip)      # 0xd298
jne 0x5c6e
movq (%rsp), %rdi
callq 0x2290
movq 0x8(%rsp), %rdi
callq 0x2290
movq %rbx, %rdi
callq 0x2290
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2290
callq 0x30cb
jmp 0x5c3d
movq 0x735c(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x3a3c(%rip), %rsi      # 0x96c2
movq %r12, %rdx
xorl %eax, %eax
callq 0x2340
movq 0x7669(%rip), %r15      # 0xd300
jmp 0x5c19
callq 0x3063
xorl %r14d, %r14d
jmp 0x5b0a
callq 0x30e0