#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 */
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mpz_get_ui(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int mpz_sizeinbase(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_tdiv_qr_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                                  int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_ui_pow_ui(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ printf(char *, size_t);
int main(void) {
  mpz_t r, q;
  mpz_init(r);
  mpz_init(q);
  size_t maxsum = 0;
  int a, b;
  for (a = 99; a > 0; --a) {
    for (b = 99; b > 0; --b) {
      mpz_ui_pow_ui(r, a, b);
      if (mpz_sizeinbase(r, 10) * 9 < maxsum)
        continue;
      size_t digsum = 0;
      while (mpz_cmp_ui(r, 0)) {
        mpz_tdiv_qr_ui(r, q, r, 10);
        digsum += mpz_get_ui(q);
      }
      if (digsum > maxsum)
        maxsum = digsum;
    }
  }
  printf("%zu\n", maxsum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <mpz_init@plt>
mov    -0xc(%rbp),%edi
call   1040 <mpz_init@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x63,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1268 <main+0xf8>
movl   $0x63,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1255 <main+0xe5>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1090 <mpz_ui_pow_ui@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1060 <mpz_sizeinbase@plt>
imul   $0x9,%eax,%eax
cltq
cmp    -0x18(%rbp),%rax
jae    11e8 <main+0x78>
jmp    1247 <main+0xd7>
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1080 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
je     122c <main+0xbc>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    $0xa,%ecx
call   1050 <mpz_tdiv_qr_ui@plt>
mov    -0xc(%rbp),%edi
call   1070 <mpz_get_ui@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11f0 <main+0x80>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1242 <main+0xd2>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1247 <main+0xd7>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    11af <main+0x3f>
jmp    125a <main+0xea>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    119e <main+0x2e>
mov    -0x18(%rbp),%rsi
lea    0xd8d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
call   1040 <mpz_init@plt>
call   1040 <mpz_init@plt>
mov    $0x63,%r14d
xor    %r15d,%r15d
jmp    11a1 <main+0x31>
nopl   (%rax)
lea    -0x1(%r14),%eax
cmp    $0x1,%r14d
mov    %eax,%r14d
jbe    1220 <main+0xb0>
mov    $0x63,%r12d
jmp    11c5 <main+0x55>
nopl   0x0(%rax)
cmp    %r15,%rbx
cmova  %rbx,%r15
lea    -0x1(%r12),%eax
cmp    $0x1,%r12d
mov    %eax,%r12d
jbe    1190 <main+0x20>
mov    %r14d,%esi
mov    %r12d,%edx
call   1090 <mpz_ui_pow_ui@plt>
mov    $0xa,%esi
call   1060 <mpz_sizeinbase@plt>
lea    (%rax,%rax,8),%eax
cltq
cmp    %rax,%r15
ja     11b7 <main+0x47>
xor    %esi,%esi
call   1080 <mpz_cmp_ui@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11b0 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0xa,%ecx
call   1050 <mpz_tdiv_qr_ui@plt>
call   1070 <mpz_get_ui@plt>
add    %rax,%rbx
xor    %esi,%esi
call   1080 <mpz_cmp_ui@plt>
test   %rax,%rax
jne    1200 <main+0x90>
jmp    11b0 <main+0x40>
lea    0xdd9(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%zu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %1
%8 = load i32, i32* %2
%9 = call i32 @mpz_init(i32 %8)
%10 = load i32, i32* %3
%11 = call i32 @mpz_init(i32 %10)
store i64 0, i64* %4
store i32 99, i32* %5
br label %12
12: ; preds = %56, %0
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %59
15: ; preds = %12
store i32 99, i32* %6
br label %16
16: ; preds = %52, %15
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %55
19: ; preds = %16
%20 = load i32, i32* %2
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = call i32 @mpz_ui_pow_ui(i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %2
%25 = call i32 @mpz_sizeinbase(i32 %24, i32 10)
%26 = mul nsw i32 %25, 9
%27 = sext i32 %26 to i64
%28 = load i64, i64* %4
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %19
br label %52
31: ; preds = %19
store i64 0, i64* %7
br label %32
32: ; preds = %36, %31
%33 = load i32, i32* %2
%34 = call i64 @mpz_cmp_ui(i32 %33, i32 0)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i32, i32* %2
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = call i32 @mpz_tdiv_qr_ui(i32 %37, i32 %38, i32 %39, i32 10)
%41 = load i32, i32* %3
%42 = call i64 @mpz_get_ui(i32 %41)
%43 = load i64, i64* %7
%44 = add i64 %43, %42
store i64 %44, i64* %7
br label %32
45: ; preds = %32
%46 = load i64, i64* %7
%47 = load i64, i64* %4
%48 = icmp ugt i64 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = load i64, i64* %7
store i64 %50, i64* %4
br label %51
51: ; preds = %49, %45
br label %52
52: ; preds = %51, %30
%53 = load i32, i32* %6
%54 = add nsw i32 %53, -1
store i32 %54, i32* %6
br label %16
55: ; preds = %16
br label %56
56: ; preds = %55
%57 = load i32, i32* %5
%58 = add nsw i32 %57, -1
store i32 %58, i32* %5
br label %12
59: ; preds = %12
%60 = load i64, i64* %4
%61 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%zu\0A\00"
define i32 @main() {
%1 = tail call i32 @mpz_init(i32 undef)
%2 = tail call i32 @mpz_init(i32 undef)
br label %3
3: ; preds = %0, %32
%4 = phi i32 [ 99, %0 ], [ %33, %32 ]
%5 = phi i64 [ 0, %0 ], [ %29, %32 ]
br label %6
6: ; preds = %3, %28
%7 = phi i32 [ 99, %3 ], [ %30, %28 ]
%8 = phi i64 [ %5, %3 ], [ %29, %28 ]
%9 = tail call i32 @mpz_ui_pow_ui(i32 undef, i32 %4, i32 %7)
%10 = tail call i32 @mpz_sizeinbase(i32 undef, i32 10)
%11 = mul nsw i32 %10, 9
%12 = sext i32 %11 to i64
%13 = icmp ugt i64 %8, %12
br i1 %13, label %28, label %14
14: ; preds = %6
%15 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %14, %17
%18 = phi i64 [ %21, %17 ], [ 0, %14 ]
%19 = tail call i32 @mpz_tdiv_qr_ui(i32 undef, i32 undef, i32 undef, i32 10)
%20 = tail call i64 @mpz_get_ui(i32 undef)
%21 = add i64 %20, %18
%22 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %17
24: ; preds = %17, %14
%25 = phi i64 [ 0, %14 ], [ %21, %17 ]
%26 = icmp ugt i64 %25, %8
%27 = select i1 %26, i64 %25, i64 %8
br label %28
28: ; preds = %6, %24
%29 = phi i64 [ %8, %6 ], [ %27, %24 ]
%30 = add nsw i32 %7, -1
%31 = icmp ugt i32 %7, 1
br i1 %31, label %6, label %32
32: ; preds = %28
%33 = add nsw i32 %4, -1
%34 = icmp ugt i32 %4, 1
br i1 %34, label %3, label %35
35: ; preds = %32
%36 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %29)
ret i32 0
}