#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 /*<<< orphan*/ hill2_crack(char *, int *);
int /*<<< orphan*/ hill2_encipher(char *, char *, int *);
int /*<<< orphan*/ invert_hill2_key(int *, int *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char str[] = "DEFENDTHEEASTWALLOFTHECASTLEATDAWNAGAINSTINVADERS";
  char *ctext = malloc(sizeof(char) * (strlen(str) + 1));
  char *ptext = malloc(sizeof(char) * (strlen(str) + 1));
  int key[] = {5, 17, 4, 15};
  int invkey[] = {0, 0, 0, 0};
  hill2_encipher(ctext, str, key);
  invert_hill2_key(key, invkey);
  hill2_encipher(ptext, ctext, invkey);
  hill2_crack(ctext, invkey);
  printf("%s\n", str);
  printf("%s\n", ctext);
  printf("%s\n", ptext);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x32,%edx
call   1070 <memcpy@plt>
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    0xe58(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xe55(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1030 <hill2_encipher@plt>
lea    -0x70(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   10a0 <invert_hill2_key@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1030 <hill2_encipher@plt>
mov    -0x58(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1090 <hill2_crack@plt>
lea    -0x50(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
mov    -0x58(%rbp),%rsi
lea    0xdf2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x60(%rbp),%rsi
lea    0xde2(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x60,%rsp
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe74(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movw   $0x53,0x50(%rsp)
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
movaps 0xe76(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%r12
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <hill2_encipher@plt>
mov    %rsp,%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <invert_hill2_key@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1030 <hill2_encipher@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <hill2_crack@plt>
lea    0xe39(%rip),%r12
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.str = [50 x i8] c"DEFENDTHEEASTWALLOFTHECASTLEATDAWNAGAINSTINVADERS\00"
@__const.main.key = [4 x i32] [i32 5, i32 17, i32 4, i32 15]
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [50 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [4 x i32]
%9 = alloca [4 x i32]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = bitcast [50 x i8]* %5 to i8*
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = mul i64 1, %14
%16 = trunc i64 %15 to i32
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %6
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = mul i64 1, %21
%23 = trunc i64 %22 to i32
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %7
%25 = bitcast [4 x i32]* %8 to i8*
%26 = bitcast [4 x i32]* %9 to i8*
%27 = load i8*, i8** %6
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%30 = call i32 @hill2_encipher(i8* %27, i8* %28, i32* %29)
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%33 = call i32 @invert_hill2_key(i32* %31, i32* %32)
%34 = load i8*, i8** %7
%35 = load i8*, i8** %6
%36 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%37 = call i32 @hill2_encipher(i8* %34, i8* %35, i32* %36)
%38 = load i8*, i8** %6
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%40 = call i32 @hill2_crack(i8* %38, i32* %39)
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %41)
%43 = load i8*, i8** %6
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %43)
%45 = load i8*, i8** %7
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %45)
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [50 x i8] c"DEFENDTHEEASTWALLOFTHECASTLEATDAWNAGAINSTINVADERS\00"
@__const.main.key = [4 x i32] [i32 5, i32 17, i32 4, i32 15]
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [50 x i8]
%4 = alloca [4 x i32]
%5 = alloca [4 x i32]
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 1
%9 = call i8* @malloc(i32 %8)
%10 = call i32 @strlen(i8* %6)
%11 = add nsw i32 %10, 1
%12 = call i8* @malloc(i32 %11)
%13 = bitcast [4 x i32]* %4 to i8*
%14 = bitcast [4 x i32]* %5 to i8*
%15 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%16 = call i32 @hill2_encipher(i8* %9, i8* %6, i32* %15)
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%18 = call i32 @invert_hill2_key(i32* %15, i32* %17)
%19 = call i32 @hill2_encipher(i8* %12, i8* %9, i32* %17)
%20 = call i32 @hill2_crack(i8* %9, i32* %17)
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
ret i32 0
}