#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 */
typedef int uint32_t;
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned char *asciihex2hexbytes(int *, char *);
unsigned char *break_shiftcipher(int, unsigned char *);
scalar_t__ contains_key(int, unsigned char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, unsigned char *);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  if (!argv[1]) {
    puts("Usage: ./a.out <filename>");
    exit(1);
  }
  unsigned char *buf = NULL;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  FILE *fp;
  fp = fopen(argv[1], "r");
  if (fp == NULL) {
    puts("error opening file");
    exit(1);
  }
  uint32_t count_line = 1;
  while ((read = getline(&line, &len, fp)) != -1) {
    uint32_t line_len = (uint32_t)len;
    line_len = line_len / 2;
    buf = asciihex2hexbytes(&line_len, line);
    buf = break_shiftcipher(line_len, buf);
    if (contains_key(line_len, buf)) {
      printf("possible decryption found in line %d:\n%s\n", count_line, buf);
    }
    count_line++;
  }
  fclose(fp);
  if (line)
    free(line);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11db <main+0x3b>
lea    0xe34(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe18(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    122c <main+0x8c>
lea    0xdff(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x1,-0x3c(%rbp)
mov    -0x38(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     12bd <main+0x11d>
mov    -0x28(%rbp),%rax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdi
call   10c0 <asciihex2hexbytes@plt>
mov    %rax,-0x18(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <break_shiftcipher@plt>
mov    %rax,-0x18(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <contains_key@plt>
cmp    $0x0,%rax
je     12af <main+0x10f>
mov    -0x3c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xd85(%rip),%rdi
call   1060 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1233 <main+0x93>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     12da <main+0x13a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     12af <main+0x10f>
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe46(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12b8 <main+0x118>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
je     1287 <main+0xe7>
mov    $0x1,%ebp
lea    0x4(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    1236 <main+0x96>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
je     1287 <main+0xe7>
mov    0x10(%rsp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
mov    %ecx,0x4(%rsp)
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
call   10c0 <asciihex2hexbytes@plt>
mov    0x4(%rsp),%edi
mov    %rax,%rsi
call   1080 <break_shiftcipher@plt>
mov    %rax,%r13
mov    0x4(%rsp),%edi
mov    %rax,%rsi
call   1070 <contains_key@plt>
test   %rax,%rax
je     1220 <main+0x80>
lea    0xdb4(%rip),%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1060 <printf@plt>
jmp    1220 <main+0x80>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     129e <main+0xfe>
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4a(%rip),%rdi
jmp    12bf <main+0x11f>
lea    0xd5d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Usage: ./a.out <filename>\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"error opening file\00"
@.str.3 = [42 x i8] c"possible decryption found in line %d:\0A%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
store i8* null, i8** %6
store i8* null, i8** %7
store i64 0, i64* %8
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %10
%25 = load i32*, i32** %10
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
store i32 1, i32* %11
br label %31
31: ; preds = %53, %30
%32 = load i32*, i32** %10
%33 = call i32 @getline(i8** %7, i64* %8, i32* %32)
store i32 %33, i32* %9
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %56
35: ; preds = %31
%36 = load i64, i64* %8
%37 = trunc i64 %36 to i32
store i32 %37, i32* %12
%38 = load i32, i32* %12
%39 = sdiv i32 %38, 2
store i32 %39, i32* %12
%40 = load i8*, i8** %7
%41 = call i8* @asciihex2hexbytes(i32* %12, i8* %40)
store i8* %41, i8** %6
%42 = load i32, i32* %12
%43 = load i8*, i8** %6
%44 = call i8* @break_shiftcipher(i32 %42, i8* %43)
store i8* %44, i8** %6
%45 = load i32, i32* %12
%46 = load i8*, i8** %6
%47 = call i64 @contains_key(i32 %45, i8* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %35
%50 = load i32, i32* %11
%51 = load i8*, i8** %6
%52 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %50, i8* %51)
br label %53
53: ; preds = %49, %35
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %31
56: ; preds = %31
%57 = load i32*, i32** %10
%58 = call i32 @fclose(i32* %57)
%59 = load i8*, i8** %7
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i8*, i8** %7
%63 = call i32 @free(i8* %62)
br label %64
64: ; preds = %61, %56
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"Usage: ./a.out <filename>\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"error opening file\00"
@.str.3 = [42 x i8] c"possible decryption found in line %d:\0A%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%14 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%15 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = call i32 @getline(i8** %3, i64* %4, i32* %15)
%19 = icmp eq i32 %18, -1
br i1 %19, label %43, label %20
20: ; preds = %17
%21 = bitcast i32* %5 to i8*
br label %25
22: ; preds = %12
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %20, %39
%26 = phi i32 [ 1, %20 ], [ %40, %39 ]
%27 = load i64, i64* %4
%28 = trunc i64 %27 to i32
%29 = sdiv i32 %28, 2
store i32 %29, i32* %5
%30 = load i8*, i8** %3
%31 = call i8* @asciihex2hexbytes(i32* %5, i8* %30)
%32 = load i32, i32* %5
%33 = call i8* @break_shiftcipher(i32 %32, i8* %31)
%34 = load i32, i32* %5
%35 = call i64 @contains_key(i32 %34, i8* %33)
%36 = icmp eq i64 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %25
%38 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %26, i8* %33)
br label %39
39: ; preds = %37, %25
%40 = add nuw nsw i32 %26, 1
%41 = call i32 @getline(i8** %3, i64* %4, i32* %15)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %25
43: ; preds = %39, %17
%44 = call i32 @fclose(i32* %15)
%45 = load i8*, i8** %3
%46 = icmp eq i8* %45, null
br i1 %46, label %49, label %47
47: ; preds = %43
%48 = call i32 @free(i8* %45)
br label %49
49: ; preds = %47, %43
ret i32 0
}