// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq $0x0, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2110
movl $0x2, -0x34(%rbp)
leaq 0x44b6(%rip), %rdi      # 0xa5ec
callq 0x22a0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x6161
movq -0x18(%rbp), %rdi
callq 0x20c0
cmpq $0x0, %rax
jbe 0x6161
movq -0x18(%rbp), %rdi
callq 0x2440
movq %rax, -0x8(%rbp)
leaq 0x447b(%rip), %rdi      # 0xa5e3
callq 0x22a0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x6193
movq -0x18(%rbp), %rdi
callq 0x20c0
cmpq $0x0, %rax
jbe 0x6193
movq -0x18(%rbp), %rdi
callq 0x2440
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x61dd
cmpq $0x0, -0x8(%rbp)
je 0x61dd
movq -0x8(%rbp), %rdi
callq 0x20c0
movq %rax, %rdi
addq $0xe, %rdi
callq 0x2300
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x61dd
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x21e0
movq -0x10(%rbp), %rdi
leaq 0x4419(%rip), %rsi      # 0xa5f1
callq 0x2420
cmpq $0x0, -0x8(%rbp)
jne 0x6201
cmpq $0x0, -0x10(%rbp)
jne 0x6201
movq 0x6de6(%rip), %rax      # 0xcfd8
movq (%rax), %rsi
leaq 0x4403(%rip), %rdi      # 0xa5ff
callq 0x2240
cmpq $0x0, -0x8(%rbp)
je 0x6244
movq -0x8(%rbp), %rdi
callq 0x20c0
movq %rax, %rdi
addq $0xf, %rdi
callq 0x2300
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x6244
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x21e0
movq -0x30(%rbp), %rdi
leaq 0x43f0(%rip), %rsi      # 0xa62f
callq 0x2420
cmpq $0x0, -0x10(%rbp)
je 0x6287
movq -0x10(%rbp), %rdi
callq 0x20c0
movq %rax, %rdi
addq $0x16, %rdi
callq 0x2300
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x6287
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21e0
movq -0x28(%rbp), %rdi
leaq 0x43bc(%rip), %rsi      # 0xa63e
callq 0x2420
movq $0x0, 0x706e(%rip) # 0xd300
movl $0x0, -0x38(%rbp)
cmpl $0x2, -0x38(%rbp)
jge 0x62cf
movslq -0x38(%rbp), %rax
cmpq $0x0, -0x30(%rbp,%rax,8)
je 0x62c2
movslq -0x38(%rbp), %rax
movq -0x30(%rbp,%rax,8), %rdi
xorl %esi, %esi
callq 0x23e0
cmpl $0x0, %eax
jne 0x62c2
jmp 0x62cf
jmp 0x62c4
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6299
cmpl $0x2, -0x38(%rbp)
jne 0x62dc
movl $0x0, -0x38(%rbp)
movslq -0x38(%rbp), %rax
cmpq $0x0, -0x30(%rbp,%rax,8)
je 0x62fd
movslq -0x38(%rbp), %rax
movq -0x30(%rbp,%rax,8), %rdi
callq 0x2440
movq %rax, 0x7003(%rip)      # 0xd300
cmpq $0x0, 0x6ffb(%rip)      # 0xd300
je 0x6508
cmpq $0x0, -0x8(%rbp)
je 0x6424
movq 0x6fe3(%rip), %rax      # 0xd300
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20c0
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq %rax, %rdx
callq 0x20f0
cmpl $0x0, %eax
jne 0x6424
movq 0x6fae(%rip), %rdi      # 0xd300
callq 0x20c0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20c0
movq -0x50(%rbp), %rdi
subq %rax, %rdi
addq $0x2, %rdi
callq 0x2300
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x63db
jmp 0x6380
movq 0x6c51(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x4485(%rip), %rsi      # 0xa816
movb $0x0, %al
callq 0x2330
movq 0x6c39(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x42ab(%rip), %rsi      # 0xa654
movb $0x0, %al
callq 0x2330
movq 0x6c21(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x43e8(%rip), %rsi      # 0xa7a9
movb $0x0, %al
callq 0x2330
xorl %eax, %eax
movl %eax, %edi
callq 0x2180
movl $0x1, %edi
callq 0x2290
movq -0x18(%rbp), %rdi
leaq 0x4275(%rip), %rsi      # 0xa65b
callq 0x21e0
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movq 0x6f06(%rip), %rax      # 0xd300
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20c0
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdi
addq %rax, %rsi
callq 0x2420
movq -0x18(%rbp), %rax
movq %rax, 0x6ee6(%rip)      # 0xd308
jmp 0x649c
movq 0x6ed5(%rip), %rdi      # 0xd300
callq 0x2440
movq %rax, 0x6ed1(%rip)      # 0xd308
cmpq $0x0, %rax
jne 0x649a
jmp 0x643f
movq 0x6b92(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x43c6(%rip), %rsi      # 0xa816
movb $0x0, %al
callq 0x2330
movq 0x6b7a(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x41f5(%rip), %rsi      # 0xa65d
movb $0x0, %al
callq 0x2330
movq 0x6b62(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
leaq 0x4329(%rip), %rsi      # 0xa7a9
movb $0x0, %al
callq 0x2330
xorl %eax, %eax
movl %eax, %edi
callq 0x2180
movl $0x1, %edi
callq 0x2290
jmp 0x649c
cmpl $0x1, 0x6e01(%rip)      # 0xd2a4
jb 0x64c4
movq 0x6b2c(%rip), %rax      # 0xcfd8
movq (%rax), %rdi
movq 0x6e52(%rip), %rdx      # 0xd308
leaq 0x41a7(%rip), %rsi      # 0xa664
movb $0x0, %al
callq 0x2330
movq 0x6e35(%rip), %rdi      # 0xd300
leaq 0x41a6(%rip), %rsi      # 0xa678
callq 0x2270
movq %rax, 0x6e32(%rip)      # 0xd310
cmpq $0x0, 0x6e2a(%rip)      # 0xd310
jne 0x6506
cmpl $0x1, 0x6db5(%rip)      # 0xd2a4
jb 0x6506
movq 0x6e08(%rip), %rsi      # 0xd300
leaq 0x417c(%rip), %rdi      # 0xa67b
movb $0x0, %al
callq 0x42b0
jmp 0x6508
movl $0x0, -0x38(%rbp)
cmpl $0x2, -0x38(%rbp)
jge 0x652e
movslq -0x38(%rbp), %rax
movq -0x30(%rbp,%rax,8), %rdi
callq 0x2280
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x650f
movq -0x8(%rbp), %rdi
callq 0x2280
movq -0x10(%rbp), %rdi
callq 0x2280
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)