#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 EOF;
int /*<<< orphan*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int putc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ rotate(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  FILE *input = stdin, *output = stdout;
  if (argc > 3) {
    usage();
    exit(1);
  } else if (argc != 1) {
    if ((input = fopen((char *)argv[1], "r")) == NULL) {
      perror(argv[1]);
      fprintf(stderr, "rot13: couldn't open %s for input\n", (char *)argv[1]);
      usage();
      exit(1);
    }
    if (argc == 3) {
      if ((output = fopen((char *)argv[2], "w")) == NULL) {
        perror(argv[2]);
        fprintf(stderr, "rot13: couldn't open %s for output\n",
                (char *)argv[2]);
        usage();
        exit(1);
      }
    }
  }
  {
    int a, b = 1;
    while ((a = fgetc(input)) != EOF && b != EOF)
      b = putc(rotate(a), output);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    11cd <main+0x4d>
mov    $0x0,%al
call   1070 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
je     12a5 <main+0x125>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1234 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xde4(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1070 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jne    12a0 <main+0x120>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    129b <main+0x11b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <perror@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xda2(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1070 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12a0 <main+0x120>
jmp    12a5 <main+0x125>
jmp    12aa <main+0x12a>
movl   $0x1,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
mov    0x2d18(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x29(%rbp)
je     12e5 <main+0x165>
mov    -0x28(%rbp),%eax
mov    0x2d03(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    12f5 <main+0x175>
jmp    1310 <main+0x190>
mov    -0x24(%rbp),%edi
call   1060 <rotate@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rsi
call   1040 <putc@plt>
mov    %eax,-0x28(%rbp)
jmp    12b1 <main+0x131>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x4,%edi
jge    1274 <main+0xf4>
mov    %edi,%ebp
mov    0x2e2f(%rip),%rax
mov    (%rax),%r14
cmp    $0x1,%edi
jne    11ad <main+0x2d>
mov    0x2e40(%rip),%rax
mov    (%rax),%rbx
jmp    11e5 <main+0x65>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
lea    0xe45(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1233 <main+0xb3>
mov    %rax,%rbx
cmp    $0x3,%ebp
jne    11e5 <main+0x65>
mov    0x10(%r15),%rdi
lea    0xe4d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     1252 <main+0xd2>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    0x2dec(%rip),%r15
mov    (%r15),%ecx
cmp    %ecx,%eax
je     1226 <main+0xa6>
cmp    $0x1,%ecx
je     1226 <main+0xa6>
mov    %eax,%edi
call   1060 <rotate@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    (%r15),%ecx
cmp    %ecx,%eax
je     1226 <main+0xa6>
cmp    %ecx,%ebp
jne    1200 <main+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r15),%rdi
call   1090 <perror@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xdb2(%rip),%rsi
jmp    126f <main+0xef>
mov    0x10(%r15),%rdi
call   1090 <perror@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r15),%rdx
lea    0xdb8(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1070 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"rot13: couldn't open %s for input\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [36 x i8] c"rot13: couldn't open %s for output\0A\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32*, i32** @stdin
store i32* %10, i32** %6
%11 = load i32*, i32** @stdout
store i32* %11, i32** %7
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (...) @usage()
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %61
20: ; preds = %17
%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, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %38
26: ; preds = %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @perror(i8* %29)
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = call i32 (...) @usage()
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %20
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 3
br i1 %40, label %41, label %60
41: ; preds = %38
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %45, i32** %7
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %59
47: ; preds = %41
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @perror(i8* %50)
%52 = load i32, i32* @stderr
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %55)
%57 = call i32 (...) @usage()
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %41
br label %60
60: ; preds = %59, %38
br label %61
61: ; preds = %60, %17
br label %62
62: ; preds = %61
store i32 1, i32* %9
br label %63
63: ; preds = %74, %62
%64 = load i32*, i32** %6
%65 = call i32 @fgetc(i32* %64)
store i32 %65, i32* %8
%66 = load i32, i32* @EOF
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %72
68: ; preds = %63
%69 = load i32, i32* %9
%70 = load i32, i32* @EOF
%71 = icmp ne i32 %69, %70
br label %72
72: ; preds = %68, %63
%73 = phi i1 [ false, %63 ], [ %71, %68 ]
br i1 %73, label %74, label %79
74: ; preds = %72
%75 = load i32, i32* %8
%76 = call i32 @rotate(i32 %75)
%77 = load i32*, i32** %7
%78 = call i32 @putc(i32 %76, i32* %77)
store i32 %78, i32* %9
br label %63
79: ; preds = %72
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"rot13: couldn't open %s for input\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [36 x i8] c"rot13: couldn't open %s for output\0A\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32*, i32** @stdout
%4 = icmp sgt i32 %0, 3
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 (...) @usage()
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = load i32*, i32** @stdin
%10 = icmp eq i32 %0, 1
br i1 %10, label %39, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = load i8*, i8** %12
%18 = tail call i32 @perror(i8* %17)
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %12
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = tail call i32 (...) @usage()
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %11
%25 = icmp eq i32 %0, 3
br i1 %25, label %26, label %39
26: ; preds = %24
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = tail call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %39
31: ; preds = %26
%32 = load i8*, i8** %27
%33 = tail call i32 @perror(i8* %32)
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %27
%36 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = tail call i32 (...) @usage()
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %8, %26, %24
%40 = phi i32* [ %29, %26 ], [ %3, %24 ], [ %3, %8 ]
%41 = phi i32* [ %14, %26 ], [ %14, %24 ], [ %9, %8 ]
%42 = tail call i32 @fgetc(i32* %41)
%43 = load i32, i32* @EOF
%44 = icmp ne i32 %42, %43
%45 = icmp ne i32 %43, 1
%46 = and i1 %44, %45
br i1 %46, label %47, label %56
47: ; preds = %39, %47
%48 = phi i32 [ %51, %47 ], [ %42, %39 ]
%49 = tail call i32 @rotate(i32 %48)
%50 = tail call i32 @putc(i32 %49, i32* %40)
%51 = tail call i32 @fgetc(i32* %41)
%52 = load i32, i32* @EOF
%53 = icmp ne i32 %51, %52
%54 = icmp ne i32 %50, %52
%55 = and i1 %53, %54
br i1 %55, label %47, label %56
56: ; preds = %47, %39
ret i32 0
}