#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*/ uint8_t;
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ EVP_CIPHER_CTX;

/* Variables and functions */
int /*<<< orphan*/ EVP_CIPHER_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_CIPHER_CTX_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_CIPHER_CTX_new();
int /*<<< orphan*/ EVP_DecryptFinal_ex(int /*<<< orphan*/ *, unsigned char *,
                                       int *);
int /*<<< orphan*/ EVP_DecryptInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DecryptUpdate(int /*<<< orphan*/ *, unsigned char *,
                                     int *, unsigned char *, scalar_t__);
int /*<<< orphan*/ EVP_des_ede3_cbc();
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int kdf_simple(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, unsigned char *, int);
int /*<<< orphan*/ untwist(unsigned char *, int);
scalar_t__ write(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int declen, infd, outfd, ret;
  ssize_t sret;
  uint8_t keybuffer[24], ivbuffer[8];
  unsigned char buf[4096], decbuf[4096];
  EVP_CIPHER_CTX *ectx;
  if (argc < 3) {
    errx(EXIT_FAILURE, "<xb24_15_4_ABCD.ehx> <out.hex>");
  }
  if ((infd = open(argv[1], O_RDONLY)) < 0) {
    err(EXIT_FAILURE, "open");
  }
  if ((outfd = creat(argv[2], S_IRUSR | S_IWUSR)) < 0) {
    err(EXIT_FAILURE, "creat");
  }
  if ((ret = kdf_simple(keybuffer, ivbuffer)) < 0) {
    return ret;
  }
  if ((sret = read(infd, buf, 4)) < 0) {
    err(EXIT_FAILURE, "read");
  }
  if ((ectx = EVP_CIPHER_CTX_new()) == NULL) {
    err(EXIT_FAILURE, "EVP_CIPHER_CTX_new");
  }
  EVP_CIPHER_CTX_init(ectx);
  EVP_DecryptInit_ex(ectx, EVP_des_ede3_cbc(), NULL, keybuffer, ivbuffer);
  while (infd > 0) {
    if ((sret = read(infd, buf, sizeof(buf))) < 0) {
      err(EXIT_FAILURE, "read");
    }
    if (!sret) {
      close(infd);
      infd = -1;
      if (!EVP_DecryptFinal_ex(ectx, decbuf, &declen)) {
        errx(EXIT_FAILURE, "EVP_DecryptFinal_ex");
      }
    } else {
      if (!EVP_DecryptUpdate(ectx, decbuf, &declen, buf, sret)) {
        errx(EXIT_FAILURE, "EVP_DecryptUpdate");
      }
    }
    untwist(decbuf, declen);
    if ((sret = write(outfd, decbuf, declen)) < 0) {
      err(EXIT_FAILURE, "write");
    }
  }
  EVP_CIPHER_CTX_free(ectx);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1238 <main+0x38>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
call   1050 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    126f <main+0x6f>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
call   10c0 <err@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
mov    0x2d59(%rip),%rax
or     (%rax),%esi
call   1110 <creat@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12af <main+0xaf>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
call   10c0 <err@plt>
lea    -0x90(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   10a0 <kdf_simple@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    12d9 <main+0xd9>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14b9 <main+0x2b9>
mov    -0x18(%rbp),%edi
lea    -0x10b0(%rbp),%rsi
mov    $0x4,%edx
call   1090 <read@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    1310 <main+0x110>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xd1f(%rip),%rsi
call   10c0 <err@plt>
mov    $0x0,%al
call   10e0 <EVP_CIPHER_CTX_new@plt>
mov    %rax,-0x20b8(%rbp)
cmp    $0x0,%rax
jne    133d <main+0x13d>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
lea    0xcf7(%rip),%rsi
call   10c0 <err@plt>
mov    -0x20b8(%rbp),%rdi
call   1080 <EVP_CIPHER_CTX_init@plt>
mov    -0x20b8(%rbp),%rax
mov    %rax,-0x20c0(%rbp)
mov    $0x0,%al
call   10f0 <EVP_des_ede3_cbc@plt>
mov    -0x20c0(%rbp),%rdi
mov    %eax,%esi
lea    -0x90(%rbp),%rcx
lea    -0xb0(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
call   10d0 <EVP_DecryptInit_ex@plt>
cmpl   $0x0,-0x18(%rbp)
jle    14a1 <main+0x2a1>
mov    -0x18(%rbp),%edi
lea    -0x10b0(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    13bf <main+0x1bf>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
lea    0xc70(%rip),%rsi
call   10c0 <err@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1413 <main+0x213>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x18(%rbp)
mov    -0x20b8(%rbp),%rdi
lea    -0x20b0(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <EVP_DecryptFinal_ex@plt>
cmp    $0x0,%eax
jne    140e <main+0x20e>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
lea    0xc39(%rip),%rsi
call   1050 <errx@plt>
jmp    1458 <main+0x258>
mov    -0x20b8(%rbp),%rdi
lea    -0x20b0(%rbp),%rsi
lea    -0x10b0(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    -0x14(%rbp),%rdx
call   1120 <EVP_DecryptUpdate@plt>
cmp    $0x0,%eax
jne    1453 <main+0x253>
mov    0x2b8b(%rip),%rax
mov    (%rax),%edi
lea    0xc08(%rip),%rsi
call   1050 <errx@plt>
jmp    1458 <main+0x258>
lea    -0x20b0(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <untwist@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20b0(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <write@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    149c <main+0x29c>
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
lea    0xbd1(%rip),%rsi
call   10c0 <err@plt>
jmp    137e <main+0x17e>
mov    -0x20b8(%rbp),%rdi
call   10b0 <EVP_CIPHER_CTX_free@plt>
mov    0x2b0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2098,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jg     122e <main+0x2e>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1050 <errx@plt>
mov    0x8(%rbp),%rdi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    125b <main+0x5b>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
call   10c0 <err@plt>
mov    0x10(%rbp),%rdi
mov    0x2d62(%rip),%rax
mov    0x2d73(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1110 <creat@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1292 <main+0x92>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
call   10c0 <err@plt>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <kdf_simple@plt>
test   %eax,%eax
js     142e <main+0x22e>
lea    0x90(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1090 <read@plt>
test   %rax,%rax
jns    12d7 <main+0xd7>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
call   10c0 <err@plt>
xor    %eax,%eax
call   10e0 <EVP_CIPHER_CTX_new@plt>
mov    %rax,%r13
test   %rax,%rax
jne    12fb <main+0xfb>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
lea    0xd39(%rip),%rsi
call   10c0 <err@plt>
mov    %r13,%rdi
call   1080 <EVP_CIPHER_CTX_init@plt>
xor    %eax,%eax
call   10f0 <EVP_des_ede3_cbc@plt>
lea    0x30(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %r13,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <EVP_DecryptInit_ex@plt>
test   %ebx,%ebx
jle    141d <main+0x21d>
lea    0x90(%rsp),%r15
lea    0x1090(%rsp),%rbp
jmp    1368 <main+0x168>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
mov    %rbp,%rdi
call   1060 <untwist@plt>
mov    0xc(%rsp),%edx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1040 <write@plt>
test   %rax,%rax
js     13b0 <main+0x1b0>
test   %ebx,%ebx
jle    141d <main+0x21d>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %rax,%r12
test   %rax,%rax
js     13d0 <main+0x1d0>
jne    13e5 <main+0x1e5>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
lea    0xc(%rsp),%rdx
call   1030 <EVP_DecryptFinal_ex@plt>
mov    $0xffffffff,%ebx
lea    0xc9e(%rip),%rsi
test   %eax,%eax
jne    1340 <main+0x140>
jmp    140a <main+0x20a>
nopw   0x0(%rax,%rax,1)
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
lea    0xca8(%rip),%rsi
call   10c0 <err@plt>
test   %ebx,%ebx
jg     1368 <main+0x168>
jmp    141d <main+0x21d>
nopl   0x0(%rax,%rax,1)
mov    0x2bf9(%rip),%rax
mov    (%rax),%edi
lea    0xc4a(%rip),%rsi
call   10c0 <err@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
lea    0xc(%rsp),%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1120 <EVP_DecryptUpdate@plt>
lea    0xc54(%rip),%rsi
test   %eax,%eax
jne    1340 <main+0x140>
mov    0x2bbf(%rip),%rax
mov    (%rax),%edi
call   1050 <errx@plt>
jmp    1340 <main+0x140>
mov    %r13,%rdi
call   10b0 <EVP_CIPHER_CTX_free@plt>
mov    0x2b94(%rip),%rax
mov    (%rax),%eax
add    $0x2098,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [31 x i8] c"<xb24_15_4_ABCD.ehx> <out.hex>\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [6 x i8] c"creat\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [19 x i8] c"EVP_CIPHER_CTX_new\00"
@.str.5 = [20 x i8] c"EVP_DecryptFinal_ex\00"
@.str.6 = [18 x i8] c"EVP_DecryptUpdate\00"
@.str.7 = [6 x i8] c"write\00"
@EXIT_SUCCESS = 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
%10 = alloca i64
%11 = alloca [24 x i32]
%12 = alloca [8 x i32]
%13 = alloca [4096 x i8]
%14 = alloca [4096 x i8]
%15 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @errx(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @err(i32 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %28, %21
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = load i32, i32* @S_IRUSR
%36 = load i32, i32* @S_IWUSR
%37 = or i32 %35, %36
%38 = call i32 @creat(i8* %34, i32 %37)
store i32 %38, i32* %8
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %31
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @err(i32 %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %40, %31
%44 = getelementptr inbounds [24 x i32], [24 x i32]* %11, i64 0, i64 0
%45 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 0
%46 = call i32 @kdf_simple(i32* %44, i32* %45)
store i32 %46, i32* %9
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = load i32, i32* %9
store i32 %49, i32* %3
br label %125
50: ; preds = %43
%51 = load i32, i32* %7
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%53 = call i64 @read(i32 %51, i8* %52, i32 4)
store i64 %53, i64* %10
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @err(i32 %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %55, %50
%59 = call i32* (...) @EVP_CIPHER_CTX_new()
store i32* %59, i32** %15
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @err(i32 %62, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %61, %58
%65 = load i32*, i32** %15
%66 = call i32 @EVP_CIPHER_CTX_init(i32* %65)
%67 = load i32*, i32** %15
%68 = call i32 (...) @EVP_des_ede3_cbc()
%69 = getelementptr inbounds [24 x i32], [24 x i32]* %11, i64 0, i64 0
%70 = getelementptr inbounds [8 x i32], [8 x i32]* %12, i64 0, i64 0
%71 = call i32 @EVP_DecryptInit_ex(i32* %67, i32 %68, i32* null, i32* %69, i32* %70)
br label %72
72: ; preds = %120, %64
%73 = load i32, i32* %7
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %121
75: ; preds = %72
%76 = load i32, i32* %7
%77 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%78 = call i64 @read(i32 %76, i8* %77, i32 4096)
store i64 %78, i64* %10
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %75
%81 = load i32, i32* @EXIT_FAILURE
%82 = call i32 @err(i32 %81, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %83
83: ; preds = %80, %75
%84 = load i64, i64* %10
%85 = icmp ne i64 %84, 0
br i1 %85, label %97, label %86
86: ; preds = %83
%87 = load i32, i32* %7
%88 = call i32 @close(i32 %87)
store i32 -1, i32* %7
%89 = load i32*, i32** %15
%90 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%91 = call i32 @EVP_DecryptFinal_ex(i32* %89, i8* %90, i32* %6)
%92 = icmp ne i32 %91, 0
br i1 %92, label %96, label %93
93: ; preds = %86
%94 = load i32, i32* @EXIT_FAILURE
%95 = call i32 @errx(i32 %94, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %96
96: ; preds = %93, %86
br label %108
97: ; preds = %83
%98 = load i32*, i32** %15
%99 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%101 = load i64, i64* %10
%102 = call i32 @EVP_DecryptUpdate(i32* %98, i8* %99, i32* %6, i8* %100, i64 %101)
%103 = icmp ne i32 %102, 0
br i1 %103, label %107, label %104
104: ; preds = %97
%105 = load i32, i32* @EXIT_FAILURE
%106 = call i32 @errx(i32 %105, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %107
107: ; preds = %104, %97
br label %108
108: ; preds = %107, %96
%109 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%110 = load i32, i32* %6
%111 = call i32 @untwist(i8* %109, i32 %110)
%112 = load i32, i32* %8
%113 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%114 = load i32, i32* %6
%115 = call i64 @write(i32 %112, i8* %113, i32 %114)
store i64 %115, i64* %10
%116 = icmp slt i64 %115, 0
br i1 %116, label %117, label %120
117: ; preds = %108
%118 = load i32, i32* @EXIT_FAILURE
%119 = call i32 @err(i32 %118, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %120
120: ; preds = %117, %108
br label %72
121: ; preds = %72
%122 = load i32*, i32** %15
%123 = call i32 @EVP_CIPHER_CTX_free(i32* %122)
%124 = load i32, i32* @EXIT_SUCCESS
store i32 %124, i32* %3
br label %125
125: ; preds = %121, %48
%126 = load i32, i32* %3
ret i32 %126
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [31 x i8] c"<xb24_15_4_ABCD.ehx> <out.hex>\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.2 = [6 x i8] c"creat\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [19 x i8] c"EVP_CIPHER_CTX_new\00"
@.str.5 = [20 x i8] c"EVP_DecryptFinal_ex\00"
@.str.6 = [18 x i8] c"EVP_DecryptUpdate\00"
@.str.7 = [6 x i8] c"write\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [24 x i32]
%5 = alloca [8 x i32]
%6 = alloca [4096 x i8]
%7 = alloca [4096 x i8]
%8 = bitcast i32* %3 to i8*
%9 = bitcast [24 x i32]* %4 to i8*
%10 = bitcast [8 x i32]* %5 to i8*
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%13 = icmp slt i32 %0, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @errx(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 @open(i8* %19, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @err(i32 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %23, %17
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = load i32, i32* @S_IRUSR
%30 = load i32, i32* @S_IWUSR
%31 = or i32 %30, %29
%32 = tail call i32 @creat(i8* %28, i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @err(i32 %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %34, %26
%38 = getelementptr inbounds [24 x i32], [24 x i32]* %4, i64 0, i64 0
%39 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%40 = call i32 @kdf_simple(i32* %38, i32* %39)
%41 = icmp slt i32 %40, 0
br i1 %41, label %95, label %42
42: ; preds = %37
%43 = call i64 @read(i32 %21, i8* %11, i32 4)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @err(i32 %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %45, %42
%49 = call i32* (...) @EVP_CIPHER_CTX_new()
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @err(i32 %52, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %51, %48
%55 = call i32 @EVP_CIPHER_CTX_init(i32* %49)
%56 = call i32 (...) @EVP_des_ede3_cbc()
%57 = call i32 @EVP_DecryptInit_ex(i32* %49, i32 %56, i32* null, i32* %38, i32* %39)
%58 = icmp sgt i32 %21, 0
br i1 %58, label %59, label %92
59: ; preds = %54, %90
%60 = phi i32 [ %81, %90 ], [ %21, %54 ]
%61 = call i64 @read(i32 %60, i8* %11, i32 4096)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @err(i32 %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %72
66: ; preds = %59
%67 = icmp eq i64 %61, 0
br i1 %67, label %68, label %72
68: ; preds = %66
%69 = call i32 @close(i32 %60)
%70 = call i32 @EVP_DecryptFinal_ex(i32* %49, i8* %12, i32* %3)
%71 = icmp eq i32 %70, 0
br i1 %71, label %75, label %80
72: ; preds = %63, %66
%73 = call i32 @EVP_DecryptUpdate(i32* %49, i8* %12, i32* %3, i8* %11, i64 %61)
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %80
75: ; preds = %72, %68
%76 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), %68 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), %72 ]
%77 = phi i32 [ -1, %68 ], [ %60, %72 ]
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @errx(i32 %78, i8* %76)
br label %80
80: ; preds = %75, %72, %68
%81 = phi i32 [ %60, %72 ], [ -1, %68 ], [ %77, %75 ]
%82 = load i32, i32* %3
%83 = call i32 @untwist(i8* %12, i32 %82)
%84 = load i32, i32* %3
%85 = call i64 @write(i32 %32, i8* %12, i32 %84)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %80
%88 = load i32, i32* @EXIT_FAILURE
%89 = call i32 @err(i32 %88, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %90
90: ; preds = %87, %80
%91 = icmp sgt i32 %81, 0
br i1 %91, label %59, label %92
92: ; preds = %90, %54
%93 = call i32 @EVP_CIPHER_CTX_free(i32* %49)
%94 = load i32, i32* @EXIT_SUCCESS
br label %95
95: ; preds = %37, %92
%96 = phi i32 [ %94, %92 ], [ %40, %37 ]
ret i32 %96
}