#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 char mul(unsigned char, unsigned char);
int /*<<< orphan*/ printf(char *);
int encryption(unsigned char *pk, unsigned char *plaintext,
               unsigned char *ciphertext, int plaintextlen) {
  int i, j, k, ij = 0, eof = 0;
  unsigned char temp, x[64];
  if (plaintextlen != 64)
    return (0);
  printf("************************************************* \n");
  printf("Start ABC encryption \n");
  printf("************************************************* \n");
  for (k = 0; k < 64; k++)
    x[k] = (unsigned char)plaintext[k];
  for (k = 0; k < 128; k++) {
    temp = 0;
    for (i = 0; i < 64; i++) {
      for (j = i; j < 64; j++) {
        temp = temp ^ mul((unsigned char)pk[ij++], mul(x[i], x[j]));
      }
    }
    ciphertext[k] = temp;
  }
  return (1);
}


x86 assembly (clang, -O0):
<encryption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x40,-0x24(%rbp)
je     115e <encryption+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    1290 <encryption+0x170>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x30(%rbp)
cmpl   $0x40,-0x30(%rbp)
jge    11b4 <encryption+0x94>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x30(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1189 <encryption+0x69>
movl   $0x0,-0x30(%rbp)
cmpl   $0x80,-0x30(%rbp)
jge    1289 <encryption+0x169>
movb   $0x0,-0x39(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x40,-0x28(%rbp)
jge    126d <encryption+0x14d>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x40,-0x2c(%rbp)
jge    125a <encryption+0x13a>
movzbl -0x39(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x34(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x85(%rbp)
movslq -0x28(%rbp),%rax
mov    -0x80(%rbp,%rax,1),%cl
movslq -0x2c(%rbp),%rax
movzbl %cl,%edi
movzbl -0x80(%rbp,%rax,1),%esi
call   1040 <mul@plt>
mov    -0x85(%rbp),%cl
movzbl %cl,%edi
movzbl %al,%esi
call   1040 <mul@plt>
mov    %al,%cl
mov    -0x84(%rbp),%eax
movzbl %cl,%ecx
xor    %ecx,%eax
mov    %al,-0x39(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e3 <encryption+0xc3>
jmp    125f <encryption+0x13f>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d3 <encryption+0xb3>
mov    -0x39(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11bb <encryption+0x9b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encryption>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,0x8(%rsp)
xor    %eax,%eax
cmp    $0x40,%ecx
jne    1254 <encryption+0x134>
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xecb(%rip),%rbp
mov    %rbp,%rdi
call   1030 <puts@plt>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
movups (%rbx),%xmm0
movups 0x10(%rbx),%xmm1
movups 0x20(%rbx),%xmm2
movups 0x30(%rbx),%xmm3
movaps %xmm0,0x20(%rsp)
movaps %xmm1,0x30(%rsp)
movaps %xmm2,0x40(%rsp)
movaps %xmm3,0x50(%rsp)
xor    %eax,%eax
xor    %r14d,%r14d
jmp    11c0 <encryption+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rcx
mov    %bl,(%rax,%rcx,1)
mov    %rcx,%rax
add    $0x1,%rax
cmp    $0x80,%rax
je     124f <encryption+0x12f>
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    11df <encryption+0xbf>
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rbp
add    $0x1,%rbp
cmp    $0x40,%rbp
je     11a0 <encryption+0x80>
mov    %ebx,%r13d
movslq %r14d,%r14
movzbl (%r15,%r14,1),%ebx
add    $0x1,%r14
movzbl 0x20(%rsp,%rbp,1),%r12d
mov    %r12d,%edi
mov    %r12d,%esi
call   1040 <mul@plt>
movzbl %al,%esi
mov    %ebx,%edi
call   1040 <mul@plt>
mov    %eax,%ebx
xor    %r13b,%bl
mov    %rbp,0x18(%rsp)
lea    0x1(%rbp),%r13
cmp    $0x40,%r13
je     11d0 <encryption+0xb0>
nopl   (%rax)
movzbl 0x20(%rsp,%r13,1),%esi
movzbl (%r15,%r14,1),%ebp
add    $0x1,%r14
mov    %r12d,%edi
call   1040 <mul@plt>
movzbl %al,%esi
mov    %ebp,%edi
call   1040 <mul@plt>
xor    %al,%bl
add    $0x1,%r13
cmp    $0x40,%r13
jne    1220 <encryption+0x100>
jmp    11d0 <encryption+0xb0>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"************************************************* \0A\00"
@.str.1 = [23 x i8] c"Start ABC encryption \0A\00"
define i32 @encryption(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8
%16 = alloca [64 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %13
store i32 0, i32* %14
%17 = load i32, i32* %9
%18 = icmp ne i32 %17, 64
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 0, i32* %5
br label %91
20: ; preds = %4
%21 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %12
br label %24
24: ; preds = %36, %20
%25 = load i32, i32* %12
%26 = icmp slt i32 %25, 64
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = load i8*, i8** %7
%29 = load i32, i32* %12
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %16, i64 0, i64 %34
store i8 %32, i8* %35
br label %36
36: ; preds = %27
%37 = load i32, i32* %12
%38 = add nsw i32 %37, 1
store i32 %38, i32* %12
br label %24
39: ; preds = %24
store i32 0, i32* %12
br label %40
40: ; preds = %87, %39
%41 = load i32, i32* %12
%42 = icmp slt i32 %41, 128
br i1 %42, label %43, label %90
43: ; preds = %40
store i8 0, i8* %15
store i32 0, i32* %10
br label %44
44: ; preds = %78, %43
%45 = load i32, i32* %10
%46 = icmp slt i32 %45, 64
br i1 %46, label %47, label %81
47: ; preds = %44
%48 = load i32, i32* %10
store i32 %48, i32* %11
br label %49
49: ; preds = %74, %47
%50 = load i32, i32* %11
%51 = icmp slt i32 %50, 64
br i1 %51, label %52, label %77
52: ; preds = %49
%53 = load i8, i8* %15
%54 = zext i8 %53 to i32
%55 = load i8*, i8** %6
%56 = load i32, i32* %13
%57 = add nsw i32 %56, 1
store i32 %57, i32* %13
%58 = sext i32 %56 to i64
%59 = getelementptr inbounds i8, i8* %55, i64 %58
%60 = load i8, i8* %59
%61 = load i32, i32* %10
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %16, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = load i32, i32* %11
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [64 x i8], [64 x i8]* %16, i64 0, i64 %66
%68 = load i8, i8* %67
%69 = call zeroext i8 @mul(i8 zeroext %64, i8 zeroext %68)
%70 = call zeroext i8 @mul(i8 zeroext %60, i8 zeroext %69)
%71 = zext i8 %70 to i32
%72 = xor i32 %54, %71
%73 = trunc i32 %72 to i8
store i8 %73, i8* %15
br label %74
74: ; preds = %52
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
br label %49
77: ; preds = %49
br label %78
78: ; preds = %77
%79 = load i32, i32* %10
%80 = add nsw i32 %79, 1
store i32 %80, i32* %10
br label %44
81: ; preds = %44
%82 = load i8, i8* %15
%83 = load i8*, i8** %8
%84 = load i32, i32* %12
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
store i8 %82, i8* %86
br label %87
87: ; preds = %81
%88 = load i32, i32* %12
%89 = add nsw i32 %88, 1
store i32 %89, i32* %12
br label %40
90: ; preds = %40
store i32 1, i32* %5
br label %91
91: ; preds = %90, %19
%92 = load i32, i32* %5
ret i32 %92
}

LLVM IR (-O2):
@str.2 = [22 x i8] c"Start ABC encryption \00"
@str.3 = [51 x i8] c"************************************************* \00"
define i32 @encryption(i8* nocapture %0, i8* nocapture %1, i8* nocapture writeonly %2, i32 %3) {
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32 %3, 64
br i1 %7, label %8, label %55
8: ; preds = %4
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.3, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.2, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.3, i64 0, i64 0))
br label %13
13: ; preds = %8, %51
%14 = phi i64 [ 0, %8 ], [ %53, %51 ]
%15 = phi i64 [ 0, %8 ], [ %47, %51 ]
br label %16
16: ; preds = %46, %13
%17 = phi i64 [ 0, %13 ], [ %49, %46 ]
%18 = phi i8 [ 0, %13 ], [ %48, %46 ]
%19 = phi i64 [ %15, %13 ], [ %47, %46 ]
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %17
%21 = load i8, i8* %20
%22 = shl i64 %19, 32
%23 = ashr exact i64 %22, 32
%24 = add nsw i64 %23, 1
%25 = getelementptr inbounds i8, i8* %0, i64 %23
%26 = load i8, i8* %25
%27 = tail call zeroext i8 @mul(i8 zeroext %21, i8 zeroext %21)
%28 = tail call zeroext i8 @mul(i8 zeroext %26, i8 zeroext %27)
%29 = xor i8 %28, %18
%30 = add nuw nsw i64 %17, 1
%31 = icmp eq i64 %30, 64
br i1 %31, label %46, label %32
32: ; preds = %16, %32
%33 = phi i64 [ %44, %32 ], [ %30, %16 ]
%34 = phi i8 [ %43, %32 ], [ %29, %16 ]
%35 = phi i64 [ %38, %32 ], [ %24, %16 ]
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %33
%37 = load i8, i8* %36
%38 = add nsw i64 %35, 1
%39 = getelementptr inbounds i8, i8* %0, i64 %35
%40 = load i8, i8* %39
%41 = tail call zeroext i8 @mul(i8 zeroext %21, i8 zeroext %37)
%42 = tail call zeroext i8 @mul(i8 zeroext %40, i8 zeroext %41)
%43 = xor i8 %42, %34
%44 = add nuw nsw i64 %33, 1
%45 = icmp eq i64 %44, 64
br i1 %45, label %46, label %32
46: ; preds = %32, %16
%47 = phi i64 [ %24, %16 ], [ %38, %32 ]
%48 = phi i8 [ %29, %16 ], [ %43, %32 ]
%49 = add nuw nsw i64 %17, 1
%50 = icmp eq i64 %49, 64
br i1 %50, label %51, label %16
51: ; preds = %46
%52 = getelementptr inbounds i8, i8* %2, i64 %14
store i8 %48, i8* %52
%53 = add nuw nsw i64 %14, 1
%54 = icmp eq i64 %53, 128
br i1 %54, label %55, label %13
55: ; preds = %51, %4
%56 = phi i32 [ 0, %4 ], [ 1, %51 ]
ret i32 %56
}