#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 char);
unsigned int getc(int /*<<< orphan*/);
int /*<<< orphan*/ init_permutations(unsigned char *, unsigned char *,
                                     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 alpha[26];
  unsigned char ialpha[26];
  unsigned char numer[10];
  unsigned char inumer[10];
  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(alpha, ialpha, numer, inumer, key, key_length);
  while ((ic = getc(stdin)) != EOF) {
    c = ic;
    if (forward)
      c = apply_permutations(alpha, numer, c);
    else
      c = apply_permutations(ialpha, inumer, c);
    (void)putc((int)c, stdout);
  }
  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)
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    11af <main+0x4f>
movl   $0x1,-0x80(%rbp)
jmp    11e0 <main+0x80>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11cf <main+0x6f>
movl   $0x0,-0x80(%rbp)
jmp    11db <main+0x7b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    11e0 <main+0x80>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x74(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x5a(%rbp),%rdx
lea    -0x64(%rbp),%rcx
mov    -0x70(%rbp),%r8
mov    -0x74(%rbp),%r9d
call   1060 <init_permutations@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1080 <getc@plt>
mov    %eax,-0x78(%rbp)
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%eax
je     128d <main+0x12d>
mov    -0x78(%rbp),%eax
mov    %al,-0x79(%rbp)
cmpl   $0x0,-0x80(%rbp)
je     1262 <main+0x102>
lea    -0x30(%rbp),%rdi
lea    -0x5a(%rbp),%rsi
movzbl -0x79(%rbp),%edx
call   1030 <apply_permutations@plt>
mov    %al,-0x79(%rbp)
jmp    1276 <main+0x116>
lea    -0x50(%rbp),%rdi
lea    -0x64(%rbp),%rsi
movzbl -0x79(%rbp),%edx
call   1030 <apply_permutations@plt>
mov    %al,-0x79(%rbp)
movzbl -0x79(%rbp),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
call   1050 <putc@plt>
jmp    1219 <main+0xb9>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
je     117e <main+0x1e>
mov    (%r14),%rdi
call   1070 <usage@plt>
mov    0x8(%r14),%rbx
mov    (%rbx),%al
cmp    $0x2b,%al
je     1191 <main+0x31>
cmp    $0x2d,%al
jne    1195 <main+0x35>
mov    $0x1,%bpl
jmp    11a1 <main+0x41>
xor    %ebp,%ebp
jmp    11a1 <main+0x41>
mov    (%r14),%rdi
call   1070 <usage@plt>
mov    0x8(%r14),%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x40(%rsp),%rdi
lea    0x20(%rsp),%rsi
lea    0x16(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%r8
mov    %eax,%r9d
call   1060 <init_permutations@plt>
mov    0x2e15(%rip),%rbx
mov    (%rbx),%edi
call   1080 <getc@plt>
mov    0x2dff(%rip),%r14
cmp    (%r14),%eax
jne    11f7 <main+0x97>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd2(%rip),%r15
lea    0x40(%rsp),%r12
lea    0x16(%rsp),%r13
jmp    1236 <main+0xd6>
nopw   0x0(%rax,%rax,1)
lea    0x20(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1030 <apply_permutations@plt>
movzbl %al,%edi
mov    (%r15),%esi
call   1050 <putc@plt>
mov    (%rbx),%edi
call   1080 <getc@plt>
cmp    (%r14),%eax
je     11e6 <main+0x86>
movzbl %al,%edx
test   $0x1,%bpl
jne    1210 <main+0xb0>
mov    %r12,%rdi
mov    %r13,%rsi
jmp    121a <main+0xba>

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