#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*/ _exit(int);
int /*<<< orphan*/ base64_to_bin(unsigned char *, size_t *);
int /*<<< orphan*/ calculate_key(unsigned char *, size_t, unsigned char *,
                                 size_t);
int /*<<< orphan*/ decrypt_repeated_key(unsigned char *, size_t,
                                        unsigned char *, size_t);
size_t find_best_key_size(unsigned char *, size_t);
size_t hamming_distance(char const *, char const *, int /*<<< orphan*/);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
unsigned char *read_file(char *, size_t *);
int /*<<< orphan*/ strlen(char const *);
int main(int argc, char *argv[]) {
  size_t data_len = 0;
  unsigned char *data = NULL;
  size_t key_size = 0;
  unsigned char *key = NULL;
  {
    const char a[] = "this is a test";
    const char b[] = "wokka wokka!!!";
    size_t dist = hamming_distance(a, b, strlen(a));
    if (37 != dist) {
      printf("Hamming #define istance %d is not 37\n", dist);
      _exit(-1);
    }
  }
  data = read_file("6.txt", &data_len);
  base64_to_bin(data, &data_len);
  key_size = find_best_key_size(data, data_len);
  key = (unsigned char *)malloc(key_size);
  calculate_key(data, data_len, key, key_size);
  decrypt_repeated_key(data, data_len, key, key_size);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0xe23(%rip),%rax
mov    %rax,-0x3f(%rbp)
mov    0xe21(%rip),%eax
mov    %eax,-0x37(%rbp)
mov    0xe1b(%rip),%ax
mov    %ax,-0x33(%rbp)
mov    0xe13(%rip),%al
mov    %al,-0x31(%rbp)
mov    0xe0a(%rip),%rax
mov    %rax,-0x4e(%rbp)
mov    0xe08(%rip),%eax
mov    %eax,-0x46(%rbp)
mov    0xe02(%rip),%ax
mov    %ax,-0x42(%rbp)
mov    0xdfa(%rip),%al
mov    %al,-0x40(%rbp)
lea    -0x3f(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x4e(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x3f(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1090 <hamming_distance@plt>
mov    %rax,-0x58(%rbp)
mov    $0x25,%eax
cmp    -0x58(%rbp),%rax
je     127d <main+0xdd>
mov    -0x58(%rbp),%rsi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <_exit@plt>
lea    0xdc0(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <read_file@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <base64_to_bin@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <find_best_key_size@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   10b0 <calculate_key@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   10c0 <decrypt_repeated_key@plt>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
movq   $0x0,0x8(%rsp)
movabs $0x74736574206120,%rax
mov    %rax,0x27(%rsp)
movabs $0x2073692073696874,%rax
69 73 20
mov    %rax,0x20(%rsp)
movabs $0x212121616b6b6f,%rax
mov    %rax,0x17(%rsp)
movabs $0x6f7720616b6b6f77,%rax
20 77 6f
mov    %rax,0x10(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   10a0 <hamming_distance@plt>
cmp    $0x25,%rax
jne    1299 <main+0xe9>
lea    0xe1d(%rip),%rdi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1090 <read_file@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <base64_to_bin@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <find_best_key_size@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   10b0 <malloc@plt>
mov    %rax,%r15
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
mov    %r14,%rcx
call   10c0 <calculate_key@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   10d0 <decrypt_repeated_key@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd7e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <_exit@plt>

LLVM IR (-O0):
@__const.main.a = [15 x i8] c"this is a test\00"
@__const.main.b = [15 x i8] c"wokka wokka!!!\00"
@.str = [38 x i8] c"Hamming #define istance %d is not 37\0A\00"
@.str.1 = [6 x i8] c"6.txt\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca [15 x i8]
%11 = alloca [15 x i8]
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i8* null, i8** %7
store i64 0, i64* %8
store i8* null, i8** %9
%13 = bitcast [15 x i8]* %10 to i8*
%14 = bitcast [15 x i8]* %11 to i8*
%15 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%16 = getelementptr inbounds [15 x i8], [15 x i8]* %11, i64 0, i64 0
%17 = getelementptr inbounds [15 x i8], [15 x i8]* %10, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i64 @hamming_distance(i8* %15, i8* %16, i32 %18)
store i64 %19, i64* %12
%20 = load i64, i64* %12
%21 = icmp ne i64 37, %20
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = load i64, i64* %12
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = call i32 @_exit(i32 -1)
unreachable
26: ; preds = %2
%27 = call i8* @read_file(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %6)
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = call i32 @base64_to_bin(i8* %28, i64* %6)
%30 = load i8*, i8** %7
%31 = load i64, i64* %6
%32 = call i64 @find_best_key_size(i8* %30, i64 %31)
store i64 %32, i64* %8
%33 = load i64, i64* %8
%34 = call i64 @malloc(i64 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %9
%36 = load i8*, i8** %7
%37 = load i64, i64* %6
%38 = load i8*, i8** %9
%39 = load i64, i64* %8
%40 = call i32 @calculate_key(i8* %36, i64 %37, i8* %38, i64 %39)
%41 = load i8*, i8** %7
%42 = load i64, i64* %6
%43 = load i8*, i8** %9
%44 = load i64, i64* %8
%45 = call i32 @decrypt_repeated_key(i8* %41, i64 %42, i8* %43, i64 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [15 x i8] c"this is a test\00"
@__const.main.b = [15 x i8] c"wokka wokka!!!\00"
@.str = [38 x i8] c"Hamming #define istance %d is not 37\0A\00"
@.str.1 = [6 x i8] c"6.txt\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [15 x i8]
%5 = alloca [15 x i8]
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%9 = call i32 @strlen(i8* %7)
%10 = call i64 @hamming_distance(i8* %7, i8* %8, i32 %9)
%11 = icmp eq i64 %10, 37
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %10)
%14 = call i32 @_exit(i32 -1)
unreachable
15: ; preds = %2
%16 = call i8* @read_file(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%17 = call i32 @base64_to_bin(i8* %16, i64* %3)
%18 = load i64, i64* %3
%19 = call i64 @find_best_key_size(i8* %16, i64 %18)
%20 = call i64 @malloc(i64 %19)
%21 = inttoptr i64 %20 to i8*
%22 = load i64, i64* %3
%23 = call i32 @calculate_key(i8* %16, i64 %22, i8* %21, i64 %19)
%24 = load i64, i64* %3
%25 = call i32 @decrypt_repeated_key(i8* %16, i64 %24, i8* %21, i64 %19)
%26 = call i32 @putchar(i32 10)
ret i32 0
}