// File: /workspace/github_c_makefile_star2_O2/ioerror[P]csidh-reference-implementation/csidh_util.c
// Function: main
int main(int argc, char **argv) {
  private_key _private_key;
  public_key _public_key;
  public_key shared_secret_key;

  bzero(&_private_key, sizeof(private_key));
  bzero(&_public_key, sizeof(public_key));
  bzero(&shared_secret_key, sizeof(public_key));

  int option = 0;
  size_t verbose = 0;
  size_t generation_mode = 0;
  size_t derivation_mode = 0;
  size_t error = 0;
  bool csidh_validate = false;
  char *priv_key_file = NULL;
  char *pub_key_file = NULL;

  while ((option = getopt(argc, argv, "hvVgdp:s:")) != -1) {
    switch (option) {
    case 'V':
      fprintf(stderr, "csidh-p%i-util version: %f\n", BITS, VERSION);
      return 0;
    case 'h':
      fprintf(stderr, "csidh-p%i-util version: %f\n", BITS, VERSION);
      fprintf(stderr, "  -V: print version\n");
      fprintf(stderr, "  -verbose: increase verbosity\n");
      fprintf(stderr, "  -g: key generation mode\n");
      fprintf(stderr, "  -d: key derivation mode\n");
      fprintf(stderr, "  -p: public key file name\n");
      fprintf(stderr, "  -s: private key file name\n");
      return 0;
    case 'v':
      verbose += 1;
      break;
    case 'g':
      generation_mode = 1;
      if (derivation_mode) {
        error += 1;
      };
      break;
    case 'd':
      derivation_mode = 1;
      if (generation_mode) {
        error = 1;
      };
      break;
    case 'p':
      pub_key_file = optarg;
      if (verbose) {
        fprintf(stderr, "pub_key_file=%s\n", pub_key_file);
      };
      break;
    case 's':
      priv_key_file = optarg;
      if (verbose) {
        fprintf(stderr, "priv_key_file=%s\n", priv_key_file);
      };
      break;
    default:
      exit(1);
    }
  }

  if (error) {
    error_exit("Mutually exclusive options chosen");
  }

  if (generation_mode) {
    if (verbose) {
      fprintf(stderr, "Key generation mode\n");
    }
    csidh_private(&_private_key);
    csidh_validate = csidh(&_public_key, &base, &_private_key);
    if (!csidh_validate) {
      error_exit("csidh_validate: failed");
    }
    pprint_sk(&_private_key);
    pprint_pk(&_public_key);
    save_file(priv_key_file, &_private_key, (uint64_t) sizeof(private_key));
    save_file(pub_key_file, &_public_key,  (uint64_t) sizeof(public_key));
    return 0;
  }

  if (derivation_mode) {
    if (verbose) {
      fprintf(stderr, "DH mode\n");
    }

    if (sizeof(private_key) !=
        ((priv_key_file != NULL)
             ? read_file(priv_key_file, (uint8_t *)&_private_key,
                        (uint64_t) sizeof(private_key))
             : read_stdin((uint8_t *)&_private_key, (uint64_t) sizeof(private_key)))) {
      error_exit("Unable to read correct number of bytes for private key");
    }

    if (sizeof(public_key) !=
        ((pub_key_file != NULL)
             ? read_file(pub_key_file, (uint8_t *)&_public_key,
                         sizeof(public_key))
             : read_stdin((uint8_t *)&_public_key, sizeof(public_key)))) {
      error_exit("Unable to read correct number of bytes for public key");
    }

    csidh_validate = csidh(&shared_secret_key, &_public_key, &_private_key);
    if (!csidh_validate) {
      error_exit("csidh_validate: failed");
    }
    if (verbose) {
      pprint_sk(&_private_key);
      pprint_pk(&_public_key);
    }
    pprint_ss((uint64_t *)&shared_secret_key);
    return 0;
  }

  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r15
movl %edi, %ebp
leaq 0x23(%rsp), %rdi
pushq $0x25
popq %rsi
callq 0x10e0
leaq 0x48(%rsp), %rdi
pushq $0x40
popq %rbx
movq %rbx, %rsi
callq 0x10e0
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
callq 0x10e0
leaq 0x3b92(%rip), %r12      # 0x5033
movq 0x6b30(%rip), %r13      # 0x7fd8
xorl %r14d, %r14d
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
xorl %ebx, %ebx
movl %ebp, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x10f0
cmpl $0x70, %eax
jne 0x1508
movq (%r13), %rbx
testq %r14, %r14
je 0x1567
movq 0x6b06(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x3c01(%rip), %rsi      # 0x50fd
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10a0
jmp 0x14d0
cmpl $-0x1, %eax
je 0x1589
cmpl $0x64, %eax
je 0x152a
cmpl $0x67, %eax
je 0x156f
cmpl $0x73, %eax
je 0x1546
cmpl $0x76, %eax
jne 0x163d
incq %r14
jmp 0x14d0
cmpq $0x0, 0x18(%rsp)
pushq $0x1
popq %rax
movq (%rsp), %rcx
cmovneq %rax, %rcx
movq %rcx, (%rsp)
movq %rax, 0x10(%rsp)
jmp 0x14d0
movq (%r13), %rdx
testq %r14, %r14
movq %rdx, 0x8(%rsp)
je 0x1567
movq 0x6a9d(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x3ba9(%rip), %rsi      # 0x510e
jmp 0x14ff
xorl %r14d, %r14d
jmp 0x14d0
movq (%rsp), %rax
addq 0x10(%rsp), %rax
movq %rax, (%rsp)
pushq $0x1
popq %rax
movq %rax, 0x18(%rsp)
jmp 0x14d0
cmpq $0x0, (%rsp)
jne 0x1810
cmpq $0x0, 0x18(%rsp)
je 0x160b
testq %r14, %r14
jne 0x17c6
leaq 0x23(%rsp), %r15
movq %r15, %rdi
callq 0x1840
leaq 0x3c37(%rip), %rsi      # 0x51f0
leaq 0x48(%rsp), %rdi
movq %r15, %rdx
callq 0x212c
testb %al, %al
je 0x181c
leaq 0x23(%rsp), %r15
movq %r15, %rdi
callq 0x1255
leaq 0x48(%rsp), %r12
movq %r12, %rdi
callq 0x121c
pushq $0x25
popq %rdx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x12c3
pushq $0x40
popq %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x12c3
jmp 0x17b2
cmpq $0x0, 0x10(%rsp)
je 0x1635
testq %r14, %r14
jne 0x17e7
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1679
leaq 0x23(%rsp), %rsi
pushq $0x25
popq %rdx
callq 0x1381
jmp 0x1686
pushq $0x1
popq %rax
jmp 0x17b4
cmpl $0x68, %eax
je 0x1708
cmpl $0x56, %eax
jne 0x1808
movq 0x69a2(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x39dd(%rip), %rsi      # 0x503d
vmovsd 0x39a0(%rip), %xmm0     # 0x5008
movl $0x200, %edx            # imm = 0x200
movb $0x1, %al
callq 0x10a0
jmp 0x17b2
leaq 0x23(%rsp), %rdi
pushq $0x25
popq %rsi
callq 0x1409
cmpq $0x25, %rax
jne 0x1828
testq %rbx, %rbx
je 0x16a7
leaq 0x48(%rsp), %rsi
pushq $0x40
popq %rdx
movq %rbx, %rdi
callq 0x1381
jmp 0x16b4
leaq 0x48(%rsp), %rdi
pushq $0x40
popq %rsi
callq 0x1409
cmpq $0x40, %rax
jne 0x1834
leaq 0x88(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x23(%rsp), %rdx
callq 0x212c
testb %al, %al
je 0x181c
testq %r14, %r14
je 0x16f6
leaq 0x23(%rsp), %rdi
callq 0x1255
leaq 0x48(%rsp), %rdi
callq 0x121c
leaq 0x88(%rsp), %rdi
callq 0x128e
jmp 0x17b2
movq 0x68e9(%rip), %r15      # 0x7ff8
movq (%r15), %rdi
leaq 0x3924(%rip), %rsi      # 0x503d
vmovsd 0x38e7(%rip), %xmm0     # 0x5008
movl $0x200, %edx            # imm = 0x200
movb $0x1, %al
callq 0x10a0
movq (%r15), %rcx
leaq 0x3922(%rip), %rdi      # 0x5059
pushq $0x14
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x1110
movq (%r15), %rcx
leaq 0x391f(%rip), %rdi      # 0x506e
pushq $0x1f
popq %rsi
movq %rbx, %rdx
callq 0x1110
movq (%r15), %rcx
leaq 0x392a(%rip), %rdi      # 0x508e
pushq $0x1a
popq %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1110
movq (%r15), %rcx
leaq 0x392c(%rip), %rdi      # 0x50a9
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1110
movq (%r15), %rcx
leaq 0x3932(%rip), %rdi      # 0x50c4
pushq $0x1b
popq %rsi
movq %rbx, %rdx
callq 0x1110
movq (%r15), %rcx
leaq 0x3939(%rip), %rdi      # 0x50e0
pushq $0x1c
popq %rsi
movq %rbx, %rdx
callq 0x1110
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x682b(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x396b(%rip), %rdi      # 0x5142
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
callq 0x1110
jmp 0x15a5
movq 0x680a(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x3976(%rip), %rdi      # 0x516e
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x1110
jmp 0x161c
pushq $0x1
popq %rdi
callq 0x1100
leaq 0x3909(%rip), %rdi      # 0x5120
callq 0x135d
leaq 0x3934(%rip), %rdi      # 0x5157
callq 0x135d
leaq 0x3948(%rip), %rdi      # 0x5177
callq 0x135d
leaq 0x3973(%rip), %rdi      # 0x51ae
callq 0x135d