#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 short encryptDecrypt(unsigned short, unsigned short, unsigned short);
int /*<<< orphan*/ keygen(unsigned short, unsigned short *, unsigned short *);
int /*<<< orphan*/ printBin(unsigned short, int);
int /*<<< orphan*/ printf(char *, ...);
void test(unsigned short input, unsigned short expOutput, unsigned short key,
          char type) {
  unsigned short a, b, output;
  static int testNo = 0;
  static int testPassNo = 0;
  testNo++;
  printf("\nTEST %d ", testNo);
  if (type == 'e') {
    printf("ENCRYPTION:\t");
    keygen(key, &a, &b);
  } else {
    printf("DECRYPTION:\t");
    keygen(key, &b, &a);
  }
  output = encryptDecrypt(input, a, b);
  printf("\n----------\nGrade:\t\t\t");
  if (output == expOutput) {
    printf("\033[22;1;32mPASS\033[0m\n");
    testPassNo++;
  } else
    printf("\033[22;1;31mFAIL\033[0m\n");
  printf("Input:\t\t\t");
  printBin(input, 8);
  printf("\nKey:\t\t\t");
  printBin(key, 10);
  printf("\nExpected Output:\t");
  printBin(expOutput, 8);
  printf("\nActual Output:\t\t");
  printBin(output, 8);
  printf("\n---------\n\033[22;1;32m%d/%d passed\033[0m\n", testPassNo, testNo);
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %cl,%al
mov    %dx,%cx
mov    %si,%dx
mov    %di,%si
mov    %si,-0x2(%rbp)
mov    %dx,-0x4(%rbp)
mov    %cx,-0x6(%rbp)
mov    %al,-0x7(%rbp)
mov    0x2edc(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ed3(%rip)
mov    0x2ecd(%rip),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movsbl -0x7(%rbp),%eax
cmp    $0x65,%eax
jne    11b6 <test+0x76>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xa(%rbp),%rsi
lea    -0xc(%rbp),%rdx
movzwl -0x6(%rbp),%edi
call   1040 <keygen@plt>
jmp    11d5 <test+0x95>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xc(%rbp),%rsi
lea    -0xa(%rbp),%rdx
movzwl -0x6(%rbp),%edi
call   1040 <keygen@plt>
mov    -0x2(%rbp),%cx
mov    -0xa(%rbp),%ax
movzwl %cx,%edi
movzwl %ax,%esi
movzwl -0xc(%rbp),%edx
call   1030 <encryptDecrypt@plt>
mov    %ax,-0xe(%rbp)
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movzwl -0xe(%rbp),%eax
movzwl -0x4(%rbp),%ecx
cmp    %ecx,%eax
jne    1230 <test+0xf0>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e26(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e1d(%rip)
jmp    123e <test+0xfe>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x8,%esi
movzwl -0x2(%rbp),%edi
call   1050 <printBin@plt>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xa,%esi
movzwl -0x6(%rbp),%edi
call   1050 <printBin@plt>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x8,%esi
movzwl -0x4(%rbp),%edi
call   1050 <printBin@plt>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x8,%esi
movzwl -0xe(%rbp),%edi
call   1050 <printBin@plt>
mov    0x2d94(%rip),%esi
mov    0x2d8a(%rip),%edx
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%r12d
mov    0x2ee0(%rip),%esi
add    $0x1,%esi
mov    %esi,0x2ed7(%rip)
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movzwl %bx,%r15d
cmp    $0x65,%bpl
jne    11a7 <test+0x57>
lea    0xe76(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe(%rsp),%rsi
lea    0xc(%rsp),%rdx
jmp    11bf <test+0x6f>
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xc(%rsp),%rsi
lea    0xe(%rsp),%rdx
mov    %r15d,%edi
call   1050 <keygen@plt>
movzwl 0xe(%rsp),%esi
movzwl 0xc(%rsp),%edx
movzwl %r12w,%ebp
mov    %ebp,%edi
call   1040 <encryptDecrypt@plt>
mov    %eax,%ebx
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    %r14w,%bx
jne    1207 <test+0xb7>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
addl   $0x1,0x2e4b(%rip)
jmp    1213 <test+0xc3>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
mov    $0x8,%esi
call   1060 <printBin@plt>
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
mov    $0xa,%esi
call   1060 <printBin@plt>
lea    0xdfe(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movzwl %r14w,%edi
mov    $0x8,%esi
call   1060 <printBin@plt>
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movzwl %bx,%edi
mov    $0x8,%esi
call   1060 <printBin@plt>
mov    0x2dcb(%rip),%esi
mov    0x2dc1(%rip),%edx
lea    0xde0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@test.testNo = internal global i32 0
@test.testPassNo = internal global i32 0
@.str = [10 x i8] c"\0ATEST %d \00"
@.str.1 = [13 x i8] c"ENCRYPTION:\09\00"
@.str.2 = [13 x i8] c"DECRYPTION:\09\00"
@.str.3 = [22 x i8] c"\0A----------\0AGrade:\09\09\09\00"
@.str.4 = [20 x i8] c"\1B[22;1;32mPASS\1B[0m\0A\00"
@.str.5 = [20 x i8] c"\1B[22;1;31mFAIL\1B[0m\0A\00"
@.str.6 = [10 x i8] c"Input:\09\09\09\00"
@.str.7 = [9 x i8] c"\0AKey:\09\09\09\00"
@.str.8 = [19 x i8] c"\0AExpected Output:\09\00"
@.str.9 = [18 x i8] c"\0AActual Output:\09\09\00"
@.str.10 = [39 x i8] c"\0A---------\0A\1B[22;1;32m%d/%d passed\1B[0m\0A\00"
define void @test(i16 zeroext %0, i16 zeroext %1, i16 zeroext %2, i8 signext %3) {
%5 = alloca i16
%6 = alloca i16
%7 = alloca i16
%8 = alloca i8
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
store i16 %0, i16* %5
store i16 %1, i16* %6
store i16 %2, i16* %7
store i8 %3, i8* %8
%12 = load i32, i32* @test.testNo
%13 = add nsw i32 %12, 1
store i32 %13, i32* @test.testNo
%14 = load i32, i32* @test.testNo
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i8, i8* %8
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 101
br i1 %18, label %19, label %23
19: ; preds = %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%21 = load i16, i16* %7
%22 = call i32 @keygen(i16 zeroext %21, i16* %9, i16* %10)
br label %27
23: ; preds = %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%25 = load i16, i16* %7
%26 = call i32 @keygen(i16 zeroext %25, i16* %10, i16* %9)
br label %27
27: ; preds = %23, %19
%28 = load i16, i16* %5
%29 = load i16, i16* %9
%30 = load i16, i16* %10
%31 = call zeroext i16 @encryptDecrypt(i16 zeroext %28, i16 zeroext %29, i16 zeroext %30)
store i16 %31, i16* %11
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%33 = load i16, i16* %11
%34 = zext i16 %33 to i32
%35 = load i16, i16* %6
%36 = zext i16 %35 to i32
%37 = icmp eq i32 %34, %36
br i1 %37, label %38, label %42
38: ; preds = %27
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* @test.testPassNo
%41 = add nsw i32 %40, 1
store i32 %41, i32* @test.testPassNo
br label %44
42: ; preds = %27
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%46 = load i16, i16* %5
%47 = call i32 @printBin(i16 zeroext %46, i32 8)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%49 = load i16, i16* %7
%50 = call i32 @printBin(i16 zeroext %49, i32 10)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%52 = load i16, i16* %6
%53 = call i32 @printBin(i16 zeroext %52, i32 8)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%55 = load i16, i16* %11
%56 = call i32 @printBin(i16 zeroext %55, i32 8)
%57 = load i32, i32* @test.testPassNo
%58 = load i32, i32* @test.testNo
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0), i32 %57, i32 %58)
ret void
}

LLVM IR (-O2):
@test.testNo = internal unnamed_addr global i32 0
@test.testPassNo = internal unnamed_addr global i32 0
@.str = [10 x i8] c"\0ATEST %d \00"
@.str.1 = [13 x i8] c"ENCRYPTION:\09\00"
@.str.2 = [13 x i8] c"DECRYPTION:\09\00"
@.str.3 = [22 x i8] c"\0A----------\0AGrade:\09\09\09\00"
@.str.6 = [10 x i8] c"Input:\09\09\09\00"
@.str.7 = [9 x i8] c"\0AKey:\09\09\09\00"
@.str.8 = [19 x i8] c"\0AExpected Output:\09\00"
@.str.9 = [18 x i8] c"\0AActual Output:\09\09\00"
@.str.10 = [39 x i8] c"\0A---------\0A\1B[22;1;32m%d/%d passed\1B[0m\0A\00"
@str = [19 x i8] c"\1B[22;1;31mFAIL\1B[0m\00"
@str.11 = [19 x i8] c"\1B[22;1;32mPASS\1B[0m\00"
define void @test(i16 zeroext %0, i16 zeroext %1, i16 zeroext %2, i8 signext %3) {
%5 = alloca i16
%6 = alloca i16
%7 = bitcast i16* %5 to i8*
%8 = bitcast i16* %6 to i8*
%9 = load i32, i32* @test.testNo
%10 = add nsw i32 %9, 1
store i32 %10, i32* @test.testNo
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i8 %3, 101
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @keygen(i16 zeroext %2, i16* %5, i16* %6)
br label %19
16: ; preds = %4
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @keygen(i16 zeroext %2, i16* %6, i16* %5)
br label %19
19: ; preds = %16, %13
%20 = load i16, i16* %5
%21 = load i16, i16* %6
%22 = call zeroext i16 @encryptDecrypt(i16 zeroext %0, i16 zeroext %20, i16 zeroext %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i16 %22, %1
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.11, i64 0, i64 0))
%27 = load i32, i32* @test.testPassNo
%28 = add nsw i32 %27, 1
store i32 %28, i32* @test.testPassNo
br label %31
29: ; preds = %19
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%33 = call i32 @printBin(i16 zeroext %0, i32 8)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%35 = call i32 @printBin(i16 zeroext %2, i32 10)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%37 = call i32 @printBin(i16 zeroext %1, i32 8)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%39 = call i32 @printBin(i16 zeroext %22, i32 8)
%40 = load i32, i32* @test.testPassNo
%41 = load i32, i32* @test.testNo
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.10, i64 0, i64 0), i32 %40, i32 %41)
ret void
}