#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 */

/* Variables and functions */
int Congru_Mod(int, int, int);
int Divide_Remainder(int);
int Montgomery(int, int, int);
int Quick_Index_Mod(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  printf("求 A^B mod M\n");
  printf("A = %d, B = %d, M = %d\n", 9, 29, 264);
  printf("二分指数取余：%d^%d mod %d = %d\n", 9, 29, 264, Divide_Remainder(29));
  printf("同余公式取模：%d^%d mod %d = %d\n", 9, 29, 264,
         Congru_Mod(9, 29, 264));
  printf("快速指数取模：%d^%d mod %d = %d\n", 9, 29, 264,
         Quick_Index_Mod(9, 29, 264));
  printf("反复平方法：  %d^%d mod %d = %d\n", 9, 29, 264,
         Montgomery(9, 29, 264));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1d,%edi
call   1050 <Divide_Remainder@plt>
mov    %eax,%r8d
lea    0xe94(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x9,%edi
mov    $0x1d,%esi
mov    $0x108,%edx
call   1070 <Congru_Mod@plt>
mov    %eax,%r8d
lea    0xe88(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x9,%edi
mov    $0x1d,%esi
mov    $0x108,%edx
call   1060 <Quick_Index_Mod@plt>
mov    %eax,%r8d
lea    0xe7c(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x9,%edi
mov    $0x1d,%esi
mov    $0x108,%edx
call   1030 <Montgomery@plt>
mov    %eax,%r8d
lea    0xe70(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf4f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8c(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1d,%edi
call   1060 <Divide_Remainder@plt>
lea    0xe7d(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x9,%edi
mov    $0x1d,%esi
mov    $0x108,%edx
call   1080 <Congru_Mod@plt>
lea    0xe71(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x9,%edi
mov    $0x1d,%esi
mov    $0x108,%edx
call   1070 <Quick_Index_Mod@plt>
lea    0xe65(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x9,%edi
mov    $0x1d,%esi
mov    $0x108,%edx
call   1030 <Montgomery@plt>
lea    0xe59(%rip),%rdi
mov    $0x9,%esi
mov    $0x1d,%edx
mov    $0x108,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"\E6\B1\82 A^B mod M\0A\00"
@.str.1 = [24 x i8] c"A = %d, B = %d, M = %d\0A\00"
@.str.2 = [40 x i8] c"\E4\BA\8C\E5\88\86\E6\8C\87\E6\95\B0\E5\8F\96\E4\BD\99\EF\BC\9A%d^%d mod %d = %d\0A\00"
@.str.3 = [40 x i8] c"\E5\90\8C\E4\BD\99\E5\85\AC\E5\BC\8F\E5\8F\96\E6\A8\A1\EF\BC\9A%d^%d mod %d = %d\0A\00"
@.str.4 = [40 x i8] c"\E5\BF\AB\E9\80\9F\E6\8C\87\E6\95\B0\E5\8F\96\E6\A8\A1\EF\BC\9A%d^%d mod %d = %d\0A\00"
@.str.5 = [39 x i8] c"\E5\8F\8D\E5\A4\8D\E5\B9\B3\E6\96\B9\E6\B3\95\EF\BC\9A %d^%d mod %d = %d\0A\00"
define i32 @main() {
%1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 9, i32 29, i32 264)
%3 = call i32 @Divide_Remainder(i32 29)
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 9, i32 29, i32 264, i32 %3)
%5 = call i32 @Congru_Mod(i32 9, i32 29, i32 264)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 9, i32 29, i32 264, i32 %5)
%7 = call i32 @Quick_Index_Mod(i32 9, i32 29, i32 264)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 9, i32 29, i32 264, i32 %7)
%9 = call i32 @Montgomery(i32 9, i32 29, i32 264)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 9, i32 29, i32 264, i32 %9)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"A = %d, B = %d, M = %d\0A\00"
@.str.2 = [40 x i8] c"\E4\BA\8C\E5\88\86\E6\8C\87\E6\95\B0\E5\8F\96\E4\BD\99\EF\BC\9A%d^%d mod %d = %d\0A\00"
@.str.3 = [40 x i8] c"\E5\90\8C\E4\BD\99\E5\85\AC\E5\BC\8F\E5\8F\96\E6\A8\A1\EF\BC\9A%d^%d mod %d = %d\0A\00"
@.str.4 = [40 x i8] c"\E5\BF\AB\E9\80\9F\E6\8C\87\E6\95\B0\E5\8F\96\E6\A8\A1\EF\BC\9A%d^%d mod %d = %d\0A\00"
@.str.5 = [39 x i8] c"\E5\8F\8D\E5\A4\8D\E5\B9\B3\E6\96\B9\E6\B3\95\EF\BC\9A %d^%d mod %d = %d\0A\00"
@str = [14 x i8] c"\E6\B1\82 A^B mod M\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 9, i32 29, i32 264)
%3 = tail call i32 @Divide_Remainder(i32 29)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 9, i32 29, i32 264, i32 %3)
%5 = tail call i32 @Congru_Mod(i32 9, i32 29, i32 264)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 9, i32 29, i32 264, i32 %5)
%7 = tail call i32 @Quick_Index_Mod(i32 9, i32 29, i32 264)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 9, i32 29, i32 264, i32 %7)
%9 = tail call i32 @Montgomery(i32 9, i32 29, i32 264)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32 9, i32 29, i32 264, i32 %9)
ret i32 0
}