#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 */

/* Variables and functions */
unsigned int EOF;
unsigned char apply_permutations(unsigned char *, unsigned char);
unsigned int getc(int /*<<< orphan*/);
int /*<<< orphan*/ init_permutations(unsigned char *, unsigned char *,
                                     unsigned char *, int);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(unsigned char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  unsigned char S[94];
  unsigned char U[94];
  unsigned char *key;
  int key_length;
  unsigned ic;
  unsigned char c;
  int forward;
  if (argc != 2)
    usage(argv[0]);
  if (argv[1][0] == '+')
    forward = 1;
  else if (argv[1][0] == '-')
    forward = 0;
  else
    usage(argv[0]);
  key = &argv[1][1];
  key_length = strlen(key);
  init_permutations(S, U, key, key_length);
  while ((ic = getc(stdin)) != EOF) {
    c = ic;
    if (forward)
      c = apply_permutations(S, c);
    else
      c = apply_permutations(U, c);
    (void)putc((int)c, stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118f <main+0x2f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11b2 <main+0x52>
movl   $0x1,-0xe8(%rbp)
jmp    11e6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11d5 <main+0x75>
movl   $0x0,-0xe8(%rbp)
jmp    11e1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    11e6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
add    $0x1,%rax
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xdc(%rbp)
lea    -0x70(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
mov    -0xd8(%rbp),%rdx
mov    -0xdc(%rbp),%ecx
call   1060 <init_permutations@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1080 <getc@plt>
mov    %eax,-0xe0(%rbp)
mov    0x2d9d(%rip),%rcx
cmp    (%rcx),%eax
je     12b2 <main+0x152>
mov    -0xe0(%rbp),%eax
mov    %al,-0xe1(%rbp)
cmpl   $0x0,-0xe8(%rbp)
je     127f <main+0x11f>
lea    -0x70(%rbp),%rdi
movzbl -0xe1(%rbp),%esi
call   1030 <apply_permutations@plt>
mov    %al,-0xe1(%rbp)
jmp    1298 <main+0x138>
lea    -0xd0(%rbp),%rdi
movzbl -0xe1(%rbp),%esi
call   1030 <apply_permutations@plt>
mov    %al,-0xe1(%rbp)
movzbl -0xe1(%rbp),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
call   1050 <putc@plt>
jmp    1228 <main+0xc8>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1181 <main+0x21>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    0x8(%rbx),%r14
mov    (%r14),%al
cmp    $0x2b,%al
je     1195 <main+0x35>
cmp    $0x2d,%al
jne    119a <main+0x3a>
mov    $0x1,%r12b
jmp    11a6 <main+0x46>
xor    %r12d,%r12d
jmp    11a6 <main+0x46>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    0x8(%rbx),%r14
add    $0x1,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x60(%rsp),%rbx
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %eax,%ecx
call   1060 <init_permutations@plt>
mov    0x2e17(%rip),%r14
mov    (%r14),%edi
call   1080 <getc@plt>
mov    0x2e00(%rip),%r13
cmp    0x0(%r13),%eax
je     1224 <main+0xc4>
test   $0x1,%r12b
cmovne %r15,%rbx
mov    0x2ddb(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
movzbl %al,%esi
mov    %rbx,%rdi
call   1030 <apply_permutations@plt>
movzbl %al,%edi
mov    0x0(%rbp),%esi
call   1050 <putc@plt>
mov    (%r14),%edi
call   1080 <getc@plt>
cmp    0x0(%r13),%eax
jne    1200 <main+0xa0>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [94 x i8]
%7 = alloca [94 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @usage(i8* %18)
br label %20
20: ; preds = %15, %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 43
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 1, i32* %12
br label %44
29: ; preds = %20
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 45
br i1 %36, label %37, label %38
37: ; preds = %29
store i32 0, i32* %12
br label %43
38: ; preds = %29
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i32 @usage(i8* %41)
br label %43
43: ; preds = %38, %37
br label %44
44: ; preds = %43, %28
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %48, i8** %8
%49 = load i8*, i8** %8
%50 = call i32 @strlen(i8* %49)
store i32 %50, i32* %9
%51 = getelementptr inbounds [94 x i8], [94 x i8]* %6, i64 0, i64 0
%52 = getelementptr inbounds [94 x i8], [94 x i8]* %7, i64 0, i64 0
%53 = load i8*, i8** %8
%54 = load i32, i32* %9
%55 = call i32 @init_permutations(i8* %51, i8* %52, i8* %53, i32 %54)
br label %56
56: ; preds = %74, %44
%57 = load i32, i32* @stdin
%58 = call i32 @getc(i32 %57)
store i32 %58, i32* %10
%59 = load i32, i32* @EOF
%60 = icmp ne i32 %58, %59
br i1 %60, label %61, label %79
61: ; preds = %56
%62 = load i32, i32* %10
%63 = trunc i32 %62 to i8
store i8 %63, i8* %11
%64 = load i32, i32* %12
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %61
%67 = getelementptr inbounds [94 x i8], [94 x i8]* %6, i64 0, i64 0
%68 = load i8, i8* %11
%69 = call zeroext i8 @apply_permutations(i8* %67, i8 zeroext %68)
store i8 %69, i8* %11
br label %74
70: ; preds = %61
%71 = getelementptr inbounds [94 x i8], [94 x i8]* %7, i64 0, i64 0
%72 = load i8, i8* %11
%73 = call zeroext i8 @apply_permutations(i8* %71, i8 zeroext %72)
store i8 %73, i8* %11
br label %74
74: ; preds = %70, %66
%75 = load i8, i8* %11
%76 = zext i8 %75 to i32
%77 = load i32, i32* @stdout
%78 = call i32 @putc(i32 %76, i32 %77)
br label %56
79: ; preds = %56
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [94 x i8]
%4 = alloca [94 x i8]
%5 = getelementptr inbounds [94 x i8], [94 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [94 x i8], [94 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @usage(i8* %9)
br label %11
11: ; preds = %8, %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
switch i8 %14, label %16 [
i8 43, label %20
i8 45, label %15
]
15: ; preds = %11
br label %20
16: ; preds = %11
%17 = load i8*, i8** %1
%18 = tail call i32 @usage(i8* %17)
%19 = load i8*, i8** %12
br label %20
20: ; preds = %11, %15, %16
%21 = phi i8* [ %13, %15 ], [ %19, %16 ], [ %13, %11 ]
%22 = phi i1 [ true, %15 ], [ undef, %16 ], [ false, %11 ]
%23 = getelementptr inbounds i8, i8* %21, i64 1
%24 = tail call i32 @strlen(i8* %23)
%25 = call i32 @init_permutations(i8* %5, i8* %6, i8* %23, i32 %24)
%26 = load i32, i32* @stdin
%27 = call i32 @getc(i32 %26)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %43, label %30
30: ; preds = %20
%31 = select i1 %22, i8* %6, i8* %5
br label %32
32: ; preds = %30, %32
%33 = phi i32 [ %40, %32 ], [ %27, %30 ]
%34 = trunc i32 %33 to i8
%35 = call zeroext i8 @apply_permutations(i8* %31, i8 zeroext %34)
%36 = zext i8 %35 to i32
%37 = load i32, i32* @stdout
%38 = call i32 @putc(i32 %36, i32 %37)
%39 = load i32, i32* @stdin
%40 = call i32 @getc(i32 %39)
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %32
43: ; preds = %32, %20
ret i32 0
}