// File: /workspace/github_c_makefile_star2_O2/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 $0xa8, %rsp
xorl %edi, %edi
callq 0x21d0
leaq 0x18(%rsp), %r14
movq %rax, (%r14)
pushq $0x9
popq %r15
movq %r15, %rdi
callq 0x2310
movq %rax, %rbx
movq %r14, %rdi
callq 0x21a0
leaq 0x37d0(%rip), %rdx      # 0x86bc
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rcx
callq 0x2160
movq 0x761f(%rip), %rdi      # 0xc520
testq %rdi, %rdi
je 0x4f13
callq 0x2290
andq $0x0, 0x760d(%rip)      # 0xc520
movq 0x7396(%rip), %rdi      # 0xc2b0
testq %rdi, %rdi
jne 0x4f8d
cmpb $0x1, 0x7602(%rip)      # 0xc528
je 0x5325
pushq $0x33
popq %rdi
callq 0x2310
movq %rax, 0x7375(%rip)      # 0xc2b0
movq 0x7096(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
leaq 0x3793(%rip), %rdi      # 0x86df
callq 0x2250
movq 0x75d8(%rip), %rdi      # 0xc530
movq 0x7351(%rip), %rdx      # 0xc2b0
leaq 0x3794(%rip), %rsi      # 0x86fa
xorl %eax, %eax
callq 0x2460
testl %eax, %eax
jle 0x534a
movq 0x75b4(%rip), %rdi      # 0xc530
callq 0x23b0
cmpl $0xa, %eax
jne 0x4f75
movq 0x7323(%rip), %rdi      # 0xc2b0
callq 0x2450
movq %rax, 0x734f(%rip)      # 0xc2e8
movq 0x7318(%rip), %rdi      # 0xc2b8
testq %rdi, %rdi
jne 0x50a1
cmpb $0x1, 0x7578(%rip)      # 0xc528
je 0x5368
pushq $0x33
popq %rdi
callq 0x2310
movq %rax, 0x72f3(%rip)      # 0xc2b8
movq 0x700c(%rip), %r15      # 0xbfd8
movq (%r15), %rsi
leaq 0x374e(%rip), %rdi      # 0x8724
callq 0x2250
movq 0x754e(%rip), %rdi      # 0xc530
callq 0x2210
leaq 0x24(%rsp), %r14
movl %eax, %edi
movq %r14, %rsi
callq 0x2240
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups 0x2c(%r14), %xmm3
leaq 0x60(%rsp), %r14
movaps %xmm0, (%r14)
movaps %xmm1, 0x10(%r14)
movaps %xmm2, 0x20(%r14)
movups %xmm3, 0x2c(%r14)
andb $-0x9, 0xc(%r14)
movq 0x7503(%rip), %rdi      # 0xc530
callq 0x2210
pushq $0x2
popq %rsi
movl %eax, %edi
movq %r14, %rdx
callq 0x22e0
movq 0x74ea(%rip), %rdi      # 0xc530
movq 0x726b(%rip), %rdx      # 0xc2b8
leaq 0x36a6(%rip), %rsi      # 0x86fa
xorl %eax, %eax
callq 0x2460
testl %eax, %eax
jle 0x538a
movq 0x74c6(%rip), %rdi      # 0xc530
callq 0x2210
pushq $0x2
popq %rsi
leaq 0x24(%rsp), %rdx
movl %eax, %edi
callq 0x22e0
movq 0x74ab(%rip), %rdi      # 0xc530
callq 0x23b0
cmpl $0xa, %eax
jne 0x507e
movq (%r15), %rsi
pushq $0xa
popq %rdi
callq 0x22d0
movq 0x7217(%rip), %rdi      # 0xc2b8
callq 0x2450
movq %rax, 0x7243(%rip)      # 0xc2f0
movq %rbx, %rdi
callq 0x42a7
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x43f7
movq %rax, %r12
movq 0x721b(%rip), %rdi      # 0xc2e8
callq 0x2290
movq 0x7217(%rip), %rdi      # 0xc2f0
callq 0x2290
movq 0x6ef3(%rip), %r13      # 0xbfd8
movq (%r13), %rsi
leaq 0x365b(%rip), %rdi      # 0x874b
callq 0x2250
movq %r12, %rdi
callq 0x4615
cmpq $0x0, 0x8(%rax)
je 0x5241
movq %rax, %r14
cmpq $0x0, (%rax)
je 0x5241
movq (%r13), %rsi
leaq 0x366f(%rip), %rdi      # 0x878f
callq 0x2250
movq (%r14), %rbp
leaq 0x3673(%rip), %rsi      # 0x87a2
movq %rbp, %rdi
callq 0x20b0
movq %rax, %r13
addq %rbp, %r13
movq %r13, %rdi
callq 0x38e1
testl %eax, %eax
je 0x526e
movq %r12, 0x8(%rsp)
leaq 0x14(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3823
movq %rax, %r13
movl (%rbp), %ebp
testb $0x7, %bpl
jne 0x52af
movq %rbx, %r12
movq %r13, %rdi
movl %ebp, %esi
movq %r15, %rdx
callq 0x4838
movq %rax, 0x7397(%rip)      # 0xc520
leaq 0x36c8(%rip), %rsi      # 0x8858
movq %rax, %rdi
callq 0x3911
movq %rax, 0x7399(%rip)      # 0xc538
testq %rax, %rax
je 0x52d4
movq %rax, %rbp
movq %rax, %rdi
callq 0x20c0
movq 0x6e1e(%rip), %rbx      # 0xbfd8
movq (%rbx), %rcx
cmpq $0x38, %rax
jne 0x52f9
leaq 0x36c1(%rip), %rsi      # 0x888f
movq %rcx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2340
movq 0x7116(%rip), %rdi      # 0xc2f8
leaq 0x36b5(%rip), %rsi      # 0x889e
callq 0x3911
movq 0x7343(%rip), %rsi      # 0xc538
movq %rax, %rdi
callq 0x4d99
movq %r12, %rdi
callq 0x2290
movq %r15, %rdi
callq 0x2290
movq 0x8(%rsp), %rdi
callq 0x2290
movq (%r14), %rdi
callq 0x2290
movq %r14, %rdi
callq 0x2290
movq %r13, %rdi
callq 0x2290
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r13), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x22d0
movq (%r13), %rcx
leaq 0x350e(%rip), %rdi      # 0x8768
pushq $0x26
popq %rsi
pushq $0x1
popq %rdx
callq 0x2480
movq (%r13), %rsi
jmp 0x5404
leaq 0x3531(%rip), %rsi      # 0x87a6
pushq $0x1b
popq %rdx
movq %r13, %rdi
callq 0x2200
movq 0x6d51(%rip), %rcx      # 0xbfd8
movq (%rcx), %rsi
testl %eax, %eax
jne 0x53c0
leaq 0x3529(%rip), %rdi      # 0x87c2
callq 0x2250
addq $0x1b, %r13
movq %r13, %rdi
callq 0x39de
jmp 0x53d8
movq 0x6d22(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
leaq 0x356c(%rip), %rdi      # 0x882c
callq 0x2250
movq %r13, %rdi
movl %ebp, %esi
callq 0x3b4f
jmp 0x53df
movq 0x6cfd(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x22d0
movq (%r14), %rcx
leaq 0x3569(%rip), %rdi      # 0x885b
pushq $0x18
jmp 0x53f8
pushq $0xa
popq %rbp
movl %ebp, %edi
movq %rcx, %rsi
callq 0x22d0
movq (%rbx), %rcx
leaq 0x3564(%rip), %rdi      # 0x8874
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x2480
movq (%rbx), %rsi
movl %ebp, %edi
jmp 0x5406
movq 0x6cac(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x22d0
movq (%r14), %rcx
leaq 0x3380(%rip), %rdi      # 0x86c3
pushq $0x1b
jmp 0x53f8
movq (%r14), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x22d0
movq (%r14), %rcx
leaq 0x339e(%rip), %rdi      # 0x86ff
pushq $0xd
jmp 0x53f8
movq 0x6c69(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x22d0
movq (%r14), %rcx
leaq 0x3387(%rip), %rdi      # 0x870d
pushq $0x16
jmp 0x53f8
pushq $0x2
popq %rsi
leaq 0x24(%rsp), %rdx
xorl %edi, %edi
callq 0x22e0
movq (%r15), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x22d0
movq (%r15), %rcx
leaq 0x338a(%rip), %rdi      # 0x873a
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x2480
movq (%r15), %rsi
jmp 0x5404
leaq 0x341f(%rip), %rdi      # 0x87e6
callq 0x2250
movq (%r14), %rdi
movl 0x8(%r14), %esi
callq 0x3b4f
movq 0x6bf9(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x22d0
movq (%r14), %rcx
leaq 0x3410(%rip), %rdi      # 0x8806
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x2480
movq (%r14), %rsi
movl %ebx, %edi
callq 0x22d0
pushq $0x1
popq %rdi
callq 0x22a0