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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
scalar_t__ isalpha(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
char toupper(int);
void baconian_encrypt(FILE *input) {
  uint8_t buffer[512];
  int c;
  int i;
  int j;
  int output_index = 0;
  const int mask = 0x10;
  char output[512];
  int size;
  while ((size = fread(buffer, 1, 512, input)) > 0) {
    for (i = 0; i < size; i++) {
      c = buffer[i];
      if (isalpha(c)) {
        c = toupper(c) - 'A';
        for (j = 0; j < 5; j++) {
          output[output_index++] = ((c & mask) == 0) ? 'A' : 'B';
          c <<= 1;
        }
      } else {
        output[output_index++] = c;
      }
      if (output_index > 512 - 5 - 1) {
        output[output_index] = '\0';
        printf("%s", output);
        output_index = 0;
      }
    }
    output[output_index] = '\0';
    printf("%s", output);
  }
  if (ferror(input)) {
    fprintf(stderr, "error reading input\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<baconian_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x820(%rbp)
movl   $0x10,-0x824(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1050 <fread@plt>
mov    %eax,-0xa34(%rbp)
cmp    $0x0,%eax
jle    132a <baconian_encrypt+0x1ba>
movl   $0x0,-0x818(%rbp)
mov    -0x818(%rbp),%eax
cmp    -0xa34(%rbp),%eax
jge    1303 <baconian_encrypt+0x193>
movslq -0x818(%rbp),%rax
mov    -0x810(%rbp,%rax,4),%eax
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%edi
call   1080 <isalpha@plt>
cmp    $0x0,%rax
je     128c <baconian_encrypt+0x11c>
mov    -0x814(%rbp),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
mov    %eax,-0x814(%rbp)
movl   $0x0,-0x81c(%rbp)
cmpl   $0x5,-0x81c(%rbp)
jge    1287 <baconian_encrypt+0x117>
mov    -0x814(%rbp),%edx
and    $0x10,%edx
mov    $0x42,%eax
mov    $0x41,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %al,%cl
mov    -0x820(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x820(%rbp)
cltq
mov    %cl,-0xa30(%rbp,%rax,1)
mov    -0x814(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0x81c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x81c(%rbp)
jmp    1222 <baconian_encrypt+0xb2>
jmp    12ae <baconian_encrypt+0x13e>
mov    -0x814(%rbp),%eax
mov    %al,%cl
mov    -0x820(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x820(%rbp)
cltq
mov    %cl,-0xa30(%rbp,%rax,1)
cmpl   $0x1fa,-0x820(%rbp)
jle    12ea <baconian_encrypt+0x17a>
movslq -0x820(%rbp),%rax
movb   $0x0,-0xa30(%rbp,%rax,1)
lea    -0xa30(%rbp),%rsi
lea    0xd25(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x820(%rbp)
jmp    12ef <baconian_encrypt+0x17f>
mov    -0x818(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x818(%rbp)
jmp    11c6 <baconian_encrypt+0x56>
movslq -0x820(%rbp),%rax
movb   $0x0,-0xa30(%rbp,%rax,1)
lea    -0xa30(%rbp),%rsi
lea    0xce0(%rip),%rdi
call   1060 <printf@plt>
jmp    1193 <baconian_encrypt+0x23>
mov    -0x8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1360 <baconian_encrypt+0x1f0>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
lea    0xcb6(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
add    $0xa40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<baconian_encrypt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa18,%rsp
mov    %rdi,%rcx
lea    0x210(%rsp),%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rcx,0x8(%rsp)
call   1050 <fread@plt>
test   %eax,%eax
jle    12b0 <baconian_encrypt+0x140>
xor    %ebx,%ebx
lea    0xe4f(%rip),%r15
lea    0x10(%rsp),%r13
jmp    11f7 <baconian_encrypt+0x87>
nopl   0x0(%rax,%rax,1)
movslq %ebx,%rax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
lea    0x210(%rsp),%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    0x8(%rsp),%rcx
call   1050 <fread@plt>
test   %eax,%eax
jle    12b0 <baconian_encrypt+0x140>
mov    %eax,%r12d
xor    %r14d,%r14d
jmp    1209 <baconian_encrypt+0x99>
nop
add    $0x1,%r14
cmp    %r14,%r12
je     11c0 <baconian_encrypt+0x50>
mov    0x210(%rsp,%r14,4),%ebp
mov    %ebp,%edi
call   1080 <isalpha@plt>
test   %rax,%rax
je     1280 <baconian_encrypt+0x110>
mov    %ebp,%edi
call   1030 <toupper@plt>
movzbl %al,%ebp
add    $0xffffffbf,%ebp
mov    %ebp,%eax
and    $0x10,%eax
cmp    $0x1,%eax
mov    $0x42,%al
sbb    $0x0,%al
movslq %ebx,%rbx
mov    %al,0x10(%rsp,%rbx,1)
mov    %ebp,%eax
and    $0x8,%eax
cmp    $0x1,%eax
mov    $0x42,%al
sbb    $0x0,%al
mov    %ebp,%ecx
and    $0x4,%ecx
cmp    $0x1,%ecx
mov    $0x42,%cl
sbb    $0x0,%cl
mov    %al,0x11(%rsp,%rbx,1)
mov    %cl,0x12(%rsp,%rbx,1)
mov    %ebp,%eax
and    $0x2,%eax
cmp    $0x1,%eax
mov    $0x42,%cl
sbb    $0x0,%cl
lea    0x4(%rbx),%rax
mov    %cl,0x13(%rsp,%rbx,1)
and    $0x1,%bpl
add    $0x41,%bpl
add    $0x5,%ebx
jmp    1286 <baconian_encrypt+0x116>
movslq %ebx,%rax
add    $0x1,%ebx
mov    %bpl,0x10(%rsp,%rax,1)
cmp    $0x1fb,%ebx
jl     1200 <baconian_encrypt+0x90>
mov    %ebx,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
xor    %ebx,%ebx
jmp    1200 <baconian_encrypt+0x90>
mov    0x8(%rsp),%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    12d1 <baconian_encrypt+0x161>
add    $0xa18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
lea    0xd22(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"error reading input\0A\00"
@EXIT_FAILURE = global i32 0
define void @baconian_encrypt(i32* %0) {
%2 = alloca i32*
%3 = alloca [512 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %7
store i32 16, i32* %8
br label %11
11: ; preds = %74, %1
%12 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i32 @fread(i32* %12, i32 1, i32 512, i32* %13)
store i32 %14, i32* %10
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %80
16: ; preds = %11
store i32 0, i32* %5
br label %17
17: ; preds = %71, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %10
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %74
21: ; preds = %17
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 %23
%25 = load i32, i32* %24
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = call i64 @isalpha(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %54
29: ; preds = %21
%30 = load i32, i32* %4
%31 = call signext i8 @toupper(i32 %30)
%32 = sext i8 %31 to i32
%33 = sub nsw i32 %32, 65
store i32 %33, i32* %4
store i32 0, i32* %6
br label %34
34: ; preds = %50, %29
%35 = load i32, i32* %6
%36 = icmp slt i32 %35, 5
br i1 %36, label %37, label %53
37: ; preds = %34
%38 = load i32, i32* %4
%39 = and i32 %38, 16
%40 = icmp eq i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 65, i32 66
%43 = trunc i32 %42 to i8
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %46
store i8 %43, i8* %47
%48 = load i32, i32* %4
%49 = shl i32 %48, 1
store i32 %49, i32* %4
br label %50
50: ; preds = %37
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %34
53: ; preds = %34
br label %61
54: ; preds = %21
%55 = load i32, i32* %4
%56 = trunc i32 %55 to i8
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %59
store i8 %56, i8* %60
br label %61
61: ; preds = %54, %53
%62 = load i32, i32* %7
%63 = icmp sgt i32 %62, 506
br i1 %63, label %64, label %70
64: ; preds = %61
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %66
store i8 0, i8* %67
%68 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%69 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %68)
store i32 0, i32* %7
br label %70
70: ; preds = %64, %61
br label %71
71: ; preds = %70
%72 = load i32, i32* %5
%73 = add nsw i32 %72, 1
store i32 %73, i32* %5
br label %17
74: ; preds = %17
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %76
store i8 0, i8* %77
%78 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%79 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %78)
br label %11
80: ; preds = %11
%81 = load i32*, i32** %2
%82 = call i64 @ferror(i32* %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %89
84: ; preds = %80
%85 = load i32, i32* @stderr
%86 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %80
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"error reading input\0A\00"
@EXIT_FAILURE = global i32 0
define void @baconian_encrypt(i32* nocapture %0) {
%2 = alloca [512 x i32]
%3 = alloca [512 x i8]
%4 = bitcast [512 x i32]* %2 to i8*
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i32], [512 x i32]* %2, i64 0, i64 0
%7 = call i32 @fread(i32* %6, i32 1, i32 512, i32* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %73
9: ; preds = %1, %67
%10 = phi i32 [ %71, %67 ], [ %7, %1 ]
%11 = phi i32 [ %64, %67 ], [ 0, %1 ]
%12 = zext i32 %10 to i64
br label %13
13: ; preds = %9, %63
%14 = phi i64 [ 0, %9 ], [ %65, %63 ]
%15 = phi i32 [ %11, %9 ], [ %64, %63 ]
%16 = getelementptr inbounds [512 x i32], [512 x i32]* %2, i64 0, i64 %14
%17 = load i32, i32* %16
%18 = call i64 @isalpha(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %49, label %20
20: ; preds = %13
%21 = call signext i8 @toupper(i32 %17)
%22 = zext i8 %21 to i32
%23 = add nsw i32 %22, -65
%24 = sext i32 %15 to i64
%25 = and i32 %23, 16
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8 65, i8 66
%28 = add nsw i64 %24, 1
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %24
store i8 %27, i8* %29
%30 = and i32 %23, 8
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i8 65, i8 66
%33 = add nsw i64 %24, 2
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %28
store i8 %32, i8* %34
%35 = and i32 %23, 4
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i8 65, i8 66
%38 = add nsw i64 %24, 3
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %33
store i8 %37, i8* %39
%40 = and i32 %23, 2
%41 = icmp eq i32 %40, 0
%42 = select i1 %41, i8 65, i8 66
%43 = add nsw i64 %24, 4
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %38
store i8 %42, i8* %44
%45 = and i32 %23, 1
%46 = icmp eq i32 %45, 0
%47 = select i1 %46, i8 65, i8 66
%48 = add nsw i32 %15, 5
br label %53
49: ; preds = %13
%50 = trunc i32 %17 to i8
%51 = add nsw i32 %15, 1
%52 = sext i32 %15 to i64
br label %53
53: ; preds = %20, %49
%54 = phi i64 [ %43, %20 ], [ %52, %49 ]
%55 = phi i8 [ %47, %20 ], [ %50, %49 ]
%56 = phi i32 [ %48, %20 ], [ %51, %49 ]
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %54
store i8 %55, i8* %57
%58 = icmp sgt i32 %56, 506
br i1 %58, label %59, label %63
59: ; preds = %53
%60 = zext i32 %56 to i64
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %60
store i8 0, i8* %61
%62 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %63
63: ; preds = %53, %59
%64 = phi i32 [ 0, %59 ], [ %56, %53 ]
%65 = add nuw nsw i64 %14, 1
%66 = icmp eq i64 %65, %12
br i1 %66, label %67, label %13
67: ; preds = %63
%68 = sext i32 %64 to i64
%69 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %68
store i8 0, i8* %69
%70 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%71 = call i32 @fread(i32* %6, i32 1, i32 512, i32* %0)
%72 = icmp sgt i32 %71, 0
br i1 %72, label %9, label %73
73: ; preds = %67, %1
%74 = call i64 @ferror(i32* %0)
%75 = icmp eq i64 %74, 0
br i1 %75, label %81, label %76
76: ; preds = %73
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%79 = load i32, i32* @EXIT_FAILURE
%80 = call i32 @exit(i32 %79)
unreachable
81: ; preds = %73
ret void
}