// File: /workspace/github_c_makefile_star2_O1/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
movl $0x25, %esi
callq 0x10d0
leaq 0x48(%rsp), %rdi
movl $0x40, %esi
callq 0x10d0
leaq 0x88(%rsp), %rdi
movl $0x40, %esi
callq 0x10d0
leaq 0x398d(%rip), %r12      # 0x5033
movq 0x692b(%rip), %r14      # 0x7fd8
xorl %r13d, %r13d
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
movq $0x0, 0x18(%rsp)
xorl %ebx, %ebx
movl %ebp, %edi
movq %r15, %rsi
movq %r12, %rdx
callq 0x10e0
cmpl $0x70, %eax
jne 0x1710
movq (%r14), %rbx
testq %r13, %r13
je 0x17a9
movq 0x68fe(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x39f9(%rip), %rsi      # 0x50fd
movq %rbx, %rdx
xorl %eax, %eax
callq 0x10a0
jmp 0x16d5
cmpl $0x66, %eax
jle 0x172d
cmpl $0x72, %eax
jle 0x1761
cmpl $0x73, %eax
je 0x1786
cmpl $0x76, %eax
jne 0x1993
incq %r13
jmp 0x16d5
cmpl $-0x1, %eax
je 0x17b1
cmpl $0x64, %eax
jne 0x1955
cmpq $0x0, 0x10(%rsp)
movl $0x1, %ecx
movl $0x1, %eax
movq %rax, 0x8(%rsp)
movq (%rsp), %rax
cmovneq %rcx, %rax
movq %rax, (%rsp)
jmp 0x16d5
cmpl $0x67, %eax
jne 0x1961
movq (%rsp), %rax
addq 0x8(%rsp), %rax
movq %rax, (%rsp)
movl $0x1, %eax
movq %rax, 0x10(%rsp)
jmp 0x16d5
movq (%r14), %rdx
testq %r13, %r13
movq %rdx, 0x18(%rsp)
je 0x17a9
movq 0x685e(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x396a(%rip), %rsi      # 0x510e
jmp 0x1707
xorl %r13d, %r13d
jmp 0x16d5
cmpq $0x0, (%rsp)
jne 0x199d
cmpq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %r14
je 0x183a
testq %r13, %r13
jne 0x197f
leaq 0x23(%rsp), %r15
movq %r15, %rdi
callq 0x19b8
leaq 0x3a0a(%rip), %rsi      # 0x51f0
leaq 0x48(%rsp), %rdi
movq %r15, %rdx
callq 0x230a
testb %al, %al
je 0x19a2
leaq 0x23(%rsp), %r15
movq %r15, %rdi
callq 0x1475
leaq 0x48(%rsp), %r12
movq %r12, %rdi
callq 0x143c
movl $0x25, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x14e6
movl $0x40, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x14e6
jmp 0x196b
cmpq $0x0, 0x8(%rsp)
je 0x1867
testq %r13, %r13
jne 0x1989
testq %r14, %r14
je 0x1871
leaq 0x23(%rsp), %rsi
movl $0x25, %edx
movq %r14, %rdi
callq 0x1590
movq %rax, %r14
jmp 0x18a8
movl $0x1, %eax
jmp 0x196d
movq 0x6758(%rip), %r12      # 0x7fd0
leaq 0x3791(%rip), %r15      # 0x5010
xorl %ebp, %ebp
xorl %r14d, %r14d
movq (%r12), %rdi
leaq (%rsp,%rbp), %rdx
addq $0x23, %rdx
movq %r15, %rsi
xorl %eax, %eax
callq 0x1040
cltq
addq %rax, %r14
incq %rbp
cmpq $0x25, %rbp
jne 0x1884
cmpq $0x25, %r14
jne 0x19a7
testq %rbx, %rbx
je 0x18ce
leaq 0x48(%rsp), %rsi
movl $0x40, %edx
movq %rbx, %rdi
callq 0x1590
movq %rax, %rbx
jmp 0x1904
movq 0x66fb(%rip), %r15      # 0x7fd0
leaq 0x3734(%rip), %r14      # 0x5010
xorl %r12d, %r12d
xorl %ebx, %ebx
movq (%r15), %rdi
leaq (%rsp,%r12), %rdx
addq $0x48, %rdx
movq %r14, %rsi
xorl %eax, %eax
callq 0x1040
cltq
addq %rax, %rbx
incq %r12
cmpq $0x40, %r12
jne 0x18e1
cmpq $0x40, %rbx
jne 0x19ac
leaq 0x88(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x23(%rsp), %rdx
callq 0x230a
testb %al, %al
je 0x19b1
testq %r13, %r13
je 0x1946
leaq 0x23(%rsp), %rdi
callq 0x1475
leaq 0x48(%rsp), %rdi
callq 0x143c
leaq 0x88(%rsp), %rdi
callq 0x14ae
jmp 0x196b
cmpl $0x56, %eax
jne 0x1993
callq 0x121c
jmp 0x196b
cmpl $0x68, %eax
jne 0x1993
callq 0x1168
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1269
jmp 0x17d2
callq 0x12ad
jmp 0x184b
movl $0x1, %edi
callq 0x10f0
callq 0x1241
callq 0x1285
callq 0x12c9
callq 0x12f1
callq 0x1319
nop