// File: /workspace/github_c_makefile_star2_O3/otrtool[P]otrtool/src/main.c
// Function: fetchKeyphrase
void fetchKeyphrase() {
  struct termios ios0, ios1;
  time_t time_ = time(NULL);
  char *date = malloc(9);
  strftime(date, 9, "%Y%m%d", gmtime(&time_));
  
  if (info) {
    free(info);
    info = NULL;
  }
  
  if (opts.email == NULL) {
    if (!interactive) ERROR("Email address not specified");
    opts.email = malloc(51);
    fputs("Enter your eMail-address: ", stderr);
    if (fscanf(ttyfile, "%50s", opts.email) < 1)
      ERROR("Email invalid");
    while (fgetc(ttyfile) != '\n');
  }
  email = strdup(opts.email);

  if (opts.password == NULL) {
    if (!interactive) ERROR("Password not specified");
    opts.password = malloc(51);
    fputs("Enter your password: ", stderr);
    tcgetattr(fileno(ttyfile), &ios0);
    ios1 = ios0;
    ios1.c_lflag &= ~ECHO;
    tcsetattr(fileno(ttyfile), TCSAFLUSH, &ios1);
    if (fscanf(ttyfile, "%50s", opts.password) < 1) {
      tcsetattr(0, TCSAFLUSH, &ios0);
      ERROR("Password invalid");
    }
    tcsetattr(fileno(ttyfile), TCSAFLUSH, &ios0);
    while (fgetc(ttyfile) != '\n');
    fputc('\n', stderr);
  }
  password = strdup(opts.password);
  
  char *bigkey = generateBigkey(date);
  char *request = generateRequest(bigkey, date);
  free(email);
  free(password);
  
  fputs("Trying to contact server...\n", stderr);
  struct MemoryStruct *response = contactServer(request);

  if (response->size == 0 || response->memory == NULL) {
    ERROR("Server sent an empty response, exiting");
  }
  fputs("Server responded.\n", stderr);
  
  // skip initial whitespace
  char *message = response->memory;
  message += strspn(message, " \t\n");
  
  if (isBase64(message) == 0) {
    if (memcmp(message,"MessageToBePrintedInDecoder",27) ==0) {
      fputs("Server sent us this sweet message:\n", stderr);
      quote(message + 27);
    } else {
      fputs("Server sent us this ugly crap:\n", stderr);
      dumpHex(response->memory, response->size);
    }
    ERROR("Server response is unuseable, exiting");
  }
  
  int info_len;
  char *info_crypted = base64Decode(message, &info_len);
  
  if (info_len % 8 != 0) {
    fputs("Length of response must be a multiple of 8.", stderr);
    dumpHex(info_crypted, info_len);
    ERROR("Server response is unuseable, exiting");
  }
  
  info = decryptResponse(info_crypted, info_len, bigkey);
  
  keyphrase = queryGetParam(info, "HP");
  if (keyphrase == NULL)
    ERROR("Response lacks keyphrase");
  
  if (strlen(keyphrase) != 56)
    ERROR("Keyphrase has wrong length");
  
  fprintf(stderr, "Keyphrase: %s\n", keyphrase);
  keycache_put(queryGetParam(header, "FH"), keyphrase);
  
  free(date);
  free(bigkey);
  free(request);
  free(response->memory);
  free(response);
  free(info_crypted);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
xorl %edi, %edi
callq 0x21d0
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movl $0x9, %edi
callq 0x2310
movq %rax, %rbx
movq %r14, %rdi
callq 0x21a0
leaq 0x3932(%rip), %rdx      # 0x978c
movl $0x9, %esi
movq %rbx, %rdi
movq %rax, %rcx
callq 0x2160
movq 0x76af(%rip), %rdi      # 0xd520
testq %rdi, %rdi
je 0x5e86
callq 0x2290
movq $0x0, 0x769a(%rip) # 0xd520
movq 0x7423(%rip), %rdi      # 0xd2b0
testq %rdi, %rdi
jne 0x5eaf
cmpb $0x1, 0x768f(%rip)      # 0xd528
je 0x60b9
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x3203
movq (%r14), %rdi
callq 0x2450
movq %rax, 0x742d(%rip)      # 0xd2e8
movq 0x73f6(%rip), %rdi      # 0xd2b8
testq %rdi, %rdi
jne 0x5eec
cmpb $0x1, 0x765a(%rip)      # 0xd528
je 0x60be
leaq 0x10(%rsp), %rdi
leaq 0x4c(%rsp), %rsi
movq %rsp, %r14
movq %r14, %rdx
callq 0x32a6
movq (%r14), %rdi
callq 0x2450
movq %rax, 0x73f8(%rip)      # 0xd2f0
movq %rbx, %rdi
callq 0x5417
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5570
movq %rax, %r15
movq 0x73d0(%rip), %rdi      # 0xd2e8
callq 0x2290
movq 0x73cc(%rip), %rdi      # 0xd2f0
callq 0x2290
movq 0x70a8(%rip), %r13      # 0xcfd8
movq (%r13), %rsi
leaq 0x38e0(%rip), %rdi      # 0x981b
callq 0x2250
movq %r15, %rdi
callq 0x5740
cmpq $0x0, 0x8(%rax)
je 0x6090
movq %rax, %r12
cmpq $0x0, (%rax)
je 0x6090
movq (%r13), %rsi
leaq 0x38f4(%rip), %rdi      # 0x985f
callq 0x2250
movq (%r12), %rbp
leaq 0x38f7(%rip), %rsi      # 0x9872
movq %rbp, %rdi
callq 0x20b0
movq %rax, %r13
addq %rbp, %r13
movq %r13, %rdi
callq 0x20c0
movq %rax, %rbp
leaq 0x3372(%rip), %rsi      # 0x930d
movq %r13, %rdi
callq 0x20b0
cmpq %rax, %rbp
jne 0x6095
movq %rsp, %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4e63
movq %rax, %r13
movl (%rbp), %esi
testb $0x7, %sil
jne 0x60a7
movq %r13, %rdi
movq %r14, %rdx
callq 0x58e6
movq %rax, 0x7544(%rip)      # 0xd520
leaq 0x3945(%rip), %rsi      # 0x9928
movq %rax, %rdi
callq 0x4f51
movq %rax, 0x7546(%rip)      # 0xd538
testq %rax, %rax
je 0x60af
movq %rax, %rbp
movq %rax, %rdi
callq 0x20c0
movq 0x6fcb(%rip), %rcx      # 0xcfd8
movq (%rcx), %rdi
cmpq $0x38, %rax
jne 0x60b4
leaq 0x393e(%rip), %rsi      # 0x995f
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2340
movq 0x72c6(%rip), %rdi      # 0xd2f8
leaq 0x3935(%rip), %rsi      # 0x996e
callq 0x4f51
movq 0x74f3(%rip), %rsi      # 0xd538
movq %rax, %rdi
callq 0x5d7d
movq %rbx, %rdi
callq 0x2290
movq %r14, %rdi
callq 0x2290
movq %r15, %rdi
callq 0x2290
movq (%r12), %rdi
callq 0x2290
movq %r12, %rdi
callq 0x2290
movq %r13, %rdi
callq 0x2290
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3559
movq %r12, %rdx
addq $0x8, %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x33e7
movq %r13, %rdi
callq 0x347d
callq 0x351a
callq 0x34db
callq 0x35d7
callq 0x3598