#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*/ mpz_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ atoi(char *);
char *calloc(int, int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ generate_keys(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_get_str(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
scalar_t__ mpz_inp_raw(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ mpz_out_raw(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_powm(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_str(int /*<<< orphan*/, char *, int);
int mpz_sizeinbase(int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  mpz_t val, n, e, d;
  FILE *pt, *ct;
  FILE *pub, *prv;
  char *string;
  int i, bytes, c;
  char ch;
  if (argc < 3) {
    usage(argv[0]);
    return -1;
  }
  if (!strcmp(argv[1], "-gen")) {
    if (argc != 3) {
      usage(argv[0]);
      return -1;
    }
    generate_keys(atoi(argv[2]));
  }
  mpz_init(val);
  mpz_init(n);
  mpz_init(e);
  mpz_init(d);
  if (!strcmp(argv[1], "-enc")) {
    if (argc != 4) {
      usage(argv[0]);
      return -1;
    }
    pub = fopen("gmp.pub", "r");
    pt = fopen(argv[2], "r");
    ct = fopen(argv[3], "w");
    mpz_inp_raw(n, pub);
    mpz_inp_raw(e, pub);
    bytes = mpz_sizeinbase(n, 16) - 2;
    string = calloc(1, bytes + 1);
    while (!feof(pt)) {
      for (i = 0; (i < bytes) && ((c = fgetc(pt)) != EOF); i += 2)
        sprintf(string + i, "%02hhx", c);
      mpz_set_str(val, string, 16);
      if (mpz_cmp(val, n) > 0) {
        fprintf(stderr, "Value is too large!\n");
      }
      mpz_powm(val, val, e, n);
      mpz_out_raw(ct, val);
    }
    free(string);
  }
  if (!strcmp(argv[1], "-dec")) {
    if (argc != 4) {
      usage(argv[0]);
      return -1;
    }
    prv = fopen("gmp.prv", "r");
    ct = fopen(argv[2], "r");
    pt = fopen(argv[3], "w");
    mpz_inp_raw(n, prv);
    mpz_inp_raw(d, prv);
    bytes = mpz_sizeinbase(n, 16);
    string = calloc(1, bytes + 2);
    string[0] = '0';
    string++;
    while (mpz_inp_raw(val, ct)) {
      mpz_powm(val, val, d, n);
      mpz_get_str(string, 16, val);
      for (i = ((strlen(string) & 1) ? -1 : 0);
           (i < bytes) && (1 == sscanf(string + i, "%02hhx", &ch)); i += 2) {
        fprintf(pt, "%c", ch);
      }
    }
    free(string - 1);
  }
  mpz_clear(val);
  mpz_clear(n);
  mpz_clear(e);
  mpz_clear(d);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1298 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1110 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1695 <main+0x435>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd59(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12eb <main+0x8b>
cmpl   $0x3,-0x8(%rbp)
je     12d7 <main+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1110 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1695 <main+0x435>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1160 <atoi@plt>
mov    %eax,%edi
call   1170 <generate_keys@plt>
mov    -0x14(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x18(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x1c(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x20(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xceb(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    14c2 <main+0x262>
cmpl   $0x4,-0x8(%rbp)
je     134a <main+0xea>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1110 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1695 <main+0x435>
lea    0xcb9(%rip),%rdi
lea    0xcba(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xca2(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xc8c(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   10e0 <mpz_inp_raw@plt>
mov    -0x1c(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   10e0 <mpz_inp_raw@plt>
mov    -0x18(%rbp),%edi
mov    $0x10,%esi
call   10d0 <mpz_sizeinbase@plt>
sub    $0x2,%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    13ee <main+0x18e>
jmp    14b9 <main+0x259>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x50(%rbp),%ecx
mov    %al,-0x56(%rbp)
jge    1421 <main+0x1c1>
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x54(%rbp)
mov    0x2bcf(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x56(%rbp)
mov    -0x56(%rbp),%al
test   $0x1,%al
jne    1431 <main+0x1d1>
jmp    1459 <main+0x1f9>
mov    -0x48(%rbp),%rdi
movslq -0x4c(%rbp),%rax
add    %rax,%rdi
mov    -0x54(%rbp),%edx
lea    0xbd0(%rip),%rsi
call   1180 <sprintf@plt>
mov    -0x4c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4c(%rbp)
jmp    13f5 <main+0x195>
mov    -0x14(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    $0x10,%edx
call   1100 <mpz_set_str@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1120 <mpz_cmp@plt>
cmp    $0x0,%rax
jle    1497 <main+0x237>
mov    0x2b52(%rip),%rax
movslq (%rax),%rdi
lea    0xb8d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <mpz_powm@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1150 <mpz_out_raw@plt>
jmp    13d0 <main+0x170>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xb61(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    166e <main+0x40e>
cmpl   $0x4,-0x8(%rbp)
je     1501 <main+0x2a1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1110 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1695 <main+0x435>
lea    0xb2f(%rip),%rdi
lea    0xb03(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xaeb(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xad5(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   10e0 <mpz_inp_raw@plt>
mov    -0x20(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   10e0 <mpz_inp_raw@plt>
mov    -0x18(%rbp),%edi
mov    $0x10,%esi
call   10d0 <mpz_sizeinbase@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%esi
add    $0x2,%esi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   10e0 <mpz_inp_raw@plt>
cmp    $0x0,%rax
je     1661 <main+0x401>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <mpz_powm@plt>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x10,%esi
call   1090 <mpz_get_str@plt>
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edx
and    $0x1,%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x50(%rbp),%ecx
mov    %al,-0x57(%rbp)
jge    1628 <main+0x3c8>
mov    -0x48(%rbp),%rdi
movslq -0x4c(%rbp),%rax
add    %rax,%rdi
lea    0xa06(%rip),%rsi
lea    -0x55(%rbp),%rdx
call   10f0 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x57(%rbp)
mov    -0x57(%rbp),%al
test   $0x1,%al
jne    1638 <main+0x3d8>
jmp    165c <main+0x3fc>
mov    -0x28(%rbp),%rdi
movsbl -0x55(%rbp),%edx
lea    0x9f8(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x4c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4c(%rbp)
jmp    15ed <main+0x38d>
jmp    1597 <main+0x337>
mov    -0x48(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1130 <mpz_clear@plt>
mov    -0x18(%rbp),%edi
call   1130 <mpz_clear@plt>
mov    -0x1c(%rbp),%edi
call   1130 <mpz_clear@plt>
mov    -0x20(%rbp),%edi
call   1130 <mpz_clear@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jg     1298 <main+0x28>
mov    (%r14),%rdi
call   1110 <usage@plt>
mov    $0xffffffff,%eax
jmp    14ec <main+0x27c>
mov    %edi,%ebp
mov    0x8(%r14),%rdi
lea    0xd5b(%rip),%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    12c3 <main+0x53>
cmp    $0x3,%ebp
jne    1286 <main+0x16>
mov    0x10(%r14),%rdi
call   1160 <atoi@plt>
mov    %eax,%edi
call   1170 <generate_keys@plt>
call   1080 <mpz_init@plt>
call   1080 <mpz_init@plt>
call   1080 <mpz_init@plt>
call   1080 <mpz_init@plt>
mov    0x8(%r14),%rbx
lea    0xd23(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    1391 <main+0x121>
cmp    $0x4,%ebp
jne    1286 <main+0x16>
mov    %ebp,0x24(%rsp)
lea    0xd08(%rip),%rdi
lea    0xd09(%rip),%rbp
mov    %rbp,%rsi
call   1140 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
mov    %rbp,%rsi
call   1140 <fopen@plt>
mov    %rax,%rbp
mov    %r14,0x10(%rsp)
mov    0x18(%r14),%rdi
lea    0xce1(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,0x18(%rsp)
mov    %rbx,%rsi
call   10e0 <mpz_inp_raw@plt>
mov    %rbx,%rsi
call   10e0 <mpz_inp_raw@plt>
mov    $0x10,%esi
call   10d0 <mpz_sizeinbase@plt>
mov    %rax,0x8(%rsp)
lea    -0x1(%rax),%esi
mov    $0x1,%edi
call   1090 <calloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
je     14fb <main+0x28b>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%r14
mov    0x8(%r14),%rbx
mov    0x24(%rsp),%ebp
lea    0xc9a(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    14d6 <main+0x266>
cmp    $0x4,%ebp
jne    1286 <main+0x16>
lea    0xc7f(%rip),%rdi
lea    0xc53(%rip),%rbx
mov    %rbx,%rsi
call   1140 <fopen@plt>
mov    %rax,%rbp
mov    0x10(%r14),%rdi
mov    %rbx,%rsi
call   1140 <fopen@plt>
mov    %rax,%r15
mov    0x18(%r14),%rdi
lea    0xc30(%rip),%rsi
call   1140 <fopen@plt>
mov    %rax,%rbx
mov    %rbp,%rsi
call   10e0 <mpz_inp_raw@plt>
mov    %rbp,%rsi
call   10e0 <mpz_inp_raw@plt>
mov    $0x10,%esi
call   10d0 <mpz_sizeinbase@plt>
mov    %rax,0x8(%rsp)
lea    0x2(%rax),%esi
mov    $0x1,%edi
call   1090 <calloc@plt>
mov    %rax,0x10(%rsp)
movb   $0x30,(%rax)
mov    %r15,0x18(%rsp)
mov    %r15,%rsi
call   10e0 <mpz_inp_raw@plt>
test   %rax,%rax
je     14cc <main+0x25c>
mov    0x10(%rsp),%rbp
add    $0x1,%rbp
movslq 0x8(%rsp),%r14
lea    0xbcb(%rip),%r13
lea    0x7(%rsp),%r15
jmp    146f <main+0x1ff>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x18(%rsp),%rsi
call   10e0 <mpz_inp_raw@plt>
test   %rax,%rax
je     14cc <main+0x25c>
call   1040 <mpz_powm@plt>
mov    %rbp,%rdi
mov    $0x10,%esi
call   10a0 <mpz_get_str@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
and    $0x1,%eax
neg    %eax
cmp    %eax,0x8(%rsp)
jle    1460 <main+0x1f0>
movslq %eax,%r12
nopw   0x0(%rax,%rax,1)
lea    (%r12,%rbp,1),%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   10f0 <sscanf@plt>
cmp    $0x1,%eax
jne    1460 <main+0x1f0>
movsbl 0x7(%rsp),%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
add    $0x2,%r12
cmp    %r14,%r12
jl     14a0 <main+0x230>
jmp    1460 <main+0x1f0>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
call   1130 <mpz_clear@plt>
call   1130 <mpz_clear@plt>
call   1130 <mpz_clear@plt>
call   1130 <mpz_clear@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rax
lea    -0x2(%rax),%r12d
mov    0x2add(%rip),%r14
lea    0xb04(%rip),%r15
jmp    153f <main+0x2cf>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1040 <mpz_powm@plt>
mov    0x18(%rsp),%rdi
call   1150 <mpz_out_raw@plt>
mov    %rbp,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
jne    137c <main+0x10c>
cmpl   $0x3,0x8(%rsp)
jl     1574 <main+0x304>
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%eax
je     1574 <main+0x304>
lea    (%rbx,%r13,1),%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1180 <sprintf@plt>
add    $0x2,%r13
cmp    %r13d,%r12d
jg     1550 <main+0x2e0>
mov    %rbx,%rsi
mov    $0x10,%edx
call   1100 <mpz_set_str@plt>
call   1120 <mpz_cmp@plt>
test   %rax,%rax
jle    1520 <main+0x2b0>
mov    0x2a46(%rip),%rax
movslq (%rax),%rcx
mov    $0x14,%esi
mov    $0x1,%edx
lea    0xa77(%rip),%rdi
call   1190 <fwrite@plt>
jmp    1520 <main+0x2b0>

LLVM IR (-O0):
@.str = [5 x i8] c"-gen\00"
@.str.1 = [5 x i8] c"-enc\00"
@.str.2 = [8 x i8] c"gmp.pub\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i32 0
@.str.5 = [7 x i8] c"%02hhx\00"
@stderr = global i32 0
@.str.6 = [21 x i8] c"Value is too large!\0A\00"
@.str.7 = [5 x i8] c"-dec\00"
@.str.8 = [8 x i8] c"gmp.prv\00"
@.str.9 = [3 x i8] c"%c\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 i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @usage(i8* %24)
store i32 -1, i32* %3
br label %236
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %46, label %32
32: ; preds = %26
%33 = load i32, i32* %4
%34 = icmp ne i32 %33, 3
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = call i32 @usage(i8* %38)
store i32 -1, i32* %3
br label %236
40: ; preds = %32
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
%45 = call i32 @generate_keys(i32 %44)
br label %46
46: ; preds = %40, %26
%47 = load i32, i32* %6
%48 = call i32 @mpz_init(i32 %47)
%49 = load i32, i32* %7
%50 = call i32 @mpz_init(i32 %49)
%51 = load i32, i32* %8
%52 = call i32 @mpz_init(i32 %51)
%53 = load i32, i32* %9
%54 = call i32 @mpz_init(i32 %53)
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = call i32 @strcmp(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%59 = icmp ne i32 %58, 0
br i1 %59, label %142, label %60
60: ; preds = %46
%61 = load i32, i32* %4
%62 = icmp ne i32 %61, 4
br i1 %62, label %63, label %68
63: ; preds = %60
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 0
%66 = load i8*, i8** %65
%67 = call i32 @usage(i8* %66)
store i32 -1, i32* %3
br label %236
68: ; preds = %60
%69 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %69, i32** %12
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 2
%72 = load i8*, i8** %71
%73 = call i32* @fopen(i8* %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %73, i32** %10
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 3
%76 = load i8*, i8** %75
%77 = call i32* @fopen(i8* %76, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %77, i32** %11
%78 = load i32, i32* %7
%79 = load i32*, i32** %12
%80 = call i64 @mpz_inp_raw(i32 %78, i32* %79)
%81 = load i32, i32* %8
%82 = load i32*, i32** %12
%83 = call i64 @mpz_inp_raw(i32 %81, i32* %82)
%84 = load i32, i32* %7
%85 = call i32 @mpz_sizeinbase(i32 %84, i32 16)
%86 = sub nsw i32 %85, 2
store i32 %86, i32* %16
%87 = load i32, i32* %16
%88 = add nsw i32 %87, 1
%89 = call i8* @calloc(i32 1, i32 %88)
store i8* %89, i8** %14
br label %90
90: ; preds = %130, %68
%91 = load i32*, i32** %10
%92 = call i32 @feof(i32* %91)
%93 = icmp ne i32 %92, 0
%94 = xor i1 %93, true
br i1 %94, label %95, label %139
95: ; preds = %90
store i32 0, i32* %15
br label %96
96: ; preds = %114, %95
%97 = load i32, i32* %15
%98 = load i32, i32* %16
%99 = icmp slt i32 %97, %98
br i1 %99, label %100, label %105
100: ; preds = %96
%101 = load i32*, i32** %10
%102 = call i32 @fgetc(i32* %101)
store i32 %102, i32* %17
%103 = load i32, i32* @EOF
%104 = icmp ne i32 %102, %103
br label %105
105: ; preds = %100, %96
%106 = phi i1 [ false, %96 ], [ %104, %100 ]
br i1 %106, label %107, label %117
107: ; preds = %105
%108 = load i8*, i8** %14
%109 = load i32, i32* %15
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8, i8* %108, i64 %110
%112 = load i32, i32* %17
%113 = call i32 @sprintf(i8* %111, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %112)
br label %114
114: ; preds = %107
%115 = load i32, i32* %15
%116 = add nsw i32 %115, 2
store i32 %116, i32* %15
br label %96
117: ; preds = %105
%118 = load i32, i32* %6
%119 = load i8*, i8** %14
%120 = call i32 @mpz_set_str(i32 %118, i8* %119, i32 16)
%121 = load i32, i32* %6
%122 = load i32, i32* %7
%123 = call i64 @mpz_cmp(i32 %121, i32 %122)
%124 = icmp sgt i64 %123, 0
br i1 %124, label %125, label %130
125: ; preds = %117
%126 = load i32, i32* @stderr
%127 = sext i32 %126 to i64
%128 = inttoptr i64 %127 to i32*
%129 = call i32 (i32*, i8*, ...) @fprintf(i32* %128, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %130
130: ; preds = %125, %117
%131 = load i32, i32* %6
%132 = load i32, i32* %6
%133 = load i32, i32* %8
%134 = load i32, i32* %7
%135 = call i32 @mpz_powm(i32 %131, i32 %132, i32 %133, i32 %134)
%136 = load i32*, i32** %11
%137 = load i32, i32* %6
%138 = call i32 @mpz_out_raw(i32* %136, i32 %137)
br label %90
139: ; preds = %90
%140 = load i8*, i8** %14
%141 = call i32 @free(i8* %140)
br label %142
142: ; preds = %139, %46
%143 = load i8**, i8*** %5
%144 = getelementptr inbounds i8*, i8** %143, i64 1
%145 = load i8*, i8** %144
%146 = call i32 @strcmp(i8* %145, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%147 = icmp ne i32 %146, 0
br i1 %147, label %227, label %148
148: ; preds = %142
%149 = load i32, i32* %4
%150 = icmp ne i32 %149, 4
br i1 %150, label %151, label %156
151: ; preds = %148
%152 = load i8**, i8*** %5
%153 = getelementptr inbounds i8*, i8** %152, i64 0
%154 = load i8*, i8** %153
%155 = call i32 @usage(i8* %154)
store i32 -1, i32* %3
br label %236
156: ; preds = %148
%157 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %157, i32** %13
%158 = load i8**, i8*** %5
%159 = getelementptr inbounds i8*, i8** %158, i64 2
%160 = load i8*, i8** %159
%161 = call i32* @fopen(i8* %160, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %161, i32** %11
%162 = load i8**, i8*** %5
%163 = getelementptr inbounds i8*, i8** %162, i64 3
%164 = load i8*, i8** %163
%165 = call i32* @fopen(i8* %164, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %165, i32** %10
%166 = load i32, i32* %7
%167 = load i32*, i32** %13
%168 = call i64 @mpz_inp_raw(i32 %166, i32* %167)
%169 = load i32, i32* %9
%170 = load i32*, i32** %13
%171 = call i64 @mpz_inp_raw(i32 %169, i32* %170)
%172 = load i32, i32* %7
%173 = call i32 @mpz_sizeinbase(i32 %172, i32 16)
store i32 %173, i32* %16
%174 = load i32, i32* %16
%175 = add nsw i32 %174, 2
%176 = call i8* @calloc(i32 1, i32 %175)
store i8* %176, i8** %14
%177 = load i8*, i8** %14
%178 = getelementptr inbounds i8, i8* %177, i64 0
store i8 48, i8* %178
%179 = load i8*, i8** %14
%180 = getelementptr inbounds i8, i8* %179, i32 1
store i8* %180, i8** %14
br label %181
181: ; preds = %222, %156
%182 = load i32, i32* %6
%183 = load i32*, i32** %11
%184 = call i64 @mpz_inp_raw(i32 %182, i32* %183)
%185 = icmp ne i64 %184, 0
br i1 %185, label %186, label %223
186: ; preds = %181
%187 = load i32, i32* %6
%188 = load i32, i32* %6
%189 = load i32, i32* %9
%190 = load i32, i32* %7
%191 = call i32 @mpz_powm(i32 %187, i32 %188, i32 %189, i32 %190)
%192 = load i8*, i8** %14
%193 = load i32, i32* %6
%194 = call i32 @mpz_get_str(i8* %192, i32 16, i32 %193)
%195 = load i8*, i8** %14
%196 = call i32 @strlen(i8* %195)
%197 = and i32 %196, 1
%198 = icmp ne i32 %197, 0
%199 = zext i1 %198 to i64
%200 = select i1 %198, i32 -1, i32 0
store i32 %200, i32* %15
br label %201
201: ; preds = %219, %186
%202 = load i32, i32* %15
%203 = load i32, i32* %16
%204 = icmp slt i32 %202, %203
br i1 %204, label %205, label %212
205: ; preds = %201
%206 = load i8*, i8** %14
%207 = load i32, i32* %15
%208 = sext i32 %207 to i64
%209 = getelementptr inbounds i8, i8* %206, i64 %208
%210 = call i32 @sscanf(i8* %209, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %18)
%211 = icmp eq i32 1, %210
br label %212
212: ; preds = %205, %201
%213 = phi i1 [ false, %201 ], [ %211, %205 ]
br i1 %213, label %214, label %222
214: ; preds = %212
%215 = load i32*, i32** %10
%216 = load i8, i8* %18
%217 = sext i8 %216 to i32
%218 = call i32 (i32*, i8*, ...) @fprintf(i32* %215, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 %217)
br label %219
219: ; preds = %214
%220 = load i32, i32* %15
%221 = add nsw i32 %220, 2
store i32 %221, i32* %15
br label %201
222: ; preds = %212
br label %181
223: ; preds = %181
%224 = load i8*, i8** %14
%225 = getelementptr inbounds i8, i8* %224, i64 -1
%226 = call i32 @free(i8* %225)
br label %227
227: ; preds = %223, %142
%228 = load i32, i32* %6
%229 = call i32 @mpz_clear(i32 %228)
%230 = load i32, i32* %7
%231 = call i32 @mpz_clear(i32 %230)
%232 = load i32, i32* %8
%233 = call i32 @mpz_clear(i32 %232)
%234 = load i32, i32* %9
%235 = call i32 @mpz_clear(i32 %234)
store i32 0, i32* %3
br label %236
236: ; preds = %227, %151, %63, %35, %21
%237 = load i32, i32* %3
ret i32 %237
}

LLVM IR (-O2):
@.str = [5 x i8] c"-gen\00"
@.str.1 = [5 x i8] c"-enc\00"
@.str.2 = [8 x i8] c"gmp.pub\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@EOF = global i32 0
@.str.5 = [7 x i8] c"%02hhx\00"
@stderr = global i32 0
@.str.6 = [21 x i8] c"Value is too large!\0A\00"
@.str.7 = [5 x i8] c"-dec\00"
@.str.8 = [8 x i8] c"gmp.prv\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @usage(i8* %6)
br label %140
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = icmp eq i32 %0, 3
br i1 %14, label %18, label %15
15: ; preds = %13
%16 = load i8*, i8** %1
%17 = tail call i32 @usage(i8* %16)
br label %140
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i32 @generate_keys(i32 %21)
br label %23
23: ; preds = %18, %8
%24 = tail call i32 @mpz_init(i32 undef)
%25 = tail call i32 @mpz_init(i32 undef)
%26 = tail call i32 @mpz_init(i32 undef)
%27 = tail call i32 @mpz_init(i32 undef)
%28 = load i8*, i8** %9
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %28, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %83
31: ; preds = %23
%32 = icmp eq i32 %0, 4
br i1 %32, label %36, label %33
33: ; preds = %31
%34 = load i8*, i8** %1
%35 = tail call i32 @usage(i8* %34)
br label %140
36: ; preds = %31
%37 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = getelementptr inbounds i8*, i8** %1, i64 2
%39 = load i8*, i8** %38
%40 = tail call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%41 = getelementptr inbounds i8*, i8** %1, i64 3
%42 = load i8*, i8** %41
%43 = tail call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%44 = tail call i64 @mpz_inp_raw(i32 undef, i32* %37)
%45 = tail call i64 @mpz_inp_raw(i32 undef, i32* %37)
%46 = tail call i32 @mpz_sizeinbase(i32 undef, i32 16)
%47 = add nsw i32 %46, -2
%48 = add nsw i32 %46, -1
%49 = tail call i8* @calloc(i32 1, i32 %48)
%50 = tail call i32 @feof(i32* %40)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %80
52: ; preds = %36
%53 = icmp sgt i32 %46, 2
br label %54
54: ; preds = %52, %75
br i1 %53, label %55, label %66
55: ; preds = %54, %60
%56 = phi i64 [ %63, %60 ], [ 0, %54 ]
%57 = tail call i32 @fgetc(i32* %40)
%58 = load i32, i32* @EOF
%59 = icmp eq i32 %57, %58
br i1 %59, label %66, label %60
60: ; preds = %55
%61 = getelementptr inbounds i8, i8* %49, i64 %56
%62 = tail call i32 @sprintf(i8* dereferenceable(1) %61, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%63 = add nuw i64 %56, 2
%64 = trunc i64 %63 to i32
%65 = icmp sgt i32 %47, %64
br i1 %65, label %55, label %66
66: ; preds = %55, %60, %54
%67 = tail call i32 @mpz_set_str(i32 undef, i8* %49, i32 16)
%68 = tail call i64 @mpz_cmp(i32 undef, i32 undef)
%69 = icmp sgt i64 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = sext i32 %71 to i64
%73 = inttoptr i64 %72 to i32*
%74 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i64 20, i64 1, i32* %73)
br label %75
75: ; preds = %70, %66
%76 = tail call i32 @mpz_powm(i32 undef, i32 undef, i32 undef, i32 undef)
%77 = tail call i32 @mpz_out_raw(i32* %43, i32 undef)
%78 = tail call i32 @feof(i32* %40)
%79 = icmp eq i32 %78, 0
br i1 %79, label %54, label %80
80: ; preds = %75, %36
%81 = tail call i32 @free(i8* %49)
%82 = load i8*, i8** %9
br label %83
83: ; preds = %80, %23
%84 = phi i8* [ %82, %80 ], [ %28, %23 ]
%85 = tail call i32 @strcmp(i8* dereferenceable(1) %84, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %135
87: ; preds = %83
%88 = icmp eq i32 %0, 4
br i1 %88, label %92, label %89
89: ; preds = %87
%90 = load i8*, i8** %1
%91 = tail call i32 @usage(i8* %90)
br label %140
92: ; preds = %87
%93 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%94 = getelementptr inbounds i8*, i8** %1, i64 2
%95 = load i8*, i8** %94
%96 = tail call i32* @fopen(i8* %95, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%97 = getelementptr inbounds i8*, i8** %1, i64 3
%98 = load i8*, i8** %97
%99 = tail call i32* @fopen(i8* %98, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%100 = tail call i64 @mpz_inp_raw(i32 undef, i32* %93)
%101 = tail call i64 @mpz_inp_raw(i32 undef, i32* %93)
%102 = tail call i32 @mpz_sizeinbase(i32 undef, i32 16)
%103 = add nsw i32 %102, 2
%104 = tail call i8* @calloc(i32 1, i32 %103)
store i8 48, i8* %104
%105 = getelementptr inbounds i8, i8* %104, i64 1
%106 = call i64 @mpz_inp_raw(i32 undef, i32* %96)
%107 = icmp eq i64 %106, 0
br i1 %107, label %133, label %108
108: ; preds = %92
%109 = sext i32 %102 to i64
br label %110
110: ; preds = %108, %130
%111 = call i32 @mpz_powm(i32 undef, i32 undef, i32 undef, i32 undef)
%112 = call i32 @mpz_get_str(i8* %105, i32 16, i32 undef)
%113 = call i32 @strlen(i8* %105)
%114 = and i32 %113, 1
%115 = sub nsw i32 0, %114
%116 = icmp sgt i32 %102, %115
br i1 %116, label %117, label %130
117: ; preds = %110
%118 = sext i32 %115 to i64
br label %119
119: ; preds = %117, %124
%120 = phi i64 [ %118, %117 ], [ %128, %124 ]
%121 = getelementptr inbounds i8, i8* %105, i64 %120
%122 = call i32 @sscanf(i8* %121, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%123 = icmp eq i32 %122, 1
br i1 %123, label %124, label %130
124: ; preds = %119
%125 = load i8, i8* %3
%126 = sext i8 %125 to i32
%127 = call i32 @fputc(i32 %126, i32* %99)
%128 = add i64 %120, 2
%129 = icmp slt i64 %128, %109
br i1 %129, label %119, label %130
130: ; preds = %119, %124, %110
%131 = call i64 @mpz_inp_raw(i32 undef, i32* %96)
%132 = icmp eq i64 %131, 0
br i1 %132, label %133, label %110
133: ; preds = %130, %92
%134 = call i32 @free(i8* %104)
br label %135
135: ; preds = %133, %83
%136 = call i32 @mpz_clear(i32 undef)
%137 = call i32 @mpz_clear(i32 undef)
%138 = call i32 @mpz_clear(i32 undef)
%139 = call i32 @mpz_clear(i32 undef)
br label %140
140: ; preds = %135, %89, %33, %15, %5
%141 = phi i32 [ -1, %5 ], [ 0, %135 ], [ -1, %89 ], [ -1, %33 ], [ -1, %15 ]
ret i32 %141
}