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

/* Variables and functions */
int /*<<< orphan*/ getPrime(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_export(void *, unsigned long *, int, int, int,
                              int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_import(int /*<<< orphan*/, unsigned long, int, int, int,
                              int /*<<< orphan*/, void *);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_powm_sec(int /*<<< orphan*/, int /*<<< orphan*/ const,
                                int /*<<< orphan*/, int /*<<< orphan*/);
void getPowm(unsigned char *res, unsigned long *reslen, const mpz_t base,
             const unsigned char *chexp, unsigned long len) {
  mpz_t prime;
  mpz_t exp;
  mpz_t ans;
  mpz_init(ans);
  mpz_init(exp);
  mpz_init(prime);
  getPrime(prime, 128, 233);
  mpz_import(exp, len, -1, 1, 1, 0, (void *)chexp);
  mpz_powm_sec(ans, base, exp, prime);
  mpz_export((void *)res, reslen, -1, 1, 1, 0, ans);
  mpz_clear(prime);
  mpz_clear(ans);
  mpz_clear(exp);
}


x86 assembly (clang, -O0):
<getPowm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x30(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x2c(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0x2c(%rbp),%edi
mov    $0x80,%esi
mov    $0xe9,%edx
call   1030 <getPrime@plt>
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    $0xffffffff,%edx
mov    $0x1,%r8d
xor    %r9d,%r9d
mov    %r8d,%ecx
mov    %rax,(%rsp)
call   1070 <mpz_import@plt>
mov    -0x34(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1080 <mpz_powm_sec@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%eax
mov    $0xffffffff,%edx
mov    $0x1,%r8d
xor    %r9d,%r9d
mov    %r8d,%ecx
mov    %eax,(%rsp)
call   1050 <mpz_export@plt>
mov    -0x2c(%rbp),%edi
call   1060 <mpz_clear@plt>
mov    -0x34(%rbp),%edi
call   1060 <mpz_clear@plt>
mov    -0x30(%rbp),%edi
call   1060 <mpz_clear@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPowm>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%rbx
mov    %rcx,%rbp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <mpz_init@plt>
call   1040 <mpz_init@plt>
call   1040 <mpz_init@plt>
mov    $0x80,%esi
mov    $0xe9,%edx
call   1030 <getPrime@plt>
mov    %rbp,(%rsp)
mov    %rbx,%rsi
mov    $0xffffffff,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
xor    %r9d,%r9d
call   1070 <mpz_import@plt>
mov    %r12d,%esi
call   1080 <mpz_powm_sec@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xffffffff,%edx
mov    $0x1,%ecx
mov    $0x1,%r8d
xor    %r9d,%r9d
call   1050 <mpz_export@plt>
call   1060 <mpz_clear@plt>
call   1060 <mpz_clear@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <mpz_clear@plt>

LLVM IR (-O0):
define void @getPowm(i8* %0, i64* %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i64* %1, i64** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%14 = load i32, i32* %13
%15 = call i32 @mpz_init(i32 %14)
%16 = load i32, i32* %12
%17 = call i32 @mpz_init(i32 %16)
%18 = load i32, i32* %11
%19 = call i32 @mpz_init(i32 %18)
%20 = load i32, i32* %11
%21 = call i32 @getPrime(i32 %20, i32 128, i32 233)
%22 = load i32, i32* %12
%23 = load i64, i64* %10
%24 = load i8*, i8** %9
%25 = call i32 @mpz_import(i32 %22, i64 %23, i32 -1, i32 1, i32 1, i32 0, i8* %24)
%26 = load i32, i32* %13
%27 = load i32, i32* %8
%28 = load i32, i32* %12
%29 = load i32, i32* %11
%30 = call i32 @mpz_powm_sec(i32 %26, i32 %27, i32 %28, i32 %29)
%31 = load i8*, i8** %6
%32 = load i64*, i64** %7
%33 = load i32, i32* %13
%34 = call i32 @mpz_export(i8* %31, i64* %32, i32 -1, i32 1, i32 1, i32 0, i32 %33)
%35 = load i32, i32* %11
%36 = call i32 @mpz_clear(i32 %35)
%37 = load i32, i32* %13
%38 = call i32 @mpz_clear(i32 %37)
%39 = load i32, i32* %12
%40 = call i32 @mpz_clear(i32 %39)
ret void
}

LLVM IR (-O2):
define void @getPowm(i8* %0, i64* %1, i32 %2, i8* %3, i64 %4) {
%6 = tail call i32 @mpz_init(i32 undef)
%7 = tail call i32 @mpz_init(i32 undef)
%8 = tail call i32 @mpz_init(i32 undef)
%9 = tail call i32 @getPrime(i32 undef, i32 128, i32 233)
%10 = tail call i32 @mpz_import(i32 undef, i64 %4, i32 -1, i32 1, i32 1, i32 0, i8* %3)
%11 = tail call i32 @mpz_powm_sec(i32 undef, i32 %2, i32 undef, i32 undef)
%12 = tail call i32 @mpz_export(i8* %0, i64* %1, i32 -1, i32 1, i32 1, i32 0, i32 undef)
%13 = tail call i32 @mpz_clear(i32 undef)
%14 = tail call i32 @mpz_clear(i32 undef)
%15 = tail call i32 @mpz_clear(i32 undef)
ret void
}