#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 */
unsigned long modexp(unsigned long, unsigned long, unsigned long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main() {
  unsigned long p, q, e, d, n, phi, i, C, M;
  int len;
  char data[100];
  system(" clear ");
  printf(" Enter the value of P and Q (such that p * q > 255, say 31 and 37 "
         "and p not equal to q) \n ");
  scanf("%lu%lu", &p, &q);
  n = p * q;
  phi = (p - 1) * (q - 1);
  printf(" phi(n) is %lu ", phi);
  for (i = 1; i < phi; i++) {
    if ((phi % i) == 0)
      continue;
    else
      break;
  }
  e = i;
  printf(" \n Encryption key is : %lu ", e);
  for (i = 1; i < phi; i++)
    if (((e * i - 1) % phi) == 0)
      break;
  d = i;
  printf(" \n decryption key is : %lu ", d);
  printf(" \n pls enter the message : ");
  scanf("%s", data);
  len = strlen(data);
  for (i = 0; i < len; i++) {
    M = (unsigned long)data[i];
    C = modexp(M, e, n);
    printf(" \n encrypted value and its char representation: %lu \t %c \n ", C,
           (char)C);
    M = modexp(C, d, n);
    printf(" \n decrypted value and its char representation: %lu \t %c \n ", M,
           (char)M);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
call   1040 <system@plt>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xee0(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
imul   %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    1210 <main+0xc0>
mov    -0x38(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x40(%rbp)
cmp    $0x0,%rdx
jne    11fa <main+0xaa>
jmp    11ff <main+0xaf>
jmp    1210 <main+0xc0>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11d1 <main+0x81>
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    127a <main+0x12a>
mov    -0x20(%rbp),%rax
imul   -0x40(%rbp),%rax
sub    $0x1,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x38(%rbp)
cmp    $0x0,%rdx
jne    1264 <main+0x114>
jmp    127a <main+0x12a>
jmp    1269 <main+0x119>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1232 <main+0xe2>
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0xc0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x54(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x54(%rbp),%rcx
cmp    %rcx,%rax
jae    135d <main+0x20d>
mov    -0x40(%rbp),%rax
movsbq -0xc0(%rbp,%rax,1),%rax
ff ff
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <modexp@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
mov    -0x48(%rbp),%rax
movsbl %al,%edx
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <modexp@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
mov    -0x50(%rbp),%rax
movsbl %al,%edx
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12ce <main+0x17e>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xe9b(%rip),%rdi
call   1040 <system@plt>
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee4(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x8(%rsp),%rbp
mov    (%rsp),%r14
lea    -0x1(%rbp),%rax
lea    -0x1(%r14),%r12
imul   %rax,%r12
lea    0xec0(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%r12
jb     126d <main+0x11d>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     11f0 <main+0xa0>
mov    %r12,%rax
xor    %edx,%edx
div    %rbx
test   %rdx,%rdx
je     11fc <main+0xac>
jmp    1208 <main+0xb8>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%eax
xor    %edx,%edx
div    %ebx
test   %rdx,%rdx
jne    1208 <main+0xb8>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11d0 <main+0x80>
mov    %r12,%rbx
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r15d
cmp    $0x2,%r12
jb     128b <main+0x13b>
lea    -0x1(%rbx),%rcx
mov    $0x1,%r15d
nop
mov    %rcx,%rax
or     %r12,%rax
shr    $0x20,%rax
je     1250 <main+0x100>
mov    %rcx,%rax
xor    %edx,%edx
div    %r12
test   %rdx,%rdx
jne    125c <main+0x10c>
jmp    128b <main+0x13b>
nopl   0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %r12d
test   %rdx,%rdx
je     128b <main+0x13b>
add    $0x1,%r15
add    %rbx,%rcx
cmp    %r15,%r12
jne    1230 <main+0xe0>
mov    %r12,%r15
jmp    128b <main+0x13b>
lea    0xe06(%rip),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r15d
lea    0xe04(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1d(%rip),%rdi
lea    0x10(%rsp),%r12
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1334 <main+0x1e4>
imul   %rbp,%r14
movslq %eax,%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
movsbq 0x10(%rsp,%r13,1),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <modexp@plt>
mov    %rax,%rbp
movsbl %bpl,%edx
lea    0xdd2(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <modexp@plt>
movsbl %al,%edx
lea    0xdec(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r13
cmp    %r13,%r12
jne    12e0 <main+0x190>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c" clear \00"
@.str.1 = [91 x i8] c" Enter the value of P and Q (such that p * q > 255, say 31 and 37 and p not equal to q) \0A \00"
@.str.2 = [7 x i8] c"%lu%lu\00"
@.str.3 = [16 x i8] c" phi(n) is %lu \00"
@.str.4 = [28 x i8] c" \0A Encryption key is : %lu \00"
@.str.5 = [28 x i8] c" \0A decryption key is : %lu \00"
@.str.6 = [28 x i8] c" \0A pls enter the message : \00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [60 x i8] c" \0A encrypted value and its char representation: %lu \09 %c \0A \00"
@.str.9 = [60 x i8] c" \0A decrypted value and its char representation: %lu \09 %c \0A \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca [100 x i8]
store i32 0, i32* %1
%13 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64* %2, i64* %3)
%16 = load i64, i64* %2
%17 = load i64, i64* %3
%18 = mul i64 %16, %17
store i64 %18, i64* %6
%19 = load i64, i64* %2
%20 = sub i64 %19, 1
%21 = load i64, i64* %3
%22 = sub i64 %21, 1
%23 = mul i64 %20, %22
store i64 %23, i64* %7
%24 = load i64, i64* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %24)
store i64 1, i64* %8
br label %26
26: ; preds = %37, %0
%27 = load i64, i64* %8
%28 = load i64, i64* %7
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = load i64, i64* %7
%32 = load i64, i64* %8
%33 = urem i64 %31, %32
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
br label %37
36: ; preds = %30
br label %40
37: ; preds = %35
%38 = load i64, i64* %8
%39 = add i64 %38, 1
store i64 %39, i64* %8
br label %26
40: ; preds = %36, %26
%41 = load i64, i64* %8
store i64 %41, i64* %4
%42 = load i64, i64* %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 %42)
store i64 1, i64* %8
br label %44
44: ; preds = %58, %40
%45 = load i64, i64* %8
%46 = load i64, i64* %7
%47 = icmp ult i64 %45, %46
br i1 %47, label %48, label %61
48: ; preds = %44
%49 = load i64, i64* %4
%50 = load i64, i64* %8
%51 = mul i64 %49, %50
%52 = sub i64 %51, 1
%53 = load i64, i64* %7
%54 = urem i64 %52, %53
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %48
br label %61
57: ; preds = %48
br label %58
58: ; preds = %57
%59 = load i64, i64* %8
%60 = add i64 %59, 1
store i64 %60, i64* %8
br label %44
61: ; preds = %56, %44
%62 = load i64, i64* %8
store i64 %62, i64* %5
%63 = load i64, i64* %5
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i64 %63)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%67 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %66)
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
store i32 %69, i32* %11
store i64 0, i64* %8
br label %70
70: ; preds = %98, %61
%71 = load i64, i64* %8
%72 = load i32, i32* %11
%73 = sext i32 %72 to i64
%74 = icmp ult i64 %71, %73
br i1 %74, label %75, label %101
75: ; preds = %70
%76 = load i64, i64* %8
%77 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = sext i8 %78 to i64
store i64 %79, i64* %10
%80 = load i64, i64* %10
%81 = load i64, i64* %4
%82 = load i64, i64* %6
%83 = call i64 @modexp(i64 %80, i64 %81, i64 %82)
store i64 %83, i64* %9
%84 = load i64, i64* %9
%85 = load i64, i64* %9
%86 = trunc i64 %85 to i8
%87 = sext i8 %86 to i32
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0), i64 %84, i32 %87)
%89 = load i64, i64* %9
%90 = load i64, i64* %5
%91 = load i64, i64* %6
%92 = call i64 @modexp(i64 %89, i64 %90, i64 %91)
store i64 %92, i64* %10
%93 = load i64, i64* %10
%94 = load i64, i64* %10
%95 = trunc i64 %94 to i8
%96 = sext i8 %95 to i32
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.9, i64 0, i64 0), i64 %93, i32 %96)
br label %98
98: ; preds = %75
%99 = load i64, i64* %8
%100 = add i64 %99, 1
store i64 %100, i64* %8
br label %70
101: ; preds = %70
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c" clear \00"
@.str.1 = [91 x i8] c" Enter the value of P and Q (such that p * q > 255, say 31 and 37 and p not equal to q) \0A \00"
@.str.2 = [7 x i8] c"%lu%lu\00"
@.str.3 = [16 x i8] c" phi(n) is %lu \00"
@.str.4 = [28 x i8] c" \0A Encryption key is : %lu \00"
@.str.5 = [28 x i8] c" \0A decryption key is : %lu \00"
@.str.6 = [28 x i8] c" \0A pls enter the message : \00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [60 x i8] c" \0A encrypted value and its char representation: %lu \09 %c \0A \00"
@.str.9 = [60 x i8] c" \0A decrypted value and its char representation: %lu \09 %c \0A \00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca [100 x i8]
%4 = bitcast i64* %1 to i8*
%5 = bitcast i64* %2 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64* %1, i64* %2)
%10 = load i64, i64* %1
%11 = load i64, i64* %2
%12 = mul i64 %11, %10
%13 = add i64 %10, -1
%14 = add i64 %11, -1
%15 = mul i64 %14, %13
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %15)
%17 = icmp ugt i64 %15, 1
br i1 %17, label %20, label %18
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 1)
br label %39
20: ; preds = %0, %24
%21 = phi i64 [ %25, %24 ], [ 1, %0 ]
%22 = urem i64 %15, %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = add nuw i64 %21, 1
%26 = icmp eq i64 %25, %15
br i1 %26, label %27, label %20
27: ; preds = %24, %20
%28 = phi i64 [ %15, %24 ], [ %21, %20 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 %28)
br i1 %17, label %30, label %39
30: ; preds = %27, %36
%31 = phi i64 [ %37, %36 ], [ 1, %27 ]
%32 = mul i64 %31, %28
%33 = add i64 %32, -1
%34 = urem i64 %33, %15
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %30
%37 = add nuw i64 %31, 1
%38 = icmp eq i64 %37, %15
br i1 %38, label %39, label %30
39: ; preds = %36, %30, %18, %27
%40 = phi i64 [ %28, %27 ], [ 1, %18 ], [ %28, %30 ], [ %28, %36 ]
%41 = phi i64 [ 1, %27 ], [ 1, %18 ], [ %15, %36 ], [ %31, %30 ]
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i64 %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%44 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %6)
%45 = call i32 @strlen(i8* %6)
%46 = icmp eq i32 %45, 0
br i1 %46, label %66, label %47
47: ; preds = %39
%48 = sext i32 %45 to i64
br label %49
49: ; preds = %47, %49
%50 = phi i64 [ %64, %49 ], [ 0, %47 ]
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i64
%54 = call i64 @modexp(i64 %53, i64 %40, i64 %12)
%55 = trunc i64 %54 to i32
%56 = shl i32 %55, 24
%57 = ashr exact i32 %56, 24
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0), i64 %54, i32 %57)
%59 = call i64 @modexp(i64 %54, i64 %41, i64 %12)
%60 = trunc i64 %59 to i32
%61 = shl i32 %60, 24
%62 = ashr exact i32 %61, 24
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.9, i64 0, i64 0), i64 %59, i32 %62)
%64 = add nuw i64 %50, 1
%65 = icmp eq i64 %64, %48
br i1 %65, label %66, label %49
66: ; preds = %49, %39
ret i32 0
}