#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 egcd(int, int);
int fmod(int, int);
int pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int m, p, q, phi, e, d, temp, n, c, message;
  printf("Enter numeric text message : ");
  scanf("%d", &m);
  p = 5;
  q = 7;
  n = p * q;
  phi = (p - 1) * (q - 1);
  e = 2;
  while (e < phi) {
    if (egcd(e, phi) == 1)
      break;
    e++;
  }
  d = 2;
  while (d < phi) {
    temp = fmod(((e * d) - 1), phi);
    if (temp == 0)
      break;
    d++;
  }
  c = fmod(pow(m, e), n);
  printf("Cipher = %d\n", c);
  message = fmod(pow(c, d), n);
  printf("Message = %d\n", message);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x5,-0xc(%rbp)
movl   $0x7,-0x10(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e1 <main+0x91>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
jne    11d3 <main+0x83>
jmp    11e1 <main+0x91>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ae <main+0x5e>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1226 <main+0xd6>
mov    -0x18(%rbp),%edi
imul   -0x1c(%rbp),%edi
sub    $0x1,%edi
mov    -0x14(%rbp),%esi
call   1040 <fmod@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1218 <main+0xc8>
jmp    1226 <main+0xd6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e8 <main+0x98>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <pow@plt>
mov    %eax,%edi
mov    -0x24(%rbp),%esi
call   1040 <fmod@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <pow@plt>
mov    %eax,%edi
mov    -0x24(%rbp),%esi
call   1040 <fmod@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    $0x2,%ebx
mov    $0x2,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
mov    $0x2,%r14d
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x3,%r14d
mov    $0x3,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x4,%r14d
mov    $0x4,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x5,%r14d
mov    $0x5,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x6,%r14d
mov    $0x6,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x7,%r14d
mov    $0x7,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x8,%r14d
mov    $0x8,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x9,%r14d
mov    $0x9,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0xa,%r14d
mov    $0xa,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0xb,%r14d
mov    $0xb,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0xc,%r14d
mov    $0xc,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0xd,%r14d
mov    $0xd,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0xe,%r14d
mov    $0xe,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0xf,%r14d
mov    $0xf,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x10,%r14d
mov    $0x10,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x11,%r14d
mov    $0x11,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x12,%r14d
mov    $0x12,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x13,%r14d
mov    $0x13,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x14,%r14d
mov    $0x14,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x15,%r14d
mov    $0x15,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x16,%r14d
mov    $0x18,%ebp
mov    $0x16,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
cmp    $0x1,%eax
je     1403 <main+0x2b3>
mov    $0x17,%edi
mov    $0x18,%esi
call   1070 <egcd@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
sub    %ecx,%ebp
mov    %ebp,%r14d
lea    (%r14,%r14,1),%ebp
add    $0xffffffff,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    $0x18,%esi
call   1040 <fmod@plt>
test   %eax,%eax
je     1430 <main+0x2e0>
add    $0x1,%ebx
add    %r14d,%ebp
cmp    $0x18,%ebx
jne    1410 <main+0x2c0>
mov    $0x18,%ebx
mov    0xc(%rsp),%edi
mov    %r14d,%esi
call   1060 <pow@plt>
mov    %eax,%edi
mov    $0x23,%esi
call   1040 <fmod@plt>
mov    %eax,%ebp
lea    0xbd0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <pow@plt>
mov    %eax,%edi
mov    $0x23,%esi
call   1040 <fmod@plt>
lea    0xbb8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Enter numeric text message : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Cipher = %d\0A\00"
@.str.3 = [14 x i8] c"Message = %d\0A\00"
define i32 @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 i32
%11 = alloca i32
store i32 0, i32* %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 5, i32* %3
store i32 7, i32* %4
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = mul nsw i32 %14, %15
store i32 %16, i32* %9
%17 = load i32, i32* %3
%18 = sub nsw i32 %17, 1
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = mul nsw i32 %18, %20
store i32 %21, i32* %5
store i32 2, i32* %6
br label %22
22: ; preds = %32, %0
%23 = load i32, i32* %6
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load i32, i32* %6
%28 = load i32, i32* %5
%29 = call i32 @egcd(i32 %27, i32 %28)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %32
31: ; preds = %26
br label %35
32: ; preds = %26
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %22
35: ; preds = %31, %22
store i32 2, i32* %7
br label %36
36: ; preds = %50, %35
%37 = load i32, i32* %7
%38 = load i32, i32* %5
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %53
40: ; preds = %36
%41 = load i32, i32* %6
%42 = load i32, i32* %7
%43 = mul nsw i32 %41, %42
%44 = sub nsw i32 %43, 1
%45 = load i32, i32* %5
%46 = call i32 @fmod(i32 %44, i32 %45)
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %40
br label %53
50: ; preds = %40
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %36
53: ; preds = %49, %36
%54 = load i32, i32* %2
%55 = load i32, i32* %6
%56 = call i32 @pow(i32 %54, i32 %55)
%57 = load i32, i32* %9
%58 = call i32 @fmod(i32 %56, i32 %57)
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %10
%62 = load i32, i32* %7
%63 = call i32 @pow(i32 %61, i32 %62)
%64 = load i32, i32* %9
%65 = call i32 @fmod(i32 %63, i32 %64)
store i32 %65, i32* %11
%66 = load i32, i32* %11
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %66)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Enter numeric text message : \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Cipher = %d\0A\00"
@.str.3 = [14 x i8] c"Message = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = call i32 @egcd(i32 2, i32 24)
%6 = icmp eq i32 %5, 1
br i1 %6, label %71, label %7
7: ; preds = %0
%8 = call i32 @egcd(i32 3, i32 24)
%9 = icmp eq i32 %8, 1
br i1 %9, label %71, label %10
10: ; preds = %7
%11 = call i32 @egcd(i32 4, i32 24)
%12 = icmp eq i32 %11, 1
br i1 %12, label %71, label %13
13: ; preds = %10
%14 = call i32 @egcd(i32 5, i32 24)
%15 = icmp eq i32 %14, 1
br i1 %15, label %71, label %16
16: ; preds = %13
%17 = call i32 @egcd(i32 6, i32 24)
%18 = icmp eq i32 %17, 1
br i1 %18, label %71, label %19
19: ; preds = %16
%20 = call i32 @egcd(i32 7, i32 24)
%21 = icmp eq i32 %20, 1
br i1 %21, label %71, label %22
22: ; preds = %19
%23 = call i32 @egcd(i32 8, i32 24)
%24 = icmp eq i32 %23, 1
br i1 %24, label %71, label %25
25: ; preds = %22
%26 = call i32 @egcd(i32 9, i32 24)
%27 = icmp eq i32 %26, 1
br i1 %27, label %71, label %28
28: ; preds = %25
%29 = call i32 @egcd(i32 10, i32 24)
%30 = icmp eq i32 %29, 1
br i1 %30, label %71, label %31
31: ; preds = %28
%32 = call i32 @egcd(i32 11, i32 24)
%33 = icmp eq i32 %32, 1
br i1 %33, label %71, label %34
34: ; preds = %31
%35 = call i32 @egcd(i32 12, i32 24)
%36 = icmp eq i32 %35, 1
br i1 %36, label %71, label %37
37: ; preds = %34
%38 = call i32 @egcd(i32 13, i32 24)
%39 = icmp eq i32 %38, 1
br i1 %39, label %71, label %40
40: ; preds = %37
%41 = call i32 @egcd(i32 14, i32 24)
%42 = icmp eq i32 %41, 1
br i1 %42, label %71, label %43
43: ; preds = %40
%44 = call i32 @egcd(i32 15, i32 24)
%45 = icmp eq i32 %44, 1
br i1 %45, label %71, label %46
46: ; preds = %43
%47 = call i32 @egcd(i32 16, i32 24)
%48 = icmp eq i32 %47, 1
br i1 %48, label %71, label %49
49: ; preds = %46
%50 = call i32 @egcd(i32 17, i32 24)
%51 = icmp eq i32 %50, 1
br i1 %51, label %71, label %52
52: ; preds = %49
%53 = call i32 @egcd(i32 18, i32 24)
%54 = icmp eq i32 %53, 1
br i1 %54, label %71, label %55
55: ; preds = %52
%56 = call i32 @egcd(i32 19, i32 24)
%57 = icmp eq i32 %56, 1
br i1 %57, label %71, label %58
58: ; preds = %55
%59 = call i32 @egcd(i32 20, i32 24)
%60 = icmp eq i32 %59, 1
br i1 %60, label %71, label %61
61: ; preds = %58
%62 = call i32 @egcd(i32 21, i32 24)
%63 = icmp eq i32 %62, 1
br i1 %63, label %71, label %64
64: ; preds = %61
%65 = call i32 @egcd(i32 22, i32 24)
%66 = icmp eq i32 %65, 1
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = call i32 @egcd(i32 23, i32 24)
%69 = icmp eq i32 %68, 1
%70 = select i1 %69, i32 23, i32 24
br label %71
71: ; preds = %67, %64, %61, %58, %55, %52, %49, %46, %43, %40, %37, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %0
%72 = phi i32 [ 2, %0 ], [ 3, %7 ], [ 4, %10 ], [ 5, %13 ], [ 6, %16 ], [ 7, %19 ], [ 8, %22 ], [ 9, %25 ], [ 10, %28 ], [ 11, %31 ], [ 12, %34 ], [ 13, %37 ], [ 14, %40 ], [ 15, %43 ], [ 16, %46 ], [ 17, %49 ], [ 18, %52 ], [ 19, %55 ], [ 20, %58 ], [ 21, %61 ], [ 22, %64 ], [ %70, %67 ]
br label %73
73: ; preds = %71, %79
%74 = phi i32 [ 2, %71 ], [ %80, %79 ]
%75 = mul nuw nsw i32 %74, %72
%76 = add nsw i32 %75, -1
%77 = call i32 @fmod(i32 %76, i32 24)
%78 = icmp eq i32 %77, 0
br i1 %78, label %82, label %79
79: ; preds = %73
%80 = add nuw nsw i32 %74, 1
%81 = icmp eq i32 %80, 24
br i1 %81, label %82, label %73
82: ; preds = %73, %79
%83 = phi i32 [ %74, %73 ], [ 24, %79 ]
%84 = load i32, i32* %1
%85 = call i32 @pow(i32 %84, i32 %72)
%86 = call i32 @fmod(i32 %85, i32 35)
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %86)
%88 = call i32 @pow(i32 %86, i32 %83)
%89 = call i32 @fmod(i32 %88, i32 35)
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %89)
ret i32 0
}