#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 *mpz_t;

/* Variables and functions */
int crypt(int *, int *, int *, int *, size_t);
int /*<<< orphan*/ gmp_sscanf(char const *, char *, int *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ mpz_clear(int *);
int /*<<< orphan*/ mpz_export(char *, size_t *, int, int, int /*<<< orphan*/,
                              int /*<<< orphan*/, int *);
int /*<<< orphan*/ mpz_init2(int *, size_t);
int strlen(char const *);
const char *decrypt_pri(const char *cipher_text, const char *private_key) {
  int len;
  gmp_sscanf(private_key, "-----RSA Private Key-----\nl: %d", &len);
  mpz_t n, d, message, cipher, t1, t2, t3;
  mpz_init2(n, len);
  mpz_init2(d, len);
  mpz_init2(t1, len);
  mpz_init2(t2, len / 2);
  mpz_init2(t3, len / 2);
  gmp_sscanf(private_key,
             "-----RSA Private Key-----\nl: %d\nn: %Zx\ne: %Zx\nd: %Zx\np: "
             "%Zx\nq: %Zx\n-----End-----\n",
             &len, n, t1, d, t2, t3);
  mpz_clear(t1);
  mpz_clear(t2);
  mpz_clear(t3);
  size_t max_bit = (strlen(cipher_text) * 4 / len + 1) * len;
  mpz_init2(cipher, max_bit);
  mpz_init2(message, max_bit);
  gmp_sscanf(cipher_text, "%Zx", cipher);
  int round = crypt(n, d, cipher, message, max_bit);
  char *buf = (char *)malloc(sizeof(char) * (round * len / 8 + 1));
  size_t length;
  mpz_export(buf, &length, 1, sizeof(char), 0, 0, message);
  buf[length] = '\0';
  mpz_clear(n);
  mpz_clear(d);
  mpz_clear(message);
  mpz_clear(cipher);
  return buf;
}


x86 assembly (clang, -O0):
<decrypt_pri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1080 <gmp_sscanf@plt>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rsi
call   1090 <mpz_init2@plt>
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rsi
call   1090 <mpz_init2@plt>
mov    -0x40(%rbp),%rdi
movslq -0x14(%rbp),%rsi
call   1090 <mpz_init2@plt>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %eax,%rsi
call   1090 <mpz_init2@plt>
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %eax,%rsi
call   1090 <mpz_init2@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x48(%rbp),%r10
mov    -0x50(%rbp),%rax
lea    0xe13(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1080 <gmp_sscanf@plt>
mov    -0x40(%rbp),%rdi
call   1070 <mpz_clear@plt>
mov    -0x48(%rbp),%rdi
call   1070 <mpz_clear@plt>
mov    -0x50(%rbp),%rdi
call   1070 <mpz_clear@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
shl    $0x2,%eax
cltd
idivl  -0x14(%rbp)
add    $0x1,%eax
imul   -0x14(%rbp),%eax
cltq
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1090 <mpz_init2@plt>
mov    -0x30(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1090 <mpz_init2@plt>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1080 <gmp_sscanf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x58(%rbp),%r8
call   1030 <crypt@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x30(%rbp),%rax
lea    -0x70(%rbp),%rsi
mov    $0x1,%ecx
xor    %r9d,%r9d
mov    %ecx,%edx
mov    %r9d,%r8d
mov    %rax,(%rsp)
call   1050 <mpz_export@plt>
mov    -0x68(%rbp),%rax
mov    -0x70(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1070 <mpz_clear@plt>
mov    -0x28(%rbp),%rdi
call   1070 <mpz_clear@plt>
mov    -0x30(%rbp),%rdi
call   1070 <mpz_clear@plt>
mov    -0x38(%rbp),%rdi
call   1070 <mpz_clear@plt>
mov    -0x68(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decrypt_pri>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe7a(%rip),%rsi
lea    0x14(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <gmp_sscanf@plt>
movslq 0x14(%rsp),%rsi
call   1090 <mpz_init2@plt>
movslq 0x14(%rsp),%rsi
call   1090 <mpz_init2@plt>
movslq 0x14(%rsp),%rsi
call   1090 <mpz_init2@plt>
mov    0x14(%rsp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rsi
call   1090 <mpz_init2@plt>
mov    0x14(%rsp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rsi
call   1090 <mpz_init2@plt>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <gmp_sscanf@plt>
call   1070 <mpz_clear@plt>
call   1070 <mpz_clear@plt>
call   1070 <mpz_clear@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
shl    $0x2,%eax
mov    0x14(%rsp),%ecx
cltd
idiv   %ecx
add    $0x1,%eax
imul   %ecx,%eax
movslq %eax,%rbx
mov    %rbx,%rsi
call   1090 <mpz_init2@plt>
mov    %rbx,%rsi
call   1090 <mpz_init2@plt>
lea    0xe3d(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <gmp_sscanf@plt>
mov    %rbx,%r8
call   1030 <crypt@plt>
imul   0x14(%rsp),%eax
lea    0x7(%rax),%edi
test   %eax,%eax
cmovns %eax,%edi
sar    $0x3,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0x18(%rsp),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <mpz_export@plt>
mov    0x18(%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
call   1070 <mpz_clear@plt>
call   1070 <mpz_clear@plt>
call   1070 <mpz_clear@plt>
call   1070 <mpz_clear@plt>
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"-----RSA Private Key-----\0Al: %d\00"
@.str.1 = [82 x i8] c"-----RSA Private Key-----\0Al: %d\0An: %Zx\0Ae: %Zx\0Ad: %Zx\0Ap: %Zx\0Aq: %Zx\0A-----End-----\0A\00"
@.str.2 = [4 x i8] c"%Zx\00"
define i8* @decrypt_pri(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%17 = load i8*, i8** %4
%18 = call i32 (i8*, i8*, i32*, ...) @gmp_sscanf(i8* %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32* %5)
%19 = load i32*, i32** %6
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = call i32 @mpz_init2(i32* %19, i64 %21)
%23 = load i32*, i32** %7
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = call i32 @mpz_init2(i32* %23, i64 %25)
%27 = load i32*, i32** %10
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = call i32 @mpz_init2(i32* %27, i64 %29)
%31 = load i32*, i32** %11
%32 = load i32, i32* %5
%33 = sdiv i32 %32, 2
%34 = sext i32 %33 to i64
%35 = call i32 @mpz_init2(i32* %31, i64 %34)
%36 = load i32*, i32** %12
%37 = load i32, i32* %5
%38 = sdiv i32 %37, 2
%39 = sext i32 %38 to i64
%40 = call i32 @mpz_init2(i32* %36, i64 %39)
%41 = load i8*, i8** %4
%42 = load i32*, i32** %6
%43 = load i32*, i32** %10
%44 = load i32*, i32** %7
%45 = load i32*, i32** %11
%46 = load i32*, i32** %12
%47 = call i32 (i8*, i8*, i32*, ...) @gmp_sscanf(i8* %41, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32* %42, i32* %43, i32* %44, i32* %45, i32* %46)
%48 = load i32*, i32** %10
%49 = call i32 @mpz_clear(i32* %48)
%50 = load i32*, i32** %11
%51 = call i32 @mpz_clear(i32* %50)
%52 = load i32*, i32** %12
%53 = call i32 @mpz_clear(i32* %52)
%54 = load i8*, i8** %3
%55 = call i32 @strlen(i8* %54)
%56 = mul nsw i32 %55, 4
%57 = load i32, i32* %5
%58 = sdiv i32 %56, %57
%59 = add nsw i32 %58, 1
%60 = load i32, i32* %5
%61 = mul nsw i32 %59, %60
%62 = sext i32 %61 to i64
store i64 %62, i64* %13
%63 = load i32*, i32** %9
%64 = load i64, i64* %13
%65 = call i32 @mpz_init2(i32* %63, i64 %64)
%66 = load i32*, i32** %8
%67 = load i64, i64* %13
%68 = call i32 @mpz_init2(i32* %66, i64 %67)
%69 = load i8*, i8** %3
%70 = load i32*, i32** %9
%71 = call i32 (i8*, i8*, i32*, ...) @gmp_sscanf(i8* %69, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %70)
%72 = load i32*, i32** %6
%73 = load i32*, i32** %7
%74 = load i32*, i32** %9
%75 = load i32*, i32** %8
%76 = load i64, i64* %13
%77 = call i32 @crypt(i32* %72, i32* %73, i32* %74, i32* %75, i64 %76)
store i32 %77, i32* %14
%78 = load i32, i32* %14
%79 = load i32, i32* %5
%80 = mul nsw i32 %78, %79
%81 = sdiv i32 %80, 8
%82 = add nsw i32 %81, 1
%83 = sext i32 %82 to i64
%84 = mul i64 1, %83
%85 = trunc i64 %84 to i32
%86 = call i64 @malloc(i32 %85)
%87 = inttoptr i64 %86 to i8*
store i8* %87, i8** %15
%88 = load i8*, i8** %15
%89 = load i32*, i32** %8
%90 = call i32 @mpz_export(i8* %88, i64* %16, i32 1, i32 1, i32 0, i32 0, i32* %89)
%91 = load i8*, i8** %15
%92 = load i64, i64* %16
%93 = getelementptr inbounds i8, i8* %91, i64 %92
store i8 0, i8* %93
%94 = load i32*, i32** %6
%95 = call i32 @mpz_clear(i32* %94)
%96 = load i32*, i32** %7
%97 = call i32 @mpz_clear(i32* %96)
%98 = load i32*, i32** %8
%99 = call i32 @mpz_clear(i32* %98)
%100 = load i32*, i32** %9
%101 = call i32 @mpz_clear(i32* %100)
%102 = load i8*, i8** %15
ret i8* %102
}

LLVM IR (-O2):
@.str = [32 x i8] c"-----RSA Private Key-----\0Al: %d\00"
@.str.1 = [82 x i8] c"-----RSA Private Key-----\0Al: %d\0An: %Zx\0Ae: %Zx\0Ad: %Zx\0Ap: %Zx\0Aq: %Zx\0A-----End-----\0A\00"
@.str.2 = [4 x i8] c"%Zx\00"
define i8* @decrypt_pri(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = bitcast i32* %3 to i8*
%6 = call i32 (i8*, i8*, i32*, ...) @gmp_sscanf(i8* %1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = call i32 @mpz_init2(i32* undef, i64 %8)
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = call i32 @mpz_init2(i32* undef, i64 %11)
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = call i32 @mpz_init2(i32* undef, i64 %14)
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 2
%18 = sext i32 %17 to i64
%19 = call i32 @mpz_init2(i32* undef, i64 %18)
%20 = load i32, i32* %3
%21 = sdiv i32 %20, 2
%22 = sext i32 %21 to i64
%23 = call i32 @mpz_init2(i32* undef, i64 %22)
%24 = call i32 (i8*, i8*, i32*, ...) @gmp_sscanf(i8* %1, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* undef, i32* undef, i32* undef, i32* undef, i32* undef)
%25 = call i32 @mpz_clear(i32* undef)
%26 = call i32 @mpz_clear(i32* undef)
%27 = call i32 @mpz_clear(i32* undef)
%28 = call i32 @strlen(i8* %0)
%29 = shl nsw i32 %28, 2
%30 = load i32, i32* %3
%31 = sdiv i32 %29, %30
%32 = add nsw i32 %31, 1
%33 = mul nsw i32 %32, %30
%34 = sext i32 %33 to i64
%35 = call i32 @mpz_init2(i32* undef, i64 %34)
%36 = call i32 @mpz_init2(i32* undef, i64 %34)
%37 = call i32 (i8*, i8*, i32*, ...) @gmp_sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* undef)
%38 = call i32 @crypt(i32* undef, i32* undef, i32* undef, i32* undef, i64 %34)
%39 = load i32, i32* %3
%40 = mul nsw i32 %39, %38
%41 = sdiv i32 %40, 8
%42 = add nsw i32 %41, 1
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to i8*
%45 = bitcast i64* %4 to i8*
%46 = call i32 @mpz_export(i8* %44, i64* %4, i32 1, i32 1, i32 0, i32 0, i32* undef)
%47 = load i64, i64* %4
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 0, i8* %48
%49 = call i32 @mpz_clear(i32* undef)
%50 = call i32 @mpz_clear(i32* undef)
%51 = call i32 @mpz_clear(i32* undef)
%52 = call i32 @mpz_clear(i32* undef)
ret i8* %44
}