#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_clears(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ mpz_cmp_si(int /*<<< orphan*/, int);
scalar_t__ mpz_even_p(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpz_init_set_si(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_neg(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpz_tdiv_q(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/);
void mpz_power(mpz_t rop, const mpz_t base, const mpz_t exp) {
  mpz_t x, y, n, one, two;
  mpz_init_set(x, base);
  mpz_init_set_si(y, 1);
  mpz_init_set(n, exp);
  mpz_init_set_si(one, 1);
  mpz_init_set_si(two, 2);
  if (mpz_cmp_si(n, 0) < 0) {
    mpz_tdiv_q(x, one, x);
    mpz_neg(n, n);
  }
  while (mpz_cmp_si(n, 1) > 0) {
    if (mpz_even_p(n)) {
      mpz_mul(x, x, x);
      mpz_tdiv_q(n, n, two);
    } else {
      mpz_mul(y, x, y);
      mpz_mul(x, x, x);
      mpz_sub(n, n, one);
      mpz_tdiv_q(n, n, two);
    }
  }
  mpz_mul(rop, x, y);
  mpz_clears(x, y, n, one, two, NULL);
}


x86 assembly (clang, -O0):
<mpz_power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10a0 <mpz_init_set@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   10b0 <mpz_init_set_si@plt>
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
call   10a0 <mpz_init_set@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   10b0 <mpz_init_set_si@plt>
mov    -0x20(%rbp),%edi
mov    $0x2,%esi
call   10b0 <mpz_init_set_si@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1080 <mpz_cmp_si@plt>
cmp    $0x0,%rax
jge    120b <mpz_power+0x7b>
mov    -0x10(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1090 <mpz_tdiv_q@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <mpz_neg@plt>
jmp    1210 <mpz_power+0x80>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1080 <mpz_cmp_si@plt>
cmp    $0x0,%rax
jle    1297 <mpz_power+0x107>
mov    -0x18(%rbp),%edi
call   1070 <mpz_even_p@plt>
cmp    $0x0,%rax
je     125a <mpz_power+0xca>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <mpz_mul@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1090 <mpz_tdiv_q@plt>
jmp    1292 <mpz_power+0x102>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1060 <mpz_mul@plt>
mov    -0x10(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <mpz_mul@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <mpz_sub@plt>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1090 <mpz_tdiv_q@plt>
jmp    1210 <mpz_power+0x80>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1060 <mpz_mul@plt>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%r9d
call   1050 <mpz_clears@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpz_power>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %edi,%ebx
call   10a0 <mpz_init_set@plt>
mov    $0x1,%esi
call   10b0 <mpz_init_set_si@plt>
mov    %ebp,%esi
call   10a0 <mpz_init_set@plt>
mov    $0x1,%esi
call   10b0 <mpz_init_set_si@plt>
mov    $0x2,%esi
call   10b0 <mpz_init_set_si@plt>
xor    %esi,%esi
call   1080 <mpz_cmp_si@plt>
test   %rax,%rax
jns    11e5 <mpz_power+0x55>
call   1090 <mpz_tdiv_q@plt>
call   1040 <mpz_neg@plt>
jmp    11e5 <mpz_power+0x55>
nopl   0x0(%rax)
call   1090 <mpz_tdiv_q@plt>
mov    $0x1,%esi
call   1080 <mpz_cmp_si@plt>
test   %rax,%rax
jle    1212 <mpz_power+0x82>
call   1070 <mpz_even_p@plt>
mov    %rax,%rbp
call   1060 <mpz_mul@plt>
test   %rbp,%rbp
jne    11e0 <mpz_power+0x50>
call   1060 <mpz_mul@plt>
call   1030 <mpz_sub@plt>
jmp    11e0 <mpz_power+0x50>
mov    %ebx,%edi
call   1060 <mpz_mul@plt>
xor    %r9d,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <mpz_clears@plt>

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

LLVM IR (-O2):
define void @mpz_power(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mpz_init_set(i32 undef, i32 %1)
%5 = tail call i32 @mpz_init_set_si(i32 undef, i32 1)
%6 = tail call i32 @mpz_init_set(i32 undef, i32 %2)
%7 = tail call i32 @mpz_init_set_si(i32 undef, i32 1)
%8 = tail call i32 @mpz_init_set_si(i32 undef, i32 2)
%9 = tail call i64 @mpz_cmp_si(i32 undef, i32 0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = tail call i32 @mpz_tdiv_q(i32 undef, i32 undef, i32 undef)
%13 = tail call i32 @mpz_neg(i32 undef, i32 undef)
br label %14
14: ; preds = %11, %3
%15 = tail call i64 @mpz_cmp_si(i32 undef, i32 1)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %14, %24
%18 = tail call i64 @mpz_even_p(i32 undef)
%19 = icmp eq i64 %18, 0
%20 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
br i1 %19, label %21, label %24
21: ; preds = %17
%22 = tail call i32 @mpz_mul(i32 undef, i32 undef, i32 undef)
%23 = tail call i32 @mpz_sub(i32 undef, i32 undef, i32 undef)
br label %24
24: ; preds = %17, %21
%25 = tail call i32 @mpz_tdiv_q(i32 undef, i32 undef, i32 undef)
%26 = tail call i64 @mpz_cmp_si(i32 undef, i32 1)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %17, label %28
28: ; preds = %24, %14
%29 = tail call i32 @mpz_mul(i32 %0, i32 undef, i32 undef)
%30 = tail call i32 @mpz_clears(i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32* null)
ret void
}