#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ decode_cipher(unsigned char *, unsigned char *, int, char);
unsigned char detect_key_single_line(unsigned char *, int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int /*<<< orphan*/ write(int /*<<< orphan*/, unsigned char *, int);
int main(int argc, char *argv[]) {
  FILE *cipher;
  unsigned char sp_img;
  unsigned char cipher_buf[(34)] = {0}, decoded_cipher[(34)] = {0};
  if (argc < 2)
    return 0x1;
  cipher = fopen(argv[1], "rb");
  if (NULL == cipher) {
    printf("Error when calling fopen(%s) : %s\n", argv[1], strerror(errno));
    return errno;
  }
  if ((34) != fread(&cipher_buf, 1, (34), cipher)) {
    fclose(cipher);
    return errno;
  }
  sp_img = detect_key_single_line(cipher_buf, (34));
  decode_cipher(cipher_buf, decoded_cipher, (34), ' ' ^ sp_img);
  write(STDOUT_FILENO, decoded_cipher, (34));
  printf("\n");
  fclose(cipher);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x22,%edx
call   1080 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x22,%edx
call   1080 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11df <main+0x4f>
movl   $0x1,-0x4(%rbp)
jmp    12e5 <main+0x155>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe12(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1243 <main+0xb3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x78(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x78(%rbp),%rsi
mov    %rax,%rdx
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e5 <main+0x155>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x22,%edx
call   1040 <fread@plt>
mov    %eax,%ecx
mov    $0x22,%eax
cmp    %ecx,%eax
je     1283 <main+0xf3>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e5 <main+0x155>
lea    -0x40(%rbp),%rdi
mov    $0x22,%esi
call   1030 <detect_key_single_line@plt>
mov    %al,-0x19(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x70(%rbp),%rsi
movzbl -0x19(%rbp),%eax
xor    $0x20,%eax
mov    $0x22,%edx
movsbl %al,%ecx
call   10b0 <decode_cipher@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
mov    $0x22,%edx
call   1050 <write@plt>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movw   $0x0,0x20(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movw   $0x0,0x50(%rsp)
mov    $0x1,%eax
cmp    $0x2,%edi
jl     1297 <main+0x107>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe27(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     125a <main+0xca>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x22,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
cmp    $0x22,%eax
jne    1286 <main+0xf6>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x22,%esi
call   1040 <detect_key_single_line@plt>
xor    $0x20,%al
movsbl %al,%ecx
lea    0x30(%rsp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x22,%edx
call   10b0 <decode_cipher@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    $0x22,%edx
call   1060 <write@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
jmp    1297 <main+0x107>
mov    0x8(%rbx),%rbx
mov    0x2d73(%rip),%r14
mov    (%r14),%edi
call   10a0 <strerror@plt>
lea    0xd8f(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r14),%eax
jmp    1297 <main+0x107>
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [35 x i8] c"Error when calling fopen(%s) : %s\0A\00"
@errno = global i32 0
@STDOUT_FILENO = global i32 0
@.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 i32*
%7 = alloca i8
%8 = alloca [34 x i8]
%9 = alloca [34 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [34 x i8]* %8 to i8*
%11 = bitcast [34 x i8]* %9 to i8*
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %55
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* null, %20
br i1 %21, label %22, label %30
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %27)
%29 = load i32, i32* @errno
store i32 %29, i32* %3
br label %55
30: ; preds = %15
%31 = bitcast [34 x i8]* %8 to i8**
%32 = load i32*, i32** %6
%33 = call i32 @fread(i8** %31, i32 1, i32 34, i32* %32)
%34 = icmp ne i32 34, %33
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
%38 = load i32, i32* @errno
store i32 %38, i32* %3
br label %55
39: ; preds = %30
%40 = getelementptr inbounds [34 x i8], [34 x i8]* %8, i64 0, i64 0
%41 = call zeroext i8 @detect_key_single_line(i8* %40, i32 34)
store i8 %41, i8* %7
%42 = getelementptr inbounds [34 x i8], [34 x i8]* %8, i64 0, i64 0
%43 = getelementptr inbounds [34 x i8], [34 x i8]* %9, i64 0, i64 0
%44 = load i8, i8* %7
%45 = zext i8 %44 to i32
%46 = xor i32 32, %45
%47 = trunc i32 %46 to i8
%48 = call i32 @decode_cipher(i8* %42, i8* %43, i32 34, i8 signext %47)
%49 = load i32, i32* @STDOUT_FILENO
%50 = getelementptr inbounds [34 x i8], [34 x i8]* %9, i64 0, i64 0
%51 = call i32 @write(i32 %49, i8* %50, i32 34)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%53 = load i32*, i32** %6
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %3
br label %55
55: ; preds = %39, %35, %22, %14
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [35 x i8] c"Error when calling fopen(%s) : %s\0A\00"
@errno = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [34 x i8]
%4 = alloca [34 x i8]
%5 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [34 x i8], [34 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %34, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %16)
%18 = load i32, i32* @errno
br label %34
19: ; preds = %8
%20 = bitcast [34 x i8]* %3 to i8**
%21 = call i32 @fread(i8** %20, i32 1, i32 34, i32* %11)
%22 = icmp eq i32 %21, 34
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = tail call i32 @fclose(i32* %11)
%25 = load i32, i32* @errno
br label %34
26: ; preds = %19
%27 = call zeroext i8 @detect_key_single_line(i8* %5, i32 34)
%28 = xor i8 %27, 32
%29 = call i32 @decode_cipher(i8* %5, i8* %6, i32 34, i8 signext %28)
%30 = load i32, i32* @STDOUT_FILENO
%31 = call i32 @write(i32 %30, i8* %6, i32 34)
%32 = call i32 @putchar(i32 10)
%33 = call i32 @fclose(i32* %11)
br label %34
34: ; preds = %2, %26, %23, %13
%35 = phi i32 [ %18, %13 ], [ %25, %23 ], [ 0, %26 ], [ 1, %2 ]
ret i32 %35
}