#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 char 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(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ islower(char);
scalar_t__ isupper(char);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
void atbash(FILE *input) {
  uint8_t buffer[512];
  char c;
  int i = 0;
  char output[512 + 1];
  int size;
  while ((size = fread(buffer, 1, 512, input)) > 0) {
    for (i = 0; i < size; i++) {
      c = buffer[i];
      if (isupper(c))
        c = 'Z' - (c - 'A');
      else if (islower(c))
        c = 'z' - (c - 'a');
      output[i] = c;
    }
    output[size] = '\0';
    printf("%s", output);
  }
  if (ferror(input)) {
    fprintf(stderr, "error reading input\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<atbash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1050 <fread@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jle    1295 <atbash+0x125>
movl   $0x0,-0x218(%rbp)
mov    -0x218(%rbp),%eax
cmp    -0x424(%rbp),%eax
jge    126e <atbash+0xfe>
movslq -0x218(%rbp),%rax
mov    -0x210(%rbp,%rax,1),%al
mov    %al,-0x211(%rbp)
movsbl -0x211(%rbp),%edi
call   1080 <isupper@plt>
cmp    $0x0,%rax
je     1214 <atbash+0xa4>
movsbl -0x211(%rbp),%ecx
sub    $0x41,%ecx
mov    $0x5a,%eax
sub    %ecx,%eax
mov    %al,-0x211(%rbp)
jmp    1246 <atbash+0xd6>
movsbl -0x211(%rbp),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     1241 <atbash+0xd1>
movsbl -0x211(%rbp),%ecx
sub    $0x61,%ecx
mov    $0x7a,%eax
sub    %ecx,%eax
mov    %al,-0x211(%rbp)
jmp    1246 <atbash+0xd6>
mov    -0x211(%rbp),%cl
movslq -0x218(%rbp),%rax
mov    %cl,-0x420(%rbp,%rax,1)
mov    -0x218(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x218(%rbp)
jmp    11bc <atbash+0x4c>
movslq -0x424(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xd75(%rip),%rdi
call   1060 <printf@plt>
jmp    1189 <atbash+0x19>
mov    -0x8(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     12cb <atbash+0x15b>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atbash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r13
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r13,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jle    1236 <atbash+0xc6>
mov    %rsp,%r12
jmp    11e8 <atbash+0x78>
cs nopw 0x0(%rax,%rax,1)
movslq %ebx,%rax
movb   $0x0,0x200(%rsp,%rax,1)
lea    0xe3e(%rip),%rdi
lea    0x200(%rsp),%rsi
call   1060 <printf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r13,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jle    1236 <atbash+0xc6>
mov    %eax,%ebx
xor    %r14d,%r14d
jmp    121a <atbash+0xaa>
nop
mov    %ebp,%edi
call   1030 <islower@plt>
mov    $0xdb,%cl
sub    %r15b,%cl
test   %rax,%rax
movzbl %cl,%ecx
movzbl %r15b,%eax
cmovne %ecx,%eax
mov    %al,0x200(%rsp,%r14,1)
add    $0x1,%r14
cmp    %r14,%rbx
je     11b0 <atbash+0x40>
movzbl (%rsp,%r14,1),%r15d
movsbl %r15b,%ebp
mov    %ebp,%edi
call   1080 <isupper@plt>
test   %rax,%rax
je     11f0 <atbash+0x80>
mov    $0x9b,%al
sub    %r15b,%al
jmp    1209 <atbash+0x99>
mov    %r13,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1255 <atbash+0xe5>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d67(%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 @atbash(i32* %0) {
%2 = alloca i32*
%3 = alloca [512 x i8]
%4 = alloca i8
%5 = alloca i32
%6 = alloca [513 x i8]
%7 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %5
br label %8
8: ; preds = %51, %1
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i32 @fread(i8* %9, i32 1, i32 512, i32* %10)
store i32 %11, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %57
13: ; preds = %8
store i32 0, i32* %5
br label %14
14: ; preds = %48, %13
%15 = load i32, i32* %5
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %51
18: ; preds = %14
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
store i8 %22, i8* %4
%23 = load i8, i8* %4
%24 = call i64 @isupper(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %18
%27 = load i8, i8* %4
%28 = sext i8 %27 to i32
%29 = sub nsw i32 %28, 65
%30 = sub nsw i32 90, %29
%31 = trunc i32 %30 to i8
store i8 %31, i8* %4
br label %43
32: ; preds = %18
%33 = load i8, i8* %4
%34 = call i64 @islower(i8 signext %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i8, i8* %4
%38 = sext i8 %37 to i32
%39 = sub nsw i32 %38, 97
%40 = sub nsw i32 122, %39
%41 = trunc i32 %40 to i8
store i8 %41, i8* %4
br label %42
42: ; preds = %36, %32
br label %43
43: ; preds = %42, %26
%44 = load i8, i8* %4
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 %46
store i8 %44, i8* %47
br label %48
48: ; preds = %43
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %14
51: ; preds = %14
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 %53
store i8 0, i8* %54
%55 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%56 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %55)
br label %8
57: ; preds = %8
%58 = load i32*, i32** %2
%59 = call i64 @ferror(i32* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %57
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %57
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 @atbash(i32* nocapture %0) {
%2 = alloca [512 x i8]
%3 = alloca [513 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%6 = call i32 @fread(i8* %4, i32 1, i32 512, i32* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %35
8: ; preds = %1, %29
%9 = phi i32 [ %33, %29 ], [ %6, %1 ]
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %8, %24
%12 = phi i64 [ 0, %8 ], [ %27, %24 ]
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = call i64 @isupper(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = sub i8 -101, %14
br label %24
19: ; preds = %11
%20 = call i64 @islower(i8 signext %14)
%21 = icmp eq i64 %20, 0
%22 = sub i8 -37, %14
%23 = select i1 %21, i8 %14, i8 %22
br label %24
24: ; preds = %19, %17
%25 = phi i8 [ %18, %17 ], [ %23, %19 ]
%26 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 %12
store i8 %25, i8* %26
%27 = add nuw nsw i64 %12, 1
%28 = icmp eq i64 %27, %10
br i1 %28, label %29, label %11
29: ; preds = %24
%30 = sext i32 %9 to i64
%31 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%33 = call i32 @fread(i8* %4, i32 1, i32 512, i32* %0)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %8, label %35
35: ; preds = %29, %1
%36 = call i64 @ferror(i32* %0)
%37 = icmp eq i64 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %35
ret void
}