#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ u_char;
struct sockaddr_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ s;
typedef int /*<<< orphan*/ RSA;

/* Variables and functions */
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ RSA_free(int /*<<< orphan*/ *);
int RSA_size(int /*<<< orphan*/ *);
int _POSIX_PATH_MAX;
int accept(int, struct sockaddr *, int *);
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int decrypt_token(char *, char, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getopt(int, char **, char *);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int is_pwd_ok(char *, char *, char *, char *);
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read_keys(int /*<<< orphan*/ **, char *, int /*<<< orphan*/ **, char *,
              char *);
int receive_msg(char *, int, char *, char **);
int send_nonce(int, char *);
int send_public_keys(char *, char *, char *, int);
int send_response(int *, char **, char *, int /*<<< orphan*/ *);
int start_server(int *, char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
int translate_and_send(char *, char, char *, char *, int, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int sock, newsock;
  struct sockaddr_storage client_addr;
  socklen_t sin_size;
  char s[INET6_ADDRSTRLEN];
  RSA *decrypt, *sign;
  decrypt = NULL;
  sign = NULL;
  int retval = 0;
  char *dir = NULL;
  char *ip = NULL;
  char *port = NULL;
  char *decr_namefile = NULL;
  char *sign_namefile = NULL;
  dir = (char *)calloc(_POSIX_PATH_MAX + 1, sizeof(char));
  ip = (char *)calloc(17 + 1, sizeof(char));
  port = (char *)calloc(10, sizeof(char));
  decr_namefile = (char *)calloc(_POSIX_PATH_MAX + 1, sizeof(char));
  sign_namefile = (char *)calloc(_POSIX_PATH_MAX + 1, sizeof(char));
  if (dir == NULL || ip == NULL || port == NULL || decr_namefile == NULL ||
      sign_namefile == NULL) {
    ;
    retval = 10011;
    goto FREE;
  }
  strncpy(dir, "/etc/sibyl", _POSIX_PATH_MAX);
  strncpy(port, "9999", 9);
  strncpy(decr_namefile, "decrypt", _POSIX_PATH_MAX);
  strncpy(sign_namefile, "sign", _POSIX_PATH_MAX);
  int c;
  while ((c = getopt(argc, argv, "d:s:i:p:D:h")) != -1) {
    if (optarg == NULL)
      c = 'h';
    switch (c) {
    case 'd':
      strncpy(decr_namefile, optarg, _POSIX_PATH_MAX);
      break;
    case 's':
      strncpy(sign_namefile, optarg, _POSIX_PATH_MAX);
      break;
    case 'p':
      strncpy(port, optarg, 9);
      break;
    case 'i':
      strncpy(ip, optarg, _POSIX_PATH_MAX);
      break;
    case 'D':
      strncpy(dir, optarg, _POSIX_PATH_MAX);
      break;
    case 'h':
    default:
      printf("Usage: %s -d decrypt -s sign -i IP -p port -D dir\n"
             "  -d decrypt: decrypt private key (default: decrypt)\n"
             "  -s sign: sign private key (default: sign)\n"
             "  -i IP: IP where the server will listen (default: localhost)\n"
             "  -p port: port where the server will listen (default: 9999)\n"
             "  -D dir: directory where the private keys are stored "
             "(default: /etc/sibyl)\n"
             "  -h: shows this help text\n",
             argv[0]);
      exit(1);
    }
  }
  retval = read_keys(&decrypt, decr_namefile, &sign, sign_namefile, dir);
  if (retval != 0)
    goto FREE;
  ;
  retval = start_server(&sock, ip, port);
  if (retval != 0) {
    goto FREE;
  };
  while (1) {
    sin_size = sizeof client_addr;
    newsock = accept(sock, (struct sockaddr *)&client_addr, &sin_size);
    if (newsock == -1) {
      perror("server: accept");
      continue;
    }
    inet_ntop(client_addr.ss_family,
              get_in_addr((struct sockaddr *)&client_addr), s, sizeof(s));
    ;
    if (!fork()) {
      close(sock);
      char *strnonce = NULL;
      char *msg = NULL;
      char command = 0;
      char *token[3] = {NULL, NULL, NULL};
      char *p1_data = NULL;
      char *p2_data = NULL;
      char *auth_result = NULL;
      strnonce = (char *)calloc(32, sizeof(char));
      if (strnonce == NULL) {
        ;
        retval = 10011;
        goto ENDCHILD;
      }
      retval = send_nonce(newsock, strnonce);
      if (retval != 0) {
        goto ENDCHILD;
      }
      msg = (char *)calloc(2120, sizeof(char));
      if (msg == NULL) {
        ;
        retval = 10011;
        goto ENDCHILD;
      }
      retval = receive_msg(msg, newsock, &command, token);
      if (retval != 0) {
        goto ENDCHILD;
      };
      ;
      ;
      ;
      ;
      if (command == '-') {
        retval = send_public_keys(dir, decr_namefile, sign_namefile, newsock);
        goto ENDCHILD;
      }
      p1_data = (char *)calloc(RSA_size(decrypt) + 1, sizeof(u_char));
      if (p1_data == NULL) {
        ;
        retval = 10011;
        goto ENDCHILD;
      };
      char *resp = (char *)calloc(2120, sizeof(u_char));
      memcpy(resp, token[1], strlen(token[1]));
      retval = decrypt_token(p1_data, command, resp, decrypt);
      if (retval != 0) {
        printf("Decryption error\n");
        goto ENDCHILD;
      };
      ;
      if (command != 0) {
        if (strncmp(strnonce, token[0], strlen(strnonce))) {
          ;
          retval = 10006;
          goto ENDCHILD;
        }
        retval = translate_and_send(p1_data, command, decr_namefile, dir,
                                    newsock, sign);
        goto ENDCHILD;
      }
      p2_data = (char *)calloc(RSA_size(decrypt) + 1, sizeof(u_char));
      if (p2_data == NULL) {
        perror("Unable to allocate memory for p2_data");
        retval = 10011;
        goto ENDCHILD;
      }
      retval = decrypt_token(p2_data, command, token[2], decrypt);
      if (retval != 0) {
        goto ENDCHILD;
      };
      auth_result = calloc(1, sizeof(char));
      if (auth_result == NULL) {
        ;
        retval = 10011;
        goto ENDCHILD;
      }
      retval = is_pwd_ok(p1_data, p2_data, auth_result, strnonce);
      if (retval != 0) {
        goto ENDCHILD;
      }
      retval = send_response(&newsock, token, auth_result, sign);
      if (retval != 0) {
        goto ENDCHILD;
      }
    ENDCHILD:
      free(strnonce);
      free(msg);
      free(p1_data);
      free(p2_data);
      free(auth_result);
      close(newsock);
      retval = 0;
      goto FREE;
    }
    close(newsock);
  }
FREE:
  RSA_free(decrypt);
  RSA_free(sign);
  free(dir);
  free(ip);
  free(port);
  free(decr_namefile);
  free(sign_namefile);
  exit(retval);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xe0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,-0x58(%rbp)
mov    $0x12,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,-0x60(%rbp)
mov    $0xa,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,-0x68(%rbp)
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,-0x70(%rbp)
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     13e9 <main+0x139>
cmpq   $0x0,-0x60(%rbp)
je     13e9 <main+0x139>
cmpq   $0x0,-0x68(%rbp)
je     13e9 <main+0x139>
cmpq   $0x0,-0x70(%rbp)
je     13e9 <main+0x139>
cmpq   $0x0,-0x78(%rbp)
jne    13f5 <main+0x145>
movl   $0x271b,-0x4c(%rbp)
jmp    1a48 <main+0x798>
mov    -0x58(%rbp),%rdi
mov    0x2bf0(%rip),%rax
mov    (%rax),%edx
lea    0xcb7(%rip),%rsi
call   1050 <strncpy@plt>
mov    -0x68(%rbp),%rdi
lea    0xcb2(%rip),%rsi
mov    $0x9,%edx
call   1050 <strncpy@plt>
mov    -0x70(%rbp),%rdi
mov    0x2bc2(%rip),%rax
mov    (%rax),%edx
lea    0xc99(%rip),%rsi
call   1050 <strncpy@plt>
mov    -0x78(%rbp),%rdi
mov    0x2ba9(%rip),%rax
mov    (%rax),%edx
lea    0xc88(%rip),%rsi
call   1050 <strncpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xc7a(%rip),%rdx
call   1180 <getopt@plt>
mov    %eax,-0x7c(%rbp)
cmp    $0xffffffff,%eax
je     1585 <main+0x2d5>
mov    0x2b7d(%rip),%rax
cmpq   $0x0,(%rax)
jne    148c <main+0x1dc>
movl   $0x68,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
add    $0xffffffbc,%eax
mov    %eax,%ecx
mov    %rcx,-0xe8(%rbp)
sub    $0x2f,%eax
ja     1561 <main+0x2b1>
mov    -0xe8(%rbp),%rax
lea    0xb4e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x70(%rbp),%rdi
mov    0x2b32(%rip),%rax
mov    (%rax),%rsi
mov    0x2b20(%rip),%rax
mov    (%rax),%edx
call   1050 <strncpy@plt>
jmp    1580 <main+0x2d0>
mov    -0x78(%rbp),%rdi
mov    0x2b11(%rip),%rax
mov    (%rax),%rsi
mov    0x2aff(%rip),%rax
mov    (%rax),%edx
call   1050 <strncpy@plt>
jmp    1580 <main+0x2d0>
mov    -0x68(%rbp),%rdi
mov    0x2af0(%rip),%rax
mov    (%rax),%rsi
mov    $0x9,%edx
call   1050 <strncpy@plt>
jmp    1580 <main+0x2d0>
mov    -0x60(%rbp),%rdi
mov    0x2ad3(%rip),%rax
mov    (%rax),%rsi
mov    0x2ac1(%rip),%rax
mov    (%rax),%edx
call   1050 <strncpy@plt>
jmp    1580 <main+0x2d0>
mov    -0x58(%rbp),%rdi
mov    0x2ab2(%rip),%rax
mov    (%rax),%rsi
mov    0x2aa0(%rip),%rax
mov    (%rax),%edx
call   1050 <strncpy@plt>
jmp    1580 <main+0x2d0>
jmp    1561 <main+0x2b1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xb7a(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
mov    $0x1,%edi
call   11a0 <exit@plt>
jmp    1455 <main+0x1a5>
mov    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%rcx
mov    -0x58(%rbp),%r8
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rdx
call   11b0 <read_keys@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     15b0 <main+0x300>
jmp    1a48 <main+0x798>
mov    -0x60(%rbp),%rsi
mov    -0x68(%rbp),%rdx
lea    -0x14(%rbp),%rdi
call   11d0 <start_server@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     15d3 <main+0x323>
jmp    1a48 <main+0x798>
jmp    15d8 <main+0x328>
jmp    15dd <main+0x32d>
movl   $0x4,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1190 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1612 <main+0x362>
lea    0xc57(%rip),%rdi
call   1170 <perror@plt>
jmp    15d8 <main+0x328>
mov    -0x20(%rbp),%eax
mov    %eax,-0xec(%rbp)
lea    -0x20(%rbp),%rdi
call   1070 <get_in_addr@plt>
mov    -0xec(%rbp),%edi
mov    -0xd8(%rbp),%rdx
mov    %eax,%esi
mov    -0xe0(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    $0x0,%al
call   11c0 <fork@plt>
cmp    $0x0,%eax
jne    1a3b <main+0x78b>
mov    -0x14(%rbp),%edi
call   1100 <close@plt>
movq   $0x0,-0x88(%rbp)
movq   $0x0,-0x90(%rbp)
movb   $0x0,-0x91(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10f0 <memset@plt>
movq   $0x0,-0xb8(%rbp)
movq   $0x0,-0xc0(%rbp)
movq   $0x0,-0xc8(%rbp)
mov    $0x20,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    16da <main+0x42a>
movl   $0x271b,-0x4c(%rbp)
jmp    19eb <main+0x73b>
mov    -0x18(%rbp),%edi
mov    -0x88(%rbp),%rsi
call   10d0 <send_nonce@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     16fb <main+0x44b>
jmp    19eb <main+0x73b>
mov    $0x848,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
jne    172b <main+0x47b>
movl   $0x271b,-0x4c(%rbp)
jmp    19eb <main+0x73b>
mov    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%esi
lea    -0xb0(%rbp),%rcx
lea    -0x91(%rbp),%rdx
call   10e0 <receive_msg@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     175a <main+0x4aa>
jmp    19eb <main+0x73b>
movsbl -0x91(%rbp),%eax
cmp    $0x2d,%eax
jne    1786 <main+0x4d6>
mov    -0x58(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1160 <send_public_keys@plt>
mov    %eax,-0x4c(%rbp)
jmp    19eb <main+0x73b>
mov    -0x40(%rbp),%rdi
call   1080 <RSA_size@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x4,%esi
call   1110 <calloc@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
jne    17bf <main+0x50f>
movl   $0x271b,-0x4c(%rbp)
jmp    19eb <main+0x73b>
mov    $0x848,%edi
mov    $0x4,%esi
call   1110 <calloc@plt>
mov    %rax,-0xd0(%rbp)
mov    -0xd0(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0xa8(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0xa8(%rbp),%rdi
call   10a0 <strlen@plt>
mov    -0x100(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
mov    %eax,%edx
call   1140 <memcpy@plt>
mov    -0xb8(%rbp),%rdi
mov    -0x91(%rbp),%al
mov    -0xd0(%rbp),%rdx
mov    -0x40(%rbp),%rcx
movsbl %al,%esi
call   1150 <decrypt_token@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1852 <main+0x5a2>
lea    0xa28(%rip),%rdi
mov    $0x0,%al
call   10c0 <printf@plt>
jmp    19eb <main+0x73b>
movsbl -0x91(%rbp),%eax
cmp    $0x0,%eax
je     18e2 <main+0x632>
mov    -0x88(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    -0xb0(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x88(%rbp),%rdi
call   10a0 <strlen@plt>
mov    -0x110(%rbp),%rdi
mov    -0x108(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
je     18b5 <main+0x605>
movl   $0x2716,-0x4c(%rbp)
jmp    19eb <main+0x73b>
mov    -0xb8(%rbp),%rdi
mov    -0x91(%rbp),%al
mov    -0x70(%rbp),%rdx
mov    -0x58(%rbp),%rcx
mov    -0x18(%rbp),%r8d
mov    -0x48(%rbp),%r9
movsbl %al,%esi
call   1120 <translate_and_send@plt>
mov    %eax,-0x4c(%rbp)
jmp    19eb <main+0x73b>
mov    -0x40(%rbp),%rdi
call   1080 <RSA_size@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x4,%esi
call   1110 <calloc@plt>
mov    %rax,-0xc0(%rbp)
cmpq   $0x0,-0xc0(%rbp)
jne    1927 <main+0x677>
lea    0x96a(%rip),%rdi
call   1170 <perror@plt>
movl   $0x271b,-0x4c(%rbp)
jmp    19eb <main+0x73b>
mov    -0xc0(%rbp),%rdi
mov    -0x91(%rbp),%al
mov    -0xa0(%rbp),%rdx
mov    -0x40(%rbp),%rcx
movsbl %al,%esi
call   1150 <decrypt_token@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1959 <main+0x6a9>
jmp    19eb <main+0x73b>
mov    $0x1,%esi
mov    %esi,%edi
call   1110 <calloc@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
jne    1986 <main+0x6d6>
movl   $0x271b,-0x4c(%rbp)
jmp    19eb <main+0x73b>
mov    -0xb8(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
mov    -0xc8(%rbp),%rdx
mov    -0x88(%rbp),%rcx
call   1130 <is_pwd_ok@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     19b9 <main+0x709>
jmp    19eb <main+0x73b>
lea    -0xb0(%rbp),%rsi
mov    -0xc8(%rbp),%rdx
mov    -0x48(%rbp),%rcx
lea    -0x18(%rbp),%rdi
call   1090 <send_response@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     19e6 <main+0x736>
jmp    19eb <main+0x73b>
jmp    19eb <main+0x73b>
mov    -0x88(%rbp),%rdi
call   1040 <free@plt>
mov    -0x90(%rbp),%rdi
call   1040 <free@plt>
mov    -0xb8(%rbp),%rdi
call   1040 <free@plt>
mov    -0xc0(%rbp),%rdi
call   1040 <free@plt>
mov    -0xc8(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%edi
call   1100 <close@plt>
movl   $0x0,-0x4c(%rbp)
jmp    1a48 <main+0x798>
mov    -0x18(%rbp),%edi
call   1100 <close@plt>
jmp    15d8 <main+0x328>
mov    -0x40(%rbp),%rdi
call   10b0 <RSA_free@plt>
mov    -0x48(%rbp),%rdi
call   10b0 <RSA_free@plt>
mov    -0x58(%rbp),%rdi
call   1040 <free@plt>
mov    -0x60(%rbp),%rdi
call   1040 <free@plt>
mov    -0x68(%rbp),%rdi
call   1040 <free@plt>
mov    -0x70(%rbp),%rdi
call   1040 <free@plt>
mov    -0x78(%rbp),%rdi
call   1040 <free@plt>
mov    -0x4c(%rbp),%edi
call   11a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x78(%rbp)
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
lea    0x1(%rax),%r13d
mov    %r13d,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,%r15
mov    $0x12,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,%r12
mov    $0xa,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,-0x60(%rbp)
mov    %r13d,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    %r13d,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
mov    %rax,%r13
mov    $0x271b,%eax
mov    %r15,-0x50(%rbp)
test   %r15,%r15
je     16ed <main+0x43d>
test   %r12,%r12
je     16ed <main+0x43d>
cmpq   $0x0,-0x60(%rbp)
je     16ed <main+0x43d>
cmpq   $0x0,-0x40(%rbp)
je     16ed <main+0x43d>
test   %r13,%r13
je     16ed <main+0x43d>
mov    %r12,-0x80(%rbp)
lea    0xd19(%rip),%rsi
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rdx
call   1050 <strncpy@plt>
lea    0xd10(%rip),%rsi
mov    -0x60(%rbp),%rdi
mov    $0x9,%edx
call   1050 <strncpy@plt>
mov    0x2c20(%rip),%r15
mov    (%r15),%edx
lea    0xcf6(%rip),%rsi
mov    -0x40(%rbp),%rdi
call   1050 <strncpy@plt>
mov    (%r15),%edx
lea    0xceb(%rip),%rsi
mov    %r13,-0x38(%rbp)
mov    %r13,%rdi
call   1050 <strncpy@plt>
lea    0xcdd(%rip),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1180 <getopt@plt>
cmp    $0xffffffff,%eax
jne    14db <main+0x22b>
lea    -0x58(%rbp),%rdi
lea    -0x78(%rbp),%rdx
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%r13
mov    %r13,%rcx
mov    -0x50(%rbp),%r8
call   11b0 <read_keys@plt>
test   %eax,%eax
mov    -0x80(%rbp),%r12
jne    16ed <main+0x43d>
lea    -0x70(%rbp),%rdi
mov    %r12,%rsi
mov    -0x60(%rbp),%rdx
call   11d0 <start_server@plt>
test   %eax,%eax
jne    16ed <main+0x43d>
lea    -0x88(%rbp),%r12
lea    -0x8c(%rbp),%r13
mov    -0x48(%rbp),%rbx
jmp    1480 <main+0x1d0>
lea    0xdf1(%rip),%rdi
call   1170 <perror@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x4,-0x8c(%rbp)
mov    -0x70(%rbp),%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1190 <accept@plt>
mov    %eax,-0x6c(%rbp)
cmp    $0xffffffff,%eax
je     1467 <main+0x1b7>
mov    %eax,%r14d
mov    -0x88(%rbp),%r15d
mov    %r12,%rdi
call   1070 <get_in_addr@plt>
mov    %r15d,%edi
mov    %eax,%esi
mov    -0x68(%rbp),%rdx
mov    %ebx,%ecx
call   1030 <inet_ntop@plt>
xor    %eax,%eax
call   11c0 <fork@plt>
test   %eax,%eax
je     1578 <main+0x2c8>
mov    %r14d,%edi
call   1100 <close@plt>
jmp    1480 <main+0x1d0>
mov    0x2b16(%rip),%r12
lea    0xb17(%rip),%r15
lea    0xbed(%rip),%r13
jmp    151b <main+0x26b>
mov    0x2af7(%rip),%rax
mov    (%rax),%edx
mov    -0x38(%rbp),%rdi
nop
call   1050 <strncpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   1180 <getopt@plt>
cmp    $0xffffffff,%eax
je     1413 <main+0x163>
mov    (%r12),%rsi
mov    $0x68,%ecx
test   %rsi,%rsi
je     152b <main+0x27b>
mov    %eax,%ecx
add    $0xffffffbc,%ecx
cmp    $0x2f,%ecx
ja     1734 <main+0x484>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
mov    0x2aa9(%rip),%rax
mov    (%rax),%edx
mov    -0x50(%rbp),%rdi
jmp    1500 <main+0x250>
mov    0x2a9a(%rip),%rax
mov    (%rax),%edx
mov    -0x80(%rbp),%rdi
jmp    1500 <main+0x250>
mov    -0x60(%rbp),%rdi
mov    $0x9,%edx
jmp    1500 <main+0x250>
mov    0x2a80(%rip),%rax
mov    (%rax),%edx
mov    -0x40(%rbp),%rdi
jmp    1500 <main+0x250>
mov    -0x70(%rbp),%edi
call   1100 <close@plt>
movb   $0x0,-0x29(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0xb0(%rbp)
movq   $0x0,-0xa0(%rbp)
mov    $0x20,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
test   %rax,%rax
mov    %rax,-0x68(%rbp)
je     1757 <main+0x4a7>
mov    %r14d,%edi
mov    %rax,%rsi
call   10e0 <send_nonce@plt>
test   %eax,%eax
mov    -0x38(%rbp),%r13
jne    174f <main+0x49f>
mov    $0x848,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
test   %rax,%rax
je     174f <main+0x49f>
lea    -0x29(%rbp),%rdx
lea    -0xb0(%rbp),%rcx
mov    %rax,-0x48(%rbp)
mov    %rax,%rdi
mov    %r14d,%esi
call   10f0 <receive_msg@plt>
test   %eax,%eax
jne    1775 <main+0x4c5>
cmpb   $0x2d,-0x29(%rbp)
je     1762 <main+0x4b2>
mov    -0x58(%rbp),%rdi
call   1090 <RSA_size@plt>
lea    0x1(%rax),%edi
mov    $0x4,%esi
call   1110 <calloc@plt>
test   %rax,%rax
je     1775 <main+0x4c5>
mov    %rax,%r15
mov    $0x848,%edi
mov    $0x4,%esi
call   1110 <calloc@plt>
mov    %rax,%r12
mov    -0xa8(%rbp),%rbx
mov    %rbx,%rdi
call   10b0 <strlen@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1140 <memcpy@plt>
movsbl -0x29(%rbp),%esi
mov    -0x58(%rbp),%rcx
mov    %r15,%rdi
mov    %r12,%rdx
call   1150 <decrypt_token@plt>
test   %eax,%eax
jne    177d <main+0x4cd>
cmpb   $0x0,-0x29(%rbp)
jne    178e <main+0x4de>
mov    -0x58(%rbp),%rdi
call   1090 <RSA_size@plt>
lea    0x1(%rax),%edi
mov    $0x4,%esi
call   1110 <calloc@plt>
test   %rax,%rax
jne    17d5 <main+0x525>
lea    0xbc3(%rip),%rdi
call   1170 <perror@plt>
xor    %ebx,%ebx
xor    %r12d,%r12d
mov    -0x68(%rbp),%rdi
call   1040 <free@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %r14d,%edi
call   1100 <close@plt>
mov    -0x80(%rbp),%r12
xor    %eax,%eax
mov    %rax,%rbx
mov    -0x58(%rbp),%rdi
call   10c0 <RSA_free@plt>
mov    -0x78(%rbp),%rdi
call   10c0 <RSA_free@plt>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    -0x60(%rbp),%rdi
call   1040 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
mov    %ebx,%edi
call   11a0 <exit@plt>
mov    (%r14),%rsi
lea    0x9ab(%rip),%rdi
xor    %eax,%eax
call   10d0 <printf@plt>
mov    $0x1,%edi
call   11a0 <exit@plt>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    1775 <main+0x4c5>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
xor    %r15d,%r15d
jmp    17ce <main+0x51e>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %r13,%rdx
mov    %r14d,%ecx
call   1160 <send_public_keys@plt>
xor    %r15d,%r15d
jmp    16b0 <main+0x400>
lea    0xb10(%rip),%rdi
call   1080 <puts@plt>
jmp    16b0 <main+0x400>
mov    -0xb0(%rbp),%r12
mov    -0x68(%rbp),%rbx
mov    %rbx,%rdi
call   10b0 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
jne    17ce <main+0x51e>
movsbl -0x29(%rbp),%esi
mov    -0x78(%rbp),%r9
mov    %r15,%rdi
mov    -0x40(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    %r14d,%r8d
call   1120 <translate_and_send@plt>
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    180a <main+0x55a>
mov    %rax,%rbx
movsbl -0x29(%rbp),%esi
mov    -0xa0(%rbp),%rdx
mov    -0x58(%rbp),%rcx
mov    %rax,%rdi
call   1150 <decrypt_token@plt>
test   %eax,%eax
jne    1807 <main+0x557>
mov    $0x1,%edi
mov    $0x1,%esi
call   1110 <calloc@plt>
test   %rax,%rax
jne    1813 <main+0x563>
xor    %r12d,%r12d
mov    -0x38(%rbp),%r13
jmp    16b5 <main+0x405>
mov    %rax,%r12
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
mov    -0x68(%rbp),%rcx
call   1130 <is_pwd_ok@plt>
test   %eax,%eax
jne    180a <main+0x55a>
mov    -0x78(%rbp),%rcx
lea    -0x6c(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    %r12,%rdx
call   10a0 <send_response@plt>
mov    -0x6c(%rbp),%r14d
jmp    180a <main+0x55a>

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@_POSIX_PATH_MAX = global i32 0
@.str = [11 x i8] c"/etc/sibyl\00"
@.str.1 = [5 x i8] c"9999\00"
@.str.2 = [8 x i8] c"decrypt\00"
@.str.3 = [5 x i8] c"sign\00"
@.str.4 = [12 x i8] c"d:s:i:p:D:h\00"
@optarg = global i8* null
@.str.5 = [374 x i8] c"Usage: %s -d decrypt -s sign -i IP -p port -D dir\0A -d decrypt: decrypt private key (default: decrypt)\0A -s sign: sign private key (default: sign)\0A -i IP: IP where the server will listen (default: localhost)\0A -p port: port where the server will listen (default: 9999)\0A -D dir: directory where the private keys are stored (default: /etc/sibyl)\0A -h: shows this help text\0A\00"
@.str.6 = [15 x i8] c"server: accept\00"
@.str.7 = [18 x i8] c"Decryption error\0A\00"
@.str.8 = [38 x i8] c"Unable to allocate memory for p2_data\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_storage
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i8
%24 = alloca [3 x i8*]
%25 = alloca i8*
%26 = alloca i8*
%27 = alloca i8*
%28 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%29 = load i32, i32* @INET6_ADDRSTRLEN
%30 = zext i32 %29 to i64
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %10
%32 = alloca i8, i64 %30
store i64 %30, i64* %11
store i32* null, i32** %12
store i32* null, i32** %13
store i32 0, i32* %14
store i8* null, i8** %15
store i8* null, i8** %16
store i8* null, i8** %17
store i8* null, i8** %18
store i8* null, i8** %19
%33 = load i32, i32* @_POSIX_PATH_MAX
%34 = add nsw i32 %33, 1
%35 = call i8* @calloc(i32 %34, i32 1)
store i8* %35, i8** %15
%36 = call i8* @calloc(i32 18, i32 1)
store i8* %36, i8** %16
%37 = call i8* @calloc(i32 10, i32 1)
store i8* %37, i8** %17
%38 = load i32, i32* @_POSIX_PATH_MAX
%39 = add nsw i32 %38, 1
%40 = call i8* @calloc(i32 %39, i32 1)
store i8* %40, i8** %18
%41 = load i32, i32* @_POSIX_PATH_MAX
%42 = add nsw i32 %41, 1
%43 = call i8* @calloc(i32 %42, i32 1)
store i8* %43, i8** %19
%44 = load i8*, i8** %15
%45 = icmp eq i8* %44, null
br i1 %45, label %58, label %46
46: ; preds = %2
%47 = load i8*, i8** %16
%48 = icmp eq i8* %47, null
br i1 %48, label %58, label %49
49: ; preds = %46
%50 = load i8*, i8** %17
%51 = icmp eq i8* %50, null
br i1 %51, label %58, label %52
52: ; preds = %49
%53 = load i8*, i8** %18
%54 = icmp eq i8* %53, null
br i1 %54, label %58, label %55
55: ; preds = %52
%56 = load i8*, i8** %19
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %59
58: ; preds = %55, %52, %49, %46, %2
store i32 10011, i32* %14
br label %291
59: ; preds = %55
%60 = load i8*, i8** %15
%61 = load i32, i32* @_POSIX_PATH_MAX
%62 = call i32 @strncpy(i8* %60, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %61)
%63 = load i8*, i8** %17
%64 = call i32 @strncpy(i8* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 9)
%65 = load i8*, i8** %18
%66 = load i32, i32* @_POSIX_PATH_MAX
%67 = call i32 @strncpy(i8* %65, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %66)
%68 = load i8*, i8** %19
%69 = load i32, i32* @_POSIX_PATH_MAX
%70 = call i32 @strncpy(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %113, %59
%72 = load i32, i32* %4
%73 = load i8**, i8*** %5
%74 = call i32 @getopt(i32 %72, i8** %73, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 %74, i32* %20
%75 = icmp ne i32 %74, -1
br i1 %75, label %76, label %114
76: ; preds = %71
%77 = load i8*, i8** @optarg
%78 = icmp eq i8* %77, null
br i1 %78, label %79, label %80
79: ; preds = %76
store i32 104, i32* %20
br label %80
80: ; preds = %79, %76
%81 = load i32, i32* %20
switch i32 %81, label %107 [
i32 100, label %82
i32 115, label %87
i32 112, label %92
i32 105, label %96
i32 68, label %101
i32 104, label %106
]
82: ; preds = %80
%83 = load i8*, i8** %18
%84 = load i8*, i8** @optarg
%85 = load i32, i32* @_POSIX_PATH_MAX
%86 = call i32 @strncpy(i8* %83, i8* %84, i32 %85)
br label %113
87: ; preds = %80
%88 = load i8*, i8** %19
%89 = load i8*, i8** @optarg
%90 = load i32, i32* @_POSIX_PATH_MAX
%91 = call i32 @strncpy(i8* %88, i8* %89, i32 %90)
br label %113
92: ; preds = %80
%93 = load i8*, i8** %17
%94 = load i8*, i8** @optarg
%95 = call i32 @strncpy(i8* %93, i8* %94, i32 9)
br label %113
96: ; preds = %80
%97 = load i8*, i8** %16
%98 = load i8*, i8** @optarg
%99 = load i32, i32* @_POSIX_PATH_MAX
%100 = call i32 @strncpy(i8* %97, i8* %98, i32 %99)
br label %113
101: ; preds = %80
%102 = load i8*, i8** %15
%103 = load i8*, i8** @optarg
%104 = load i32, i32* @_POSIX_PATH_MAX
%105 = call i32 @strncpy(i8* %102, i8* %103, i32 %104)
br label %113
106: ; preds = %80
br label %107
107: ; preds = %80, %106
%108 = load i8**, i8*** %5
%109 = getelementptr inbounds i8*, i8** %108, i64 0
%110 = load i8*, i8** %109
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([374 x i8], [374 x i8]* @.str.5, i64 0, i64 0), i8* %110)
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %101, %96, %92, %87, %82
br label %71
114: ; preds = %71
%115 = load i8*, i8** %18
%116 = load i8*, i8** %19
%117 = load i8*, i8** %15
%118 = call i32 @read_keys(i32** %12, i8* %115, i32** %13, i8* %116, i8* %117)
store i32 %118, i32* %14
%119 = load i32, i32* %14
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %122
121: ; preds = %114
br label %291
122: ; preds = %114
%123 = load i8*, i8** %16
%124 = load i8*, i8** %17
%125 = call i32 @start_server(i32* %6, i8* %123, i8* %124)
store i32 %125, i32* %14
%126 = load i32, i32* %14
%127 = icmp ne i32 %126, 0
br i1 %127, label %128, label %129
128: ; preds = %122
br label %291
129: ; preds = %122
br label %130
130: ; preds = %288, %137, %129
br label %131
131: ; preds = %130
store i32 4, i32* %9
%132 = load i32, i32* %6
%133 = bitcast %struct.sockaddr_storage* %8 to %struct.sockaddr*
%134 = call i32 @accept(i32 %132, %struct.sockaddr* %133, i32* %9)
store i32 %134, i32* %7
%135 = load i32, i32* %7
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %139
137: ; preds = %131
%138 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %130
139: ; preds = %131
%140 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %8, i32 0, i32 0
%141 = load i32, i32* %140
%142 = bitcast %struct.sockaddr_storage* %8 to %struct.sockaddr*
%143 = call i32 @get_in_addr(%struct.sockaddr* %142)
%144 = trunc i64 %30 to i32
%145 = call i32 @inet_ntop(i32 %141, i32 %143, i8* %32, i32 %144)
%146 = call i32 (...) @fork()
%147 = icmp ne i32 %146, 0
br i1 %147, label %288, label %148
148: ; preds = %139
%149 = load i32, i32* %6
%150 = call i32 @close(i32 %149)
store i8* null, i8** %21
store i8* null, i8** %22
store i8 0, i8* %23
%151 = bitcast [3 x i8*]* %24 to i8*
store i8* null, i8** %25
store i8* null, i8** %26
store i8* null, i8** %27
%152 = call i8* @calloc(i32 32, i32 1)
store i8* %152, i8** %21
%153 = load i8*, i8** %21
%154 = icmp eq i8* %153, null
br i1 %154, label %155, label %156
155: ; preds = %148
store i32 10011, i32* %14
br label %275
156: ; preds = %148
%157 = load i32, i32* %7
%158 = load i8*, i8** %21
%159 = call i32 @send_nonce(i32 %157, i8* %158)
store i32 %159, i32* %14
%160 = load i32, i32* %14
%161 = icmp ne i32 %160, 0
br i1 %161, label %162, label %163
162: ; preds = %156
br label %275
163: ; preds = %156
%164 = call i8* @calloc(i32 2120, i32 1)
store i8* %164, i8** %22
%165 = load i8*, i8** %22
%166 = icmp eq i8* %165, null
br i1 %166, label %167, label %168
167: ; preds = %163
store i32 10011, i32* %14
br label %275
168: ; preds = %163
%169 = load i8*, i8** %22
%170 = load i32, i32* %7
%171 = getelementptr inbounds [3 x i8*], [3 x i8*]* %24, i64 0, i64 0
%172 = call i32 @receive_msg(i8* %169, i32 %170, i8* %23, i8** %171)
store i32 %172, i32* %14
%173 = load i32, i32* %14
%174 = icmp ne i32 %173, 0
br i1 %174, label %175, label %176
175: ; preds = %168
br label %275
176: ; preds = %168
%177 = load i8, i8* %23
%178 = sext i8 %177 to i32
%179 = icmp eq i32 %178, 45
br i1 %179, label %180, label %186
180: ; preds = %176
%181 = load i8*, i8** %15
%182 = load i8*, i8** %18
%183 = load i8*, i8** %19
%184 = load i32, i32* %7
%185 = call i32 @send_public_keys(i8* %181, i8* %182, i8* %183, i32 %184)
store i32 %185, i32* %14
br label %275
186: ; preds = %176
%187 = load i32*, i32** %12
%188 = call i32 @RSA_size(i32* %187)
%189 = add nsw i32 %188, 1
%190 = call i8* @calloc(i32 %189, i32 4)
store i8* %190, i8** %25
%191 = load i8*, i8** %25
%192 = icmp eq i8* %191, null
br i1 %192, label %193, label %194
193: ; preds = %186
store i32 10011, i32* %14
br label %275
194: ; preds = %186
%195 = call i8* @calloc(i32 2120, i32 4)
store i8* %195, i8** %28
%196 = load i8*, i8** %28
%197 = getelementptr inbounds [3 x i8*], [3 x i8*]* %24, i64 0, i64 1
%198 = load i8*, i8** %197
%199 = getelementptr inbounds [3 x i8*], [3 x i8*]* %24, i64 0, i64 1
%200 = load i8*, i8** %199
%201 = call i32 @strlen(i8* %200)
%202 = call i32 @memcpy(i8* %196, i8* %198, i32 %201)
%203 = load i8*, i8** %25
%204 = load i8, i8* %23
%205 = load i8*, i8** %28
%206 = load i32*, i32** %12
%207 = call i32 @decrypt_token(i8* %203, i8 signext %204, i8* %205, i32* %206)
store i32 %207, i32* %14
%208 = load i32, i32* %14
%209 = icmp ne i32 %208, 0
br i1 %209, label %210, label %212
210: ; preds = %194
%211 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %275
212: ; preds = %194
%213 = load i8, i8* %23
%214 = sext i8 %213 to i32
%215 = icmp ne i32 %214, 0
br i1 %215, label %216, label %233
216: ; preds = %212
%217 = load i8*, i8** %21
%218 = getelementptr inbounds [3 x i8*], [3 x i8*]* %24, i64 0, i64 0
%219 = load i8*, i8** %218
%220 = load i8*, i8** %21
%221 = call i32 @strlen(i8* %220)
%222 = call i64 @strncmp(i8* %217, i8* %219, i32 %221)
%223 = icmp ne i64 %222, 0
br i1 %223, label %224, label %225
224: ; preds = %216
store i32 10006, i32* %14
br label %275
225: ; preds = %216
%226 = load i8*, i8** %25
%227 = load i8, i8* %23
%228 = load i8*, i8** %18
%229 = load i8*, i8** %15
%230 = load i32, i32* %7
%231 = load i32*, i32** %13
%232 = call i32 @translate_and_send(i8* %226, i8 signext %227, i8* %228, i8* %229, i32 %230, i32* %231)
store i32 %232, i32* %14
br label %275
233: ; preds = %212
%234 = load i32*, i32** %12
%235 = call i32 @RSA_size(i32* %234)
%236 = add nsw i32 %235, 1
%237 = call i8* @calloc(i32 %236, i32 4)
store i8* %237, i8** %26
%238 = load i8*, i8** %26
%239 = icmp eq i8* %238, null
br i1 %239, label %240, label %242
240: ; preds = %233
%241 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
store i32 10011, i32* %14
br label %275
242: ; preds = %233
%243 = load i8*, i8** %26
%244 = load i8, i8* %23
%245 = getelementptr inbounds [3 x i8*], [3 x i8*]* %24, i64 0, i64 2
%246 = load i8*, i8** %245
%247 = load i32*, i32** %12
%248 = call i32 @decrypt_token(i8* %243, i8 signext %244, i8* %246, i32* %247)
store i32 %248, i32* %14
%249 = load i32, i32* %14
%250 = icmp ne i32 %249, 0
br i1 %250, label %251, label %252
251: ; preds = %242
br label %275
252: ; preds = %242
%253 = call i8* @calloc(i32 1, i32 1)
store i8* %253, i8** %27
%254 = load i8*, i8** %27
%255 = icmp eq i8* %254, null
br i1 %255, label %256, label %257
256: ; preds = %252
store i32 10011, i32* %14
br label %275
257: ; preds = %252
%258 = load i8*, i8** %25
%259 = load i8*, i8** %26
%260 = load i8*, i8** %27
%261 = load i8*, i8** %21
%262 = call i32 @is_pwd_ok(i8* %258, i8* %259, i8* %260, i8* %261)
store i32 %262, i32* %14
%263 = load i32, i32* %14
%264 = icmp ne i32 %263, 0
br i1 %264, label %265, label %266
265: ; preds = %257
br label %275
266: ; preds = %257
%267 = getelementptr inbounds [3 x i8*], [3 x i8*]* %24, i64 0, i64 0
%268 = load i8*, i8** %27
%269 = load i32*, i32** %13
%270 = call i32 @send_response(i32* %7, i8** %267, i8* %268, i32* %269)
store i32 %270, i32* %14
%271 = load i32, i32* %14
%272 = icmp ne i32 %271, 0
br i1 %272, label %273, label %274
273: ; preds = %266
br label %275
274: ; preds = %266
br label %275
275: ; preds = %274, %273, %265, %256, %251, %240, %225, %224, %210, %193, %180, %175, %167, %162, %155
%276 = load i8*, i8** %21
%277 = call i32 @free(i8* %276)
%278 = load i8*, i8** %22
%279 = call i32 @free(i8* %278)
%280 = load i8*, i8** %25
%281 = call i32 @free(i8* %280)
%282 = load i8*, i8** %26
%283 = call i32 @free(i8* %282)
%284 = load i8*, i8** %27
%285 = call i32 @free(i8* %284)
%286 = load i32, i32* %7
%287 = call i32 @close(i32 %286)
store i32 0, i32* %14
br label %291
288: ; preds = %139
%289 = load i32, i32* %7
%290 = call i32 @close(i32 %289)
br label %130
291: ; preds = %275, %128, %121, %58
%292 = load i32*, i32** %12
%293 = call i32 @RSA_free(i32* %292)
%294 = load i32*, i32** %13
%295 = call i32 @RSA_free(i32* %294)
%296 = load i8*, i8** %15
%297 = call i32 @free(i8* %296)
%298 = load i8*, i8** %16
%299 = call i32 @free(i8* %298)
%300 = load i8*, i8** %17
%301 = call i32 @free(i8* %300)
%302 = load i8*, i8** %18
%303 = call i32 @free(i8* %302)
%304 = load i8*, i8** %19
%305 = call i32 @free(i8* %304)
%306 = load i32, i32* %14
%307 = call i32 @exit(i32 %306)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@_POSIX_PATH_MAX = global i32 0
@.str = [11 x i8] c"/etc/sibyl\00"
@.str.1 = [5 x i8] c"9999\00"
@.str.2 = [8 x i8] c"decrypt\00"
@.str.3 = [5 x i8] c"sign\00"
@.str.4 = [12 x i8] c"d:s:i:p:D:h\00"
@optarg = global i8* null
@.str.5 = [374 x i8] c"Usage: %s -d decrypt -s sign -i IP -p port -D dir\0A -d decrypt: decrypt private key (default: decrypt)\0A -s sign: sign private key (default: sign)\0A -i IP: IP where the server will listen (default: localhost)\0A -p port: port where the server will listen (default: 9999)\0A -D dir: directory where the private keys are stored (default: /etc/sibyl)\0A -h: shows this help text\0A\00"
@.str.6 = [15 x i8] c"server: accept\00"
@.str.8 = [38 x i8] c"Unable to allocate memory for p2_data\00"
@str = [17 x i8] c"Decryption error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_storage
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8
%10 = alloca [3 x i8*]
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast %struct.sockaddr_storage* %5 to i8*
%14 = bitcast i32* %6 to i8*
%15 = load i32, i32* @INET6_ADDRSTRLEN
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
%18 = bitcast i32** %7 to i8*
%19 = bitcast i32** %8 to i8*
store i32* null, i32** %7
store i32* null, i32** %8
%20 = load i32, i32* @_POSIX_PATH_MAX
%21 = add nsw i32 %20, 1
%22 = tail call i8* @calloc(i32 %21, i32 1)
%23 = tail call dereferenceable_or_null(18) i8* @calloc(i32 18, i32 1)
%24 = tail call dereferenceable_or_null(10) i8* @calloc(i32 10, i32 1)
%25 = tail call i8* @calloc(i32 %21, i32 1)
%26 = tail call i8* @calloc(i32 %21, i32 1)
%27 = icmp eq i8* %22, null
%28 = icmp eq i8* %23, null
%29 = or i1 %27, %28
%30 = icmp eq i8* %24, null
%31 = or i1 %29, %30
%32 = icmp eq i8* %25, null
%33 = or i1 %31, %32
%34 = icmp eq i8* %26, null
%35 = or i1 %33, %34
br i1 %35, label %183, label %36
36: ; preds = %2
%37 = tail call i32 @strncpy(i8* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %20)
%38 = tail call i32 @strncpy(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 9)
%39 = load i32, i32* @_POSIX_PATH_MAX
%40 = tail call i32 @strncpy(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32, i32* @_POSIX_PATH_MAX
%42 = tail call i32 @strncpy(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%44 = icmp eq i32 %43, -1
br i1 %44, label %71, label %45
45: ; preds = %36, %68
%46 = phi i32 [ %69, %68 ], [ %43, %36 ]
%47 = load i8*, i8** @optarg
%48 = icmp eq i8* %47, null
%49 = select i1 %48, i32 104, i32 %46
switch i32 %49, label %64 [
i32 100, label %50
i32 115, label %53
i32 112, label %56
i32 105, label %58
i32 68, label %61
]
50: ; preds = %45
%51 = load i32, i32* @_POSIX_PATH_MAX
%52 = tail call i32 @strncpy(i8* %25, i8* %47, i32 %51)
br label %68
53: ; preds = %45
%54 = load i32, i32* @_POSIX_PATH_MAX
%55 = tail call i32 @strncpy(i8* %26, i8* %47, i32 %54)
br label %68
56: ; preds = %45
%57 = tail call i32 @strncpy(i8* %24, i8* %47, i32 9)
br label %68
58: ; preds = %45
%59 = load i32, i32* @_POSIX_PATH_MAX
%60 = tail call i32 @strncpy(i8* %23, i8* %47, i32 %59)
br label %68
61: ; preds = %45
%62 = load i32, i32* @_POSIX_PATH_MAX
%63 = tail call i32 @strncpy(i8* %22, i8* %47, i32 %62)
br label %68
64: ; preds = %45
%65 = load i8*, i8** %1
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([374 x i8], [374 x i8]* @.str.5, i64 0, i64 0), i8* %65)
%67 = tail call i32 @exit(i32 1)
unreachable
68: ; preds = %61, %58, %56, %53, %50
%69 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %45
71: ; preds = %68, %36
%72 = call i32 @read_keys(i32** %7, i8* %25, i32** %8, i8* %26, i8* %22)
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %183
74: ; preds = %71
%75 = call i32 @start_server(i32* %3, i8* %23, i8* %24)
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %183
77: ; preds = %74
%78 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %5, i64 0, i32 0
%79 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
br label %80
80: ; preds = %86, %77
store i32 4, i32* %6
%81 = load i32, i32* %3
%82 = call i32 @accept(i32 %81, %struct.sockaddr* %79, i32* %6)
store i32 %82, i32* %4
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %87
84: ; preds = %80
%85 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %86
86: ; preds = %84, %181
br label %80
87: ; preds = %80
%88 = load i32, i32* %78
%89 = call i32 @get_in_addr(%struct.sockaddr* %79)
%90 = call i32 @inet_ntop(i32 %88, i32 %89, i8* %17, i32 %15)
%91 = call i32 (...) @fork()
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %181
93: ; preds = %87
%94 = load i32, i32* %3
%95 = call i32 @close(i32 %94)
store i8 0, i8* %9
%96 = bitcast [3 x i8*]* %10 to i8*
%97 = call dereferenceable_or_null(32) i8* @calloc(i32 32, i32 1)
%98 = icmp eq i8* %97, null
br i1 %98, label %169, label %99
99: ; preds = %93
%100 = call i32 @send_nonce(i32 %82, i8* %97)
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %169
102: ; preds = %99
%103 = call dereferenceable_or_null(2120) i8* @calloc(i32 2120, i32 1)
%104 = icmp eq i8* %103, null
br i1 %104, label %169, label %105
105: ; preds = %102
%106 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 0
%107 = call i32 @receive_msg(i8* %103, i32 %82, i8* %9, i8** %106)
%108 = icmp eq i32 %107, 0
br i1 %108, label %109, label %169
109: ; preds = %105
%110 = load i8, i8* %9
%111 = icmp eq i8 %110, 45
br i1 %111, label %112, label %114
112: ; preds = %109
%113 = call i32 @send_public_keys(i8* %22, i8* %25, i8* %26, i32 %82)
br label %169
114: ; preds = %109
%115 = load i32*, i32** %7
%116 = call i32 @RSA_size(i32* %115)
%117 = add nsw i32 %116, 1
%118 = call i8* @calloc(i32 %117, i32 4)
%119 = icmp eq i8* %118, null
br i1 %119, label %169, label %120
120: ; preds = %114
%121 = call dereferenceable_or_null(8480) i8* @calloc(i32 2120, i32 4)
%122 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 1
%123 = load i8*, i8** %122
%124 = call i32 @strlen(i8* %123)
%125 = call i32 @memcpy(i8* %121, i8* %123, i32 %124)
%126 = load i8, i8* %9
%127 = load i32*, i32** %7
%128 = call i32 @decrypt_token(i8* %118, i8 signext %126, i8* %121, i32* %127)
%129 = icmp eq i32 %128, 0
br i1 %129, label %132, label %130
130: ; preds = %120
%131 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %169
132: ; preds = %120
%133 = load i8, i8* %9
%134 = icmp eq i8 %133, 0
br i1 %134, label %144, label %135
135: ; preds = %132
%136 = load i8*, i8** %106
%137 = call i32 @strlen(i8* %97)
%138 = call i64 @strncmp(i8* %97, i8* %136, i32 %137)
%139 = icmp eq i64 %138, 0
br i1 %139, label %140, label %169
140: ; preds = %135
%141 = load i8, i8* %9
%142 = load i32*, i32** %8
%143 = call i32 @translate_and_send(i8* %118, i8 signext %141, i8* %25, i8* %22, i32 %82, i32* %142)
br label %169
144: ; preds = %132
%145 = load i32*, i32** %7
%146 = call i32 @RSA_size(i32* %145)
%147 = add nsw i32 %146, 1
%148 = call i8* @calloc(i32 %147, i32 4)
%149 = icmp eq i8* %148, null
br i1 %149, label %150, label %152
150: ; preds = %144
%151 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
br label %169
152: ; preds = %144
%153 = load i8, i8* %9
%154 = getelementptr inbounds [3 x i8*], [3 x i8*]* %10, i64 0, i64 2
%155 = load i8*, i8** %154
%156 = load i32*, i32** %7
%157 = call i32 @decrypt_token(i8* %148, i8 signext %153, i8* %155, i32* %156)
%158 = icmp eq i32 %157, 0
br i1 %158, label %159, label %169
159: ; preds = %152
%160 = call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
%161 = icmp eq i8* %160, null
br i1 %161, label %169, label %162
162: ; preds = %159
%163 = call i32 @is_pwd_ok(i8* %118, i8* %148, i8* %160, i8* %97)
%164 = icmp eq i32 %163, 0
br i1 %164, label %165, label %169
165: ; preds = %162
%166 = load i32*, i32** %8
%167 = call i32 @send_response(i32* %4, i8** %106, i8* %160, i32* %166)
%168 = load i32, i32* %4
br label %169
169: ; preds = %159, %135, %114, %102, %93, %165, %162, %152, %105, %99, %150, %140, %130, %112
%170 = phi i32 [ %82, %99 ], [ %82, %105 ], [ %82, %112 ], [ %82, %130 ], [ %82, %140 ], [ %82, %150 ], [ %82, %152 ], [ %82, %162 ], [ %168, %165 ], [ %82, %93 ], [ %82, %102 ], [ %82, %114 ], [ %82, %135 ], [ %82, %159 ]
%171 = phi i8* [ null, %99 ], [ %103, %105 ], [ %103, %112 ], [ %103, %130 ], [ %103, %140 ], [ %103, %150 ], [ %103, %152 ], [ %103, %162 ], [ %103, %165 ], [ null, %93 ], [ null, %102 ], [ %103, %114 ], [ %103, %135 ], [ %103, %159 ]
%172 = phi i8* [ null, %99 ], [ null, %105 ], [ null, %112 ], [ %118, %130 ], [ %118, %140 ], [ %118, %150 ], [ %118, %152 ], [ %118, %162 ], [ %118, %165 ], [ null, %93 ], [ null, %102 ], [ null, %114 ], [ %118, %135 ], [ %118, %159 ]
%173 = phi i8* [ null, %99 ], [ null, %105 ], [ null, %112 ], [ null, %130 ], [ null, %140 ], [ null, %150 ], [ %148, %152 ], [ %148, %162 ], [ %148, %165 ], [ null, %93 ], [ null, %102 ], [ null, %114 ], [ null, %135 ], [ %148, %159 ]
%174 = phi i8* [ null, %99 ], [ null, %105 ], [ null, %112 ], [ null, %130 ], [ null, %140 ], [ null, %150 ], [ null, %152 ], [ %160, %162 ], [ %160, %165 ], [ null, %93 ], [ null, %102 ], [ null, %114 ], [ null, %135 ], [ null, %159 ]
%175 = call i32 @free(i8* %97)
%176 = call i32 @free(i8* %171)
%177 = call i32 @free(i8* %172)
%178 = call i32 @free(i8* %173)
%179 = call i32 @free(i8* %174)
%180 = call i32 @close(i32 %170)
br label %183
181: ; preds = %87
%182 = call i32 @close(i32 %82)
br label %86
183: ; preds = %2, %74, %71, %169
%184 = phi i32 [ %72, %71 ], [ %75, %74 ], [ 0, %169 ], [ 10011, %2 ]
%185 = load i32*, i32** %7
%186 = call i32 @RSA_free(i32* %185)
%187 = load i32*, i32** %8
%188 = call i32 @RSA_free(i32* %187)
%189 = call i32 @free(i8* %22)
%190 = call i32 @free(i8* %23)
%191 = call i32 @free(i8* %24)
%192 = call i32 @free(i8* %25)
%193 = call i32 @free(i8* %26)
%194 = call i32 @exit(i32 %184)
unreachable
}