#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 */
struct rusage {
  int /*<<< orphan*/ ru_maxrss;
};
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ gmp_printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_pow_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  mpz_t r, b;
  unsigned int e;
  struct rusage ru;
  if (argc != 3) {
    fputs("Usage: powmp 'base' 'expoent'\n", stderr);
    return 1;
  }
  getrusage(RUSAGE_SELF, &ru);
  printf("Before: %ld KiB used.\n", ru.ru_maxrss);
  mpz_init_set_ui(r, 1);
  mpz_init_set_str(b, argv[1], 10);
  getrusage(RUSAGE_SELF, &ru);
  printf("Init: %ld KiB used.\n", ru.ru_maxrss);
  e = strtoul(argv[2], NULL, 10);
  mpz_pow_ui(r, b, e);
  getrusage(RUSAGE_SELF, &ru);
  printf("After pow: %ld KiB used.\n", ru.ru_maxrss);
  mpz_clear(b);
  gmp_printf("%Zd\n", r);
  mpz_clear(r);
  getrusage(RUSAGE_SELF, &ru);
  printf("After cleanup: %ld KiB used.\n", ru.ru_maxrss);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d1 <main+0x41>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0xe40(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c4 <main+0x134>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1090 <getrusage@plt>
mov    -0x20(%rbp),%esi
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1060 <mpz_init_set_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0xa,%edx
call   1040 <mpz_init_set_str@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1090 <getrusage@plt>
mov    -0x20(%rbp),%esi
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <mpz_pow_ui@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1090 <getrusage@plt>
mov    -0x20(%rbp),%esi
lea    0xdd3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    -0x14(%rbp),%esi
lea    0xdd6(%rip),%rdi
call   10b0 <gmp_printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <mpz_clear@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1090 <getrusage@plt>
mov    -0x20(%rbp),%esi
lea    0xdb2(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    1266 <main+0xd6>
mov    %rsi,%rbx
mov    0x2e2c(%rip),%r15
mov    (%r15),%edi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1090 <getrusage@plt>
mov    0x8(%rsp),%esi
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%esi
call   1060 <mpz_init_set_ui@plt>
mov    0x8(%rbx),%rsi
mov    $0xa,%edx
call   1040 <mpz_init_set_str@plt>
mov    (%r15),%edi
mov    %r14,%rsi
call   1090 <getrusage@plt>
mov    0x8(%rsp),%esi
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
mov    0x10(%rbx),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <strtoul@plt>
mov    %eax,%edx
call   1070 <mpz_pow_ui@plt>
mov    (%r15),%edi
mov    %r14,%rsi
call   1090 <getrusage@plt>
mov    0x8(%rsp),%esi
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
call   1080 <mpz_clear@plt>
lea    0xe26(%rip),%rdi
call   10b0 <gmp_printf@plt>
call   1080 <mpz_clear@plt>
mov    (%r15),%edi
mov    %r14,%rsi
call   1090 <getrusage@plt>
mov    0x8(%rsp),%esi
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
jmp    1280 <main+0xf0>
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
lea    0xd8a(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rusage = type { i32 }
@.str = [31 x i8] c"Usage: powmp 'base' 'expoent'\0A\00"
@stderr = global i32 0
@RUSAGE_SELF = global i32 0
@.str.1 = [23 x i8] c"Before: %ld KiB used.\0A\00"
@.str.2 = [21 x i8] c"Init: %ld KiB used.\0A\00"
@.str.3 = [26 x i8] c"After pow: %ld KiB used.\0A\00"
@.str.4 = [5 x i8] c"%Zd\0A\00"
@.str.5 = [30 x i8] c"After cleanup: %ld KiB used.\0A\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 %struct.rusage
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 1, i32* %3
br label %57
15: ; preds = %2
%16 = load i32, i32* @RUSAGE_SELF
%17 = call i32 @getrusage(i32 %16, %struct.rusage* %9)
%18 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %6
%22 = call i32 @mpz_init_set_ui(i32 %21, i32 1)
%23 = load i32, i32* %7
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @mpz_init_set_str(i32 %23, i8* %26, i32 10)
%28 = load i32, i32* @RUSAGE_SELF
%29 = call i32 @getrusage(i32 %28, %struct.rusage* %9)
%30 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @strtoul(i8* %35, i32* null, i32 10)
store i32 %36, i32* %8
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = call i32 @mpz_pow_ui(i32 %37, i32 %38, i32 %39)
%41 = load i32, i32* @RUSAGE_SELF
%42 = call i32 @getrusage(i32 %41, %struct.rusage* %9)
%43 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %7
%47 = call i32 @mpz_clear(i32 %46)
%48 = load i32, i32* %6
%49 = call i32 @gmp_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %6
%51 = call i32 @mpz_clear(i32 %50)
%52 = load i32, i32* @RUSAGE_SELF
%53 = call i32 @getrusage(i32 %52, %struct.rusage* %9)
%54 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %55)
store i32 0, i32* %3
br label %57
57: ; preds = %15, %12
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.rusage = type { i32 }
@.str = [31 x i8] c"Usage: powmp 'base' 'expoent'\0A\00"
@stderr = global i32 0
@RUSAGE_SELF = global i32 0
@.str.1 = [23 x i8] c"Before: %ld KiB used.\0A\00"
@.str.2 = [21 x i8] c"Init: %ld KiB used.\0A\00"
@.str.3 = [26 x i8] c"After pow: %ld KiB used.\0A\00"
@.str.4 = [5 x i8] c"%Zd\0A\00"
@.str.5 = [30 x i8] c"After cleanup: %ld KiB used.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.rusage
%4 = bitcast %struct.rusage* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %38
9: ; preds = %2
%10 = load i32, i32* @RUSAGE_SELF
%11 = call i32 @getrusage(i32 %10, %struct.rusage* %3)
%12 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @mpz_init_set_ui(i32 undef, i32 1)
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @mpz_init_set_str(i32 undef, i8* %17, i32 10)
%19 = load i32, i32* @RUSAGE_SELF
%20 = call i32 @getrusage(i32 %19, %struct.rusage* %3)
%21 = load i32, i32* %12
%22 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @strtoul(i8* nocapture %24, i32* null, i32 10)
%26 = call i32 @mpz_pow_ui(i32 undef, i32 undef, i32 %25)
%27 = load i32, i32* @RUSAGE_SELF
%28 = call i32 @getrusage(i32 %27, %struct.rusage* %3)
%29 = load i32, i32* %12
%30 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = call i32 @mpz_clear(i32 undef)
%32 = call i32 @gmp_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 undef)
%33 = call i32 @mpz_clear(i32 undef)
%34 = load i32, i32* @RUSAGE_SELF
%35 = call i32 @getrusage(i32 %34, %struct.rusage* %3)
%36 = load i32, i32* %12
%37 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %9, %6
%39 = phi i32 [ 1, %6 ], [ 0, %9 ]
ret i32 %39
}