#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 decode_c(int);
int encode_c(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int i, decode;
  int c;
  FILE *inf, *outf;
  char name[256];
  if (argc < 3) {
    printf(
        "Decode file:\n\tencsh -d file.sh\nEncode file:\n\tencsh -c file.sh\n");
    exit(1);
  }
  if (strcmp(argv[1], "-d"))
    decode = 1;
  else
    decode = 0;
  strcpy(name, argv[2]);
  strcat(name, ".$$$$");
  inf = fopen(argv[2], "rb");
  outf = fopen(name, "wb");
  while ((c = fgetc(inf)) >= 0) {
    if (decode)
      c = decode_c(c);
    else
      c = encode_c(c);
    fputc(c, outf);
  }
  fclose(inf);
  fclose(outf);
  rename(name, argv[2]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11f9 <main+0x39>
lea    0xe16(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe37(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1223 <main+0x63>
movl   $0x1,-0x18(%rbp)
jmp    122a <main+0x6a>
movl   $0x0,-0x18(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x130(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xde8(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x130(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     12cb <main+0x10b>
cmpl   $0x0,-0x18(%rbp)
je     12af <main+0xef>
mov    -0x1c(%rbp),%edi
call   1070 <decode_c@plt>
mov    %eax,-0x1c(%rbp)
jmp    12ba <main+0xfa>
mov    -0x1c(%rbp),%edi
call   1040 <encode_c@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1090 <fputc@plt>
jmp    1280 <main+0xc0>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   10c0 <rename@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
cmp    $0x2,%edi
jle    1296 <main+0xd6>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe1b(%rip),%rsi
call   10a0 <strcmp@plt>
mov    %rax,%r15
mov    0x10(%r14),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe00(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <strcat@plt>
mov    0x10(%r14),%rdi
lea    0xdf3(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r12
lea    0xde7(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
jmp    124f <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1050 <encode_c@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1090 <fputc@plt>
mov    %r12,%rdi
call   1080 <fgetc@plt>
test   %eax,%eax
js     1269 <main+0xa9>
mov    %eax,%edi
test   %r15,%r15
je     1240 <main+0x80>
call   1070 <decode_c@plt>
jmp    1245 <main+0x85>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x10(%r14),%rsi
mov    %rsp,%rdi
call   10c0 <rename@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd72(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [63 x i8] c"Decode file:\0A\09encsh -d file.sh\0AEncode file:\0A\09encsh -c file.sh\0A\00"
@.str.1 = [3 x i8] c"-d\00"
@.str.2 = [6 x i8] c".$$$$\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"wb\00"
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*
%10 = alloca i32*
%11 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 1, i32* %7
br label %25
24: ; preds = %17
store i32 0, i32* %7
br label %25
25: ; preds = %24, %23
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @strcpy(i8* %26, i8* %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %36, i32** %9
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %38, i32** %10
br label %39
39: ; preds = %52, %25
%40 = load i32*, i32** %9
%41 = call i32 @fgetc(i32* %40)
store i32 %41, i32* %8
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %56
43: ; preds = %39
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %8
%48 = call i32 @decode_c(i32 %47)
store i32 %48, i32* %8
br label %52
49: ; preds = %43
%50 = load i32, i32* %8
%51 = call i32 @encode_c(i32 %50)
store i32 %51, i32* %8
br label %52
52: ; preds = %49, %46
%53 = load i32, i32* %8
%54 = load i32*, i32** %10
%55 = call i32 @fputc(i32 %53, i32* %54)
br label %39
56: ; preds = %39
%57 = load i32*, i32** %9
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %10
%60 = call i32 @fclose(i32* %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
%65 = call i32 @rename(i8* %61, i8* %64)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"-d\00"
@.str.2 = [6 x i8] c".$$$$\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"wb\00"
@str = [62 x i8] c"Decode file:\0A\09encsh -d file.sh\0AEncode file:\0A\09encsh -c file.sh\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @strcpy(i8* %4, i8* %15)
%17 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%18 = load i8*, i8** %14
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @fgetc(i32* %19)
%22 = icmp sgt i32 %21, -1
br i1 %22, label %23, label %34
23: ; preds = %9, %29
%24 = phi i32 [ %32, %29 ], [ %21, %9 ]
br i1 %13, label %27, label %25
25: ; preds = %23
%26 = call i32 @decode_c(i32 %24)
br label %29
27: ; preds = %23
%28 = call i32 @encode_c(i32 %24)
br label %29
29: ; preds = %27, %25
%30 = phi i32 [ %26, %25 ], [ %28, %27 ]
%31 = call i32 @fputc(i32 %30, i32* %20)
%32 = call i32 @fgetc(i32* %19)
%33 = icmp sgt i32 %32, -1
br i1 %33, label %23, label %34
34: ; preds = %29, %9
%35 = call i32 @fclose(i32* %19)
%36 = call i32 @fclose(i32* %20)
%37 = load i8*, i8** %14
%38 = call i32 @rename(i8* %4, i8* %37)
ret i32 0
}