#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EVP_cleanup();
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ decrypt(char *);
int /*<<< orphan*/ encrypt(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int getopt(int, char **, char *);
char *optarg;
scalar_t__ optind;
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int flag_d = -1;
  int flag_e = -1;
  const char *passin = NULL;
  FILE *f;
  char *line = NULL;
  size_t len = 0;
  ssize_t n;
  int opt;
  while ((opt = getopt(argc, argv, "dehp:")) != -1) {
    switch (opt) {
    case 'd':
      flag_d = 1;
      flag_e = 0;
      break;
    case 'e':
      flag_e = 1;
      flag_d = 0;
      break;
    case 'h':
      usage();
      exit(EXIT_SUCCESS);
      break;
    case 'p':
      passin = optarg;
      break;
    case '?':
    default:
      usage();
      exit(EXIT_FAILURE);
    }
  }
  argc -= optind;
  argv += optind;
  if (argc != 0)
    fprintf(stderr,
            "There are more arguments than needed, they will be ignored.\n");
  if (passin == NULL)
    passin = getenv("AED_PASS");
  if ((f = fopen(passin, "rb")) == NULL) {
    fprintf(stderr, "Cannot open passin file!\n");
    exit(EXIT_FAILURE);
  }
  if ((n = getline(&line, &len, f)) == -1) {
    fprintf(stderr, "Cannot read passin file!\n");
    exit(EXIT_FAILURE);
  }
  line[strlen(line) - 1] = '\0';
  if (flag_d == 1) {
    decrypt(line);
  } else if (flag_e == 1) {
    encrypt(line);
  }
  EVP_cleanup();
  if (line)
    free(line);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeae(%rip),%rdx
call   10d0 <getopt@plt>
mov    %eax,-0x40(%rbp)
cmp    $0xffffffff,%eax
je     12c1 <main+0xf1>
mov    -0x40(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x31,%eax
ja     12a7 <main+0xd7>
mov    -0x48(%rbp),%rax
lea    0xdb5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    12bc <main+0xec>
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    12bc <main+0xec>
mov    $0x0,%al
call   10b0 <usage@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12bc <main+0xec>
jmp    12a7 <main+0xd7>
mov    $0x0,%al
call   10b0 <usage@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    120c <main+0x3c>
mov    0x2d18(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d04(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     130a <main+0x13a>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
call   1090 <fprintf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1325 <main+0x155>
lea    0xdef(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1366 <main+0x196>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10e0 <getline@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    13a6 <main+0x1d6>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2c29(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x1,-0x14(%rbp)
jne    13df <main+0x20f>
mov    -0x30(%rbp),%rdi
call   1040 <decrypt@plt>
jmp    13f7 <main+0x227>
cmpl   $0x1,-0x18(%rbp)
jne    13f2 <main+0x222>
mov    -0x30(%rbp),%rdi
call   1080 <encrypt@plt>
jmp    13f7 <main+0x227>
mov    $0x0,%al
call   10a0 <EVP_cleanup@plt>
cmpq   $0x0,-0x30(%rbp)
je     1412 <main+0x242>
mov    -0x30(%rbp),%rdi
call   1050 <free@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0xffffffff,0x4(%rsp)
ff
xor    %r14d,%r14d
lea    0xdf9(%rip),%r15
mov    0x2dea(%rip),%r12
mov    $0xffffffff,%r13d
jmp    1224 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%r14
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10d0 <getopt@plt>
cmp    $0x70,%eax
je     1220 <main+0x50>
cmp    $0x64,%eax
jg     1259 <main+0x89>
cmp    $0xffffffff,%eax
je     126f <main+0x9f>
cmp    $0x64,%eax
jne    1359 <main+0x189>
mov    $0x1,%r13d
movl   $0x0,0x4(%rsp)
jmp    1224 <main+0x54>
cmp    $0x65,%eax
jne    133f <main+0x16f>
xor    %r13d,%r13d
movl   $0x1,0x4(%rsp)
jmp    1224 <main+0x54>
mov    0x2d6a(%rip),%rax
cmp    %ebp,(%rax)
je     128f <main+0xbf>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
call   1090 <fprintf@plt>
test   %r14,%r14
jne    12a3 <main+0xd3>
lea    0xda8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xda2(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     136e <main+0x19e>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   10e0 <getline@plt>
cmp    $0xffffffff,%eax
je     1380 <main+0x1b0>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
cmp    $0x1,%r13d
jne    12ff <main+0x12f>
mov    0x8(%rsp),%rdi
call   1040 <decrypt@plt>
jmp    1310 <main+0x140>
cmpl   $0x1,0x4(%rsp)
jne    1310 <main+0x140>
mov    0x8(%rsp),%rdi
call   1080 <encrypt@plt>
xor    %eax,%eax
call   10a0 <EVP_cleanup@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1326 <main+0x156>
call   1050 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x68,%eax
jne    1359 <main+0x189>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
lea    0xcd1(%rip),%rsi
jmp    1390 <main+0x1c0>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
lea    0xcd9(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1360 <main+0x190>

LLVM IR (-O0):
@.str = [6 x i8] c"dehp:\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@optind = global i64 0
@stderr = global i32 0
@.str.1 = [61 x i8] c"There are more arguments than needed, they will be ignored.\0A\00"
@.str.2 = [9 x i8] c"AED_PASS\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [26 x i8] c"Cannot open passin file!\0A\00"
@.str.5 = [26 x i8] c"Cannot read passin file!\0A\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 i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i8* null, i8** %8
store i8* null, i8** %10
store i64 0, i64* %11
br label %14
14: ; preds = %34, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %13
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %35
19: ; preds = %14
%20 = load i32, i32* %13
switch i32 %20, label %30 [
i32 100, label %21
i32 101, label %22
i32 104, label %23
i32 112, label %27
i32 63, label %29
]
21: ; preds = %19
store i32 1, i32* %6
store i32 0, i32* %7
br label %34
22: ; preds = %19
store i32 1, i32* %7
store i32 0, i32* %6
br label %34
23: ; preds = %19
%24 = call i32 (...) @usage()
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
%28 = load i8*, i8** @optarg
store i8* %28, i8** %8
br label %34
29: ; preds = %19
br label %30
30: ; preds = %19, %29
%31 = call i32 (...) @usage()
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %27, %22, %21
br label %14
35: ; preds = %14
%36 = load i64, i64* @optind
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = sub nsw i64 %38, %36
%40 = trunc i64 %39 to i32
store i32 %40, i32* %4
%41 = load i64, i64* @optind
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 %41
store i8** %43, i8*** %5
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %35
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %46, %35
%50 = load i8*, i8** %8
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i8* %53, i8** %8
br label %54
54: ; preds = %52, %49
%55 = load i8*, i8** %8
%56 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %56, i32** %9
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %54
%64 = load i32*, i32** %9
%65 = call i32 @getline(i8** %10, i64* %11, i32* %64)
store i32 %65, i32* %12
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %72
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %63
%73 = load i8*, i8** %10
%74 = load i8*, i8** %10
%75 = call i32 @strlen(i8* %74)
%76 = sub nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %73, i64 %77
store i8 0, i8* %78
%79 = load i32, i32* %6
%80 = icmp eq i32 %79, 1
br i1 %80, label %81, label %84
81: ; preds = %72
%82 = load i8*, i8** %10
%83 = call i32 @decrypt(i8* %82)
br label %91
84: ; preds = %72
%85 = load i32, i32* %7
%86 = icmp eq i32 %85, 1
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = load i8*, i8** %10
%89 = call i32 @encrypt(i8* %88)
br label %90
90: ; preds = %87, %84
br label %91
91: ; preds = %90, %81
%92 = call i32 (...) @EVP_cleanup()
%93 = load i8*, i8** %10
%94 = icmp ne i8* %93, null
br i1 %94, label %95, label %98
95: ; preds = %91
%96 = load i8*, i8** %10
%97 = call i32 @free(i8* %96)
br label %98
98: ; preds = %95, %91
%99 = load i32*, i32** %9
%100 = call i32 @fclose(i32* %99)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"dehp:\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@optind = global i64 0
@stderr = global i32 0
@.str.1 = [61 x i8] c"There are more arguments than needed, they will be ignored.\0A\00"
@.str.2 = [9 x i8] c"AED_PASS\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [26 x i8] c"Cannot open passin file!\0A\00"
@.str.5 = [26 x i8] c"Cannot read passin file!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
br label %7
7: ; preds = %15, %2
%8 = phi i32 [ -1, %2 ], [ %16, %15 ]
%9 = phi i8* [ null, %2 ], [ %12, %15 ]
%10 = phi i32 [ -1, %2 ], [ %17, %15 ]
br label %11
11: ; preds = %7, %22
%12 = phi i8* [ %23, %22 ], [ %9, %7 ]
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %24 [
i32 -1, label %28
i32 100, label %15
i32 101, label %14
i32 104, label %18
i32 112, label %22
]
14: ; preds = %11
br label %15
15: ; preds = %11, %14
%16 = phi i32 [ 1, %14 ], [ 0, %11 ]
%17 = phi i32 [ 0, %14 ], [ 1, %11 ]
br label %7
18: ; preds = %11
%19 = tail call i32 (...) @usage()
%20 = load i32, i32* @EXIT_SUCCESS
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %11
%23 = load i8*, i8** @optarg
br label %11
24: ; preds = %11
%25 = tail call i32 (...) @usage()
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %11
%29 = load i64, i64* @optind
%30 = trunc i64 %29 to i32
%31 = icmp eq i32 %30, %0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %32, %28
%36 = icmp eq i8* %12, null
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %35
%40 = phi i8* [ %38, %37 ], [ %12, %35 ]
%41 = tail call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = tail call i32 @exit(i32 %46)
unreachable
48: ; preds = %39
%49 = call i32 @getline(i8** %3, i64* %4, i32* %41)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %48
%57 = load i8*, i8** %3
%58 = call i32 @strlen(i8* %57)
%59 = add nsw i32 %58, -1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
store i8 0, i8* %61
%62 = icmp eq i32 %10, 1
br i1 %62, label %63, label %66
63: ; preds = %56
%64 = load i8*, i8** %3
%65 = call i32 @decrypt(i8* %64)
br label %71
66: ; preds = %56
%67 = icmp eq i32 %8, 1
br i1 %67, label %68, label %71
68: ; preds = %66
%69 = load i8*, i8** %3
%70 = call i32 @encrypt(i8* %69)
br label %71
71: ; preds = %66, %68, %63
%72 = call i32 (...) @EVP_cleanup()
%73 = load i8*, i8** %3
%74 = icmp eq i8* %73, null
br i1 %74, label %77, label %75
75: ; preds = %71
%76 = call i32 @free(i8* %73)
br label %77
77: ; preds = %75, %71
%78 = call i32 @fclose(i32* %41)
ret i32 0
}