#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*/ mpz_addmul(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init2(int /*<<< orphan*/, size_t);
int /*<<< orphan*/ mpz_powm(int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_tdiv_qr(int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/);
int crypt(mpz_t n, mpz_t e, mpz_t message, mpz_t cipher, size_t length) {
  int i = 1;
  mpz_t t1, t2, t3, m;
  mpz_init2(t1, length);
  mpz_init2(t2, length);
  mpz_init2(t3, length);
  mpz_init2(m, length);
  mpz_set(m, message);
  while (mpz_cmp(m, n) > 0) {
    mpz_tdiv_qr(t1, t2, m, n);
    mpz_powm(t3, t2, e, n);
    mpz_addmul(t3, cipher, n);
    mpz_set(cipher, t3);
    mpz_set(m, t1);
    ++i;
  }
  mpz_powm(t3, m, e, n);
  mpz_addmul(t3, cipher, n);
  mpz_set(cipher, t3);
  mpz_clear(t1);
  mpz_clear(t2);
  mpz_clear(t3);
  return i;
}


x86 assembly (clang, -O0):
<crypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1090 <mpz_init2@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1090 <mpz_init2@plt>
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1090 <mpz_init2@plt>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1090 <mpz_init2@plt>
mov    -0x2c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x2c(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1070 <mpz_cmp@plt>
cmp    $0x0,%rax
jle    1233 <crypt+0xc3>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x4(%rbp),%ecx
call   1050 <mpz_tdiv_qr@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
call   1030 <mpz_powm@plt>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1060 <mpz_addmul@plt>
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <crypt+0x5a>
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
call   1030 <mpz_powm@plt>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1060 <mpz_addmul@plt>
mov    -0x10(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1040 <mpz_set@plt>
mov    -0x20(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x24(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x28(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%rbx
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%r14d
mov    %edi,%ebp
mov    %r8,%rsi
call   1090 <mpz_init2@plt>
mov    %rbx,%rsi
call   1090 <mpz_init2@plt>
mov    %rbx,%rsi
call   1090 <mpz_init2@plt>
mov    %rbx,%rsi
call   1090 <mpz_init2@plt>
mov    %r12d,%esi
call   1040 <mpz_set@plt>
mov    %ebp,%esi
call   1070 <mpz_cmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
jle    11f7 <crypt+0x87>
nop
mov    %ebp,%ecx
call   1050 <mpz_tdiv_qr@plt>
mov    %r14d,%edx
mov    %ebp,%ecx
call   1030 <mpz_powm@plt>
mov    %r15d,%esi
mov    %ebp,%edx
call   1060 <mpz_addmul@plt>
mov    %r15d,%edi
call   1040 <mpz_set@plt>
call   1040 <mpz_set@plt>
add    $0x1,%ebx
mov    %ebp,%esi
call   1070 <mpz_cmp@plt>
test   %rax,%rax
jg     11c0 <crypt+0x50>
mov    %r14d,%edx
mov    %ebp,%ecx
call   1030 <mpz_powm@plt>
mov    %r15d,%esi
mov    %ebp,%edx
call   1060 <mpz_addmul@plt>
mov    %r15d,%edi
call   1040 <mpz_set@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
call   1080 <mpz_clear@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @crypt(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i64 %4, i64* %10
store i32 1, i32* %11
%16 = load i32, i32* %12
%17 = load i64, i64* %10
%18 = call i32 @mpz_init2(i32 %16, i64 %17)
%19 = load i32, i32* %13
%20 = load i64, i64* %10
%21 = call i32 @mpz_init2(i32 %19, i64 %20)
%22 = load i32, i32* %14
%23 = load i64, i64* %10
%24 = call i32 @mpz_init2(i32 %22, i64 %23)
%25 = load i32, i32* %15
%26 = load i64, i64* %10
%27 = call i32 @mpz_init2(i32 %25, i64 %26)
%28 = load i32, i32* %15
%29 = load i32, i32* %8
%30 = call i32 @mpz_set(i32 %28, i32 %29)
br label %31
31: ; preds = %36, %5
%32 = load i32, i32* %15
%33 = load i32, i32* %6
%34 = call i64 @mpz_cmp(i32 %32, i32 %33)
%35 = icmp sgt i64 %34, 0
br i1 %35, label %36, label %59
36: ; preds = %31
%37 = load i32, i32* %12
%38 = load i32, i32* %13
%39 = load i32, i32* %15
%40 = load i32, i32* %6
%41 = call i32 @mpz_tdiv_qr(i32 %37, i32 %38, i32 %39, i32 %40)
%42 = load i32, i32* %14
%43 = load i32, i32* %13
%44 = load i32, i32* %7
%45 = load i32, i32* %6
%46 = call i32 @mpz_powm(i32 %42, i32 %43, i32 %44, i32 %45)
%47 = load i32, i32* %14
%48 = load i32, i32* %9
%49 = load i32, i32* %6
%50 = call i32 @mpz_addmul(i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %9
%52 = load i32, i32* %14
%53 = call i32 @mpz_set(i32 %51, i32 %52)
%54 = load i32, i32* %15
%55 = load i32, i32* %12
%56 = call i32 @mpz_set(i32 %54, i32 %55)
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %31
59: ; preds = %31
%60 = load i32, i32* %14
%61 = load i32, i32* %15
%62 = load i32, i32* %7
%63 = load i32, i32* %6
%64 = call i32 @mpz_powm(i32 %60, i32 %61, i32 %62, i32 %63)
%65 = load i32, i32* %14
%66 = load i32, i32* %9
%67 = load i32, i32* %6
%68 = call i32 @mpz_addmul(i32 %65, i32 %66, i32 %67)
%69 = load i32, i32* %9
%70 = load i32, i32* %14
%71 = call i32 @mpz_set(i32 %69, i32 %70)
%72 = load i32, i32* %12
%73 = call i32 @mpz_clear(i32 %72)
%74 = load i32, i32* %13
%75 = call i32 @mpz_clear(i32 %74)
%76 = load i32, i32* %14
%77 = call i32 @mpz_clear(i32 %76)
%78 = load i32, i32* %11
ret i32 %78
}

LLVM IR (-O2):
define i32 @crypt(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4) {
%6 = tail call i32 @mpz_init2(i32 undef, i64 %4)
%7 = tail call i32 @mpz_init2(i32 undef, i64 %4)
%8 = tail call i32 @mpz_init2(i32 undef, i64 %4)
%9 = tail call i32 @mpz_init2(i32 undef, i64 %4)
%10 = tail call i32 @mpz_set(i32 undef, i32 %2)
%11 = tail call i64 @mpz_cmp(i32 undef, i32 %0)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %5, %13
%14 = phi i32 [ %20, %13 ], [ 1, %5 ]
%15 = tail call i32 @mpz_tdiv_qr(i32 undef, i32 undef, i32 undef, i32 %0)
%16 = tail call i32 @mpz_powm(i32 undef, i32 undef, i32 %1, i32 %0)
%17 = tail call i32 @mpz_addmul(i32 undef, i32 %3, i32 %0)
%18 = tail call i32 @mpz_set(i32 %3, i32 undef)
%19 = tail call i32 @mpz_set(i32 undef, i32 undef)
%20 = add nuw nsw i32 %14, 1
%21 = tail call i64 @mpz_cmp(i32 undef, i32 %0)
%22 = icmp sgt i64 %21, 0
br i1 %22, label %13, label %23
23: ; preds = %13, %5
%24 = phi i32 [ 1, %5 ], [ %20, %13 ]
%25 = tail call i32 @mpz_powm(i32 undef, i32 undef, i32 %1, i32 %0)
%26 = tail call i32 @mpz_addmul(i32 undef, i32 %3, i32 %0)
%27 = tail call i32 @mpz_set(i32 %3, i32 undef)
%28 = tail call i32 @mpz_clear(i32 undef)
%29 = tail call i32 @mpz_clear(i32 undef)
%30 = tail call i32 @mpz_clear(i32 undef)
ret i32 %24
}