// File: /workspace/github_c_makefile_star2_O1/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 0x21c0
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
movl $0x9, %edi
callq 0x2300
movq %rax, %rbx
movq %r14, %rdi
callq 0x2190
leaq 0x2ab3(%rip), %rdx      # 0x86bc
movl $0x9, %esi
movq %rbx, %rdi
movq %rax, %rcx
callq 0x2150
movq 0x68f0(%rip), %rdi      # 0xc510
testq %rdi, %rdi
je 0x5c35
callq 0x2280
movq $0x0, 0x68db(%rip) # 0xc510
cmpq $0x0, 0x6663(%rip)      # 0xc2a0
jne 0x5c51
cmpb $0x1, 0x68d2(%rip)      # 0xc518
je 0x5e60
callq 0x303b
movq 0x6648(%rip), %rdi      # 0xc2a0
callq 0x2440
movq %rax, 0x6674(%rip)      # 0xc2d8
cmpq $0x0, 0x663c(%rip)      # 0xc2a8
jne 0x5c8a
cmpb $0x1, 0x68a3(%rip)      # 0xc518
je 0x5e65
leaq 0x4c(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x30d1
movq 0x6617(%rip), %rdi      # 0xc2a8
callq 0x2440
movq %rax, 0x6643(%rip)      # 0xc2e0
movq %rbx, %rdi
callq 0x521d
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x5376
movq %rax, %r15
movq 0x661b(%rip), %rdi      # 0xc2d8
callq 0x2280
movq 0x6617(%rip), %rdi      # 0xc2e0
callq 0x2280
movq 0x6303(%rip), %r13      # 0xbfd8
movq (%r13), %rsi
leaq 0x2a6b(%rip), %rdi      # 0x874b
callq 0x2240
movq %r15, %rdi
callq 0x5546
cmpq $0x0, 0x8(%rax)
je 0x5e37
movq %rax, %r12
cmpq $0x0, (%rax)
je 0x5e37
movq (%r13), %rsi
leaq 0x2a7f(%rip), %rdi      # 0x878f
callq 0x2240
movq (%r12), %rbp
leaq 0x2a82(%rip), %rsi      # 0x87a2
movq %rbp, %rdi
callq 0x20b0
movq %rax, %r13
addq %rbp, %r13
movq %r13, %rdi
callq 0x20c0
movq %rax, %rbp
leaq 0x24fd(%rip), %rsi      # 0x823d
movq %r13, %rdi
callq 0x20b0
cmpq %rax, %rbp
jne 0x5e3c
leaq 0x4(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4c66
movq %rax, %r13
movl (%rbp), %esi
testb $0x7, %sil
jne 0x5e4e
movq %r13, %rdi
movq %r14, %rdx
callq 0x56ed
movq %rax, 0x678d(%rip)      # 0xc510
leaq 0x2ace(%rip), %rsi      # 0x8858
movq %rax, %rdi
callq 0x4d54
movq %rax, 0x678f(%rip)      # 0xc528
testq %rax, %rax
je 0x5e56
movq %rax, %rbp
movq %rax, %rdi
callq 0x20c0
movq 0x6224(%rip), %rcx      # 0xbfd8
movq (%rcx), %rdi
cmpq $0x38, %rax
jne 0x5e5b
leaq 0x2ac7(%rip), %rsi      # 0x888f
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2330
movq 0x650f(%rip), %rdi      # 0xc2e8
leaq 0x2abe(%rip), %rsi      # 0x889e
callq 0x4d54
movq 0x673c(%rip), %rsi      # 0xc528
movq %rax, %rdi
callq 0x5b2c
movq %rbx, %rdi
callq 0x2280
movq %r14, %rdi
callq 0x2280
movq %r15, %rdi
callq 0x2280
movq (%r12), %rdi
callq 0x2280
movq %r12, %rdi
callq 0x2280
movq %r13, %rdi
callq 0x2280
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3365
movq %r12, %rdx
addq $0x8, %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x31f3
movq %r13, %rdi
callq 0x3289
callq 0x3326
callq 0x32e7
callq 0x33e3
callq 0x33a4