#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 candp(int, int, int);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
void main() {
  int p, q, e, d, m, n, r, c, t;
  char s;
  printf("please input the p,q:");
  scanf("%d%d", &p, &q);
  n = p * q;
  printf("the n is %3d\n", n);
  t = (p - 1) * (q - 1);
  printf("the t is %3d\n", t);
  printf("please input the e:");
  scanf("%d", &e);
  if (e < 1 || e > t) {
    printf("e is error,please input again:");
    scanf("%d", &e);
  }
  d = 1;
  while (((e * d) % t) != 1)
    d++;
  printf("then caculate out that the d is %d\n", d);
  printf("the cipher please input 1\n");
  printf("the plain please input 2\n");
  scanf("%d", &r);
  switch (r) {
  case 1:
    printf("input the m:");
    scanf("%d", &m);
    c = candp(m, e, n);
    printf("the cipher is %d\n", c);
    break;
  case 2:
    printf("input the c:");
    scanf("%d", &c);
    m = candp(c, d, n);
    printf("the cipher is %d\n", m);
  }
  getch();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe59(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x1,-0xc(%rbp)
jl     11e0 <main+0xa0>
mov    -0xc(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    1200 <main+0xc0>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe23(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cltd
idivl  -0x24(%rbp)
cmp    $0x1,%edx
je     1229 <main+0xe9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1207 <main+0xc7>
mov    -0x10(%rbp),%esi
lea    0xe37(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x2d(%rbp)
call   1030 <printf@plt>
mov    -0x2d(%rbp),%al
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2d(%rbp),%al
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2d(%rbp),%al
lea    0xdb3(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x1,%eax
je     1293 <main+0x153>
jmp    1282 <main+0x142>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     12da <main+0x19a>
jmp    131c <main+0x1dc>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd70(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <candp@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131c <main+0x1dc>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd29(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <candp@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <getch@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea9(%rip),%rdi
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x14(%rsp),%r14d
imul   0x18(%rsp),%r14d
lea    0xe8b(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%eax
add    $0xffffffff,%eax
mov    0x14(%rsp),%ebp
add    $0xffffffff,%ebp
imul   %eax,%ebp
lea    0xe77(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe48(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x8(%rsp),%esi
test   %esi,%esi
jle    11e8 <main+0x98>
cmp    %ebp,%esi
jle    120d <main+0xbd>
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe1b(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x8(%rsp),%esi
xor    %ebx,%ebx
mov    %esi,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%eax
cltd
idiv   %ebp
add    $0x1,%ebx
add    %esi,%ecx
cmp    $0x1,%edx
jne    1220 <main+0xd0>
lea    0xe34(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
lea    0xdba(%rip),%rdi
lea    0x1c(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x1c(%rsp),%eax
cmp    $0x2,%eax
je     12af <main+0x15f>
cmp    $0x1,%eax
jne    12f2 <main+0x1a2>
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd8b(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x10(%rsp),%edi
mov    0x8(%rsp),%esi
mov    %r14d,%edx
call   1050 <candp@plt>
mov    %eax,0xc(%rsp)
jmp    12e2 <main+0x192>
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd54(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%edi
mov    %ebx,%esi
mov    %r14d,%edx
call   1050 <candp@plt>
mov    %eax,0x10(%rsp)
lea    0xdb2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <getch@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"please input the p,q:\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [14 x i8] c"the n is %3d\0A\00"
@.str.3 = [14 x i8] c"the t is %3d\0A\00"
@.str.4 = [20 x i8] c"please input the e:\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [31 x i8] c"e is error,please input again:\00"
@.str.7 = [36 x i8] c"then caculate out that the d is %d\0A\00"
@.str.8 = [27 x i8] c"the cipher please input 1\0A\00"
@.str.9 = [26 x i8] c"the plain please input 2\0A\00"
@.str.10 = [13 x i8] c"input the m:\00"
@.str.11 = [18 x i8] c"the cipher is %d\0A\00"
@.str.12 = [13 x i8] c"input the c:\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = mul nsw i32 %13, %14
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %1
%19 = sub nsw i32 %18, 1
%20 = load i32, i32* %2
%21 = sub nsw i32 %20, 1
%22 = mul nsw i32 %19, %21
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 1
br i1 %28, label %33, label %29
29: ; preds = %0
%30 = load i32, i32* %3
%31 = load i32, i32* %9
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %29, %0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%35 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
br label %36
36: ; preds = %33, %29
store i32 1, i32* %4
br label %37
37: ; preds = %44, %36
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = mul nsw i32 %38, %39
%41 = load i32, i32* %9
%42 = srem i32 %40, %41
%43 = icmp ne i32 %42, 1
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
br label %37
47: ; preds = %37
%48 = load i32, i32* %4
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
%52 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %7)
%53 = load i32, i32* %7
switch i32 %53, label %72 [
i32 1, label %54
i32 2, label %63
]
54: ; preds = %47
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%56 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %5)
%57 = load i32, i32* %5
%58 = load i32, i32* %3
%59 = load i32, i32* %6
%60 = call i32 @candp(i32 %57, i32 %58, i32 %59)
store i32 %60, i32* %8
%61 = load i32, i32* %8
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %61)
br label %72
63: ; preds = %47
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
%65 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %8)
%66 = load i32, i32* %8
%67 = load i32, i32* %4
%68 = load i32, i32* %6
%69 = call i32 @candp(i32 %66, i32 %67, i32 %68)
store i32 %69, i32* %5
%70 = load i32, i32* %5
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %63, %47, %54
%73 = call i32 (...) @getch()
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"please input the p,q:\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [14 x i8] c"the n is %3d\0A\00"
@.str.3 = [14 x i8] c"the t is %3d\0A\00"
@.str.4 = [20 x i8] c"please input the e:\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [31 x i8] c"e is error,please input again:\00"
@.str.7 = [36 x i8] c"then caculate out that the d is %d\0A\00"
@.str.10 = [13 x i8] c"input the m:\00"
@.str.11 = [18 x i8] c"the cipher is %d\0A\00"
@.str.12 = [13 x i8] c"input the c:\00"
@str = [26 x i8] c"the cipher please input 1\00"
@str.13 = [25 x i8] c"the plain please input 2\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = mul nsw i32 %16, %15
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %1
%20 = add nsw i32 %19, -1
%21 = load i32, i32* %2
%22 = add nsw i32 %21, -1
%23 = mul nsw i32 %22, %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 1
%29 = icmp sgt i32 %27, %23
%30 = or i1 %28, %29
br i1 %30, label %31, label %35
31: ; preds = %0
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%34 = load i32, i32* %3
br label %35
35: ; preds = %0, %31
%36 = phi i32 [ %27, %0 ], [ %34, %31 ]
br label %37
37: ; preds = %37, %35
%38 = phi i32 [ 1, %35 ], [ %42, %37 ]
%39 = mul nsw i32 %36, %38
%40 = srem i32 %39, %23
%41 = icmp eq i32 %40, 1
%42 = add nuw nsw i32 %38, 1
br i1 %41, label %43, label %37
43: ; preds = %37
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i32 %38)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.13, i64 0, i64 0))
%47 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %5)
%48 = load i32, i32* %5
switch i32 %48, label %63 [
i32 1, label %49
i32 2, label %55
]
49: ; preds = %43
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%51 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %4)
%52 = load i32, i32* %4
%53 = load i32, i32* %3
%54 = call i32 @candp(i32 %52, i32 %53, i32 %17)
store i32 %54, i32* %6
br label %60
55: ; preds = %43
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
%57 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %6)
%58 = load i32, i32* %6
%59 = call i32 @candp(i32 %58, i32 %38, i32 %17)
store i32 %59, i32* %4
br label %60
60: ; preds = %49, %55
%61 = phi i32 [ %59, %55 ], [ %54, %49 ]
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %60, %43
%64 = call i32 (...) @getch()
ret void
}