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

/* Variables and functions */
int /*<<< orphan*/ EVP_CIPHER_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_CIPHER_CTX_new();
int /*<<< orphan*/ EVP_DecryptFinal_ex(int /*<<< orphan*/ *, int *, int *);
int /*<<< orphan*/ EVP_DecryptInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *, int *, int *);
int /*<<< orphan*/ EVP_DecryptUpdate(int /*<<< orphan*/ *, int *, int *, int *,
                                     int);
int /*<<< orphan*/ EVP_des_ede3_cbc();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ stderr;
int apple_des3_ede_unwrap_key(uint8_t *wrapped_key, int wrapped_key_len,
                              uint8_t *decryptKey, uint8_t *unwrapped_key) {
  EVP_CIPHER_CTX *ctx;
  ctx = EVP_CIPHER_CTX_new();
  uint8_t *TEMP1, *TEMP2, *CEKICV;
  uint8_t IV[8] = {0x4a, 0xdd, 0xa2, 0x2c, 0x79, 0xe8, 0x21, 0x05};
  int outlen, tmplen, i;
  TEMP1 = malloc(wrapped_key_len);
  TEMP2 = malloc(wrapped_key_len);
  CEKICV = malloc(wrapped_key_len);
  EVP_DecryptInit_ex(ctx, EVP_des_ede3_cbc(), NULL, decryptKey, IV);
  if (!EVP_DecryptUpdate(ctx, TEMP1, &outlen, wrapped_key, wrapped_key_len)) {
    fprintf(stderr, "internal error (1) during key unwrap operation!\n");
    return (-1);
  }
  if (!EVP_DecryptFinal_ex(ctx, TEMP1 + outlen, &tmplen)) {
    fprintf(stderr, "internal error (2) during key unwrap operation!\n");
    return (-1);
  }
  outlen += tmplen;
  EVP_CIPHER_CTX_free(ctx);
  for (i = 0; i < outlen; i++)
    TEMP2[i] = TEMP1[outlen - i - 1];
  ctx = EVP_CIPHER_CTX_new();
  EVP_DecryptInit_ex(ctx, EVP_des_ede3_cbc(), NULL, decryptKey, TEMP2);
  if (!EVP_DecryptUpdate(ctx, CEKICV, &outlen, TEMP2 + 8, outlen - 8)) {
    fprintf(stderr, "internal error (3) during key unwrap operation!\n");
    return (-1);
  }
  if (!EVP_DecryptFinal_ex(ctx, CEKICV + outlen, &tmplen)) {
    fprintf(stderr, "internal error (4) during key unwrap operation!\n");
    return (-1);
  }
  outlen += tmplen;
  EVP_CIPHER_CTX_free(ctx);
  memcpy(unwrapped_key, CEKICV + 4, outlen - 4);
  free(TEMP1);
  free(TEMP2);
  free(CEKICV);
  return (0);
}


x86 assembly (clang, -O0):
<apple_des3_ede_unwrap_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x0,%al
call   10a0 <EVP_CIPHER_CTX_new@plt>
mov    %rax,-0x30(%rbp)
mov    0xe34(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xe31(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0xe2e(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe2b(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    $0x0,%al
call   10b0 <EVP_des_ede3_cbc@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rcx
lea    -0x70(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
call   1090 <EVP_DecryptInit_ex@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
lea    -0x74(%rbp),%rdx
call   10c0 <EVP_DecryptUpdate@plt>
cmp    $0x0,%eax
jne    1284 <apple_des3_ede_unwrap_key+0xe4>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    142e <apple_des3_ede_unwrap_key+0x28e>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
movslq -0x74(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    -0x78(%rbp),%rdx
call   1030 <EVP_DecryptFinal_ex@plt>
cmp    $0x0,%eax
jne    12ca <apple_des3_ede_unwrap_key+0x12a>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    142e <apple_des3_ede_unwrap_key+0x28e>
mov    -0x78(%rbp),%eax
add    -0x74(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <EVP_CIPHER_CTX_free@plt>
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    131b <apple_des3_ede_unwrap_key+0x17b>
mov    -0x38(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    -0x7c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x40(%rbp),%rax
movslq -0x7c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    12e3 <apple_des3_ede_unwrap_key+0x143>
mov    $0x0,%al
call   10a0 <EVP_CIPHER_CTX_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    $0x0,%al
call   10b0 <EVP_des_ede3_cbc@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rcx
mov    -0x40(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edx
call   1090 <EVP_DecryptInit_ex@plt>
mov    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rcx
add    $0x20,%rcx
mov    -0x74(%rbp),%r8d
sub    $0x8,%r8d
lea    -0x74(%rbp),%rdx
call   10c0 <EVP_DecryptUpdate@plt>
cmp    $0x0,%eax
jne    139d <apple_des3_ede_unwrap_key+0x1fd>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
lea    0xcf6(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    142e <apple_des3_ede_unwrap_key+0x28e>
mov    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rsi
movslq -0x74(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    -0x78(%rbp),%rdx
call   1030 <EVP_DecryptFinal_ex@plt>
cmp    $0x0,%eax
jne    13e3 <apple_des3_ede_unwrap_key+0x243>
mov    0x2c17(%rip),%rax
mov    (%rax),%edi
lea    0xce1(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    142e <apple_des3_ede_unwrap_key+0x28e>
mov    -0x78(%rbp),%eax
add    -0x74(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <EVP_CIPHER_CTX_free@plt>
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rsi
add    $0x10,%rsi
mov    -0x74(%rbp),%edx
sub    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x48(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apple_des3_ede_unwrap_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdx,%r13
mov    %esi,%r14d
mov    %rdi,%r12
xor    %eax,%eax
call   10a0 <EVP_CIPHER_CTX_new@plt>
mov    %rax,%rbp
movaps 0xe43(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movdqa 0xe26(%rip),%xmm0
movdqa %xmm0,0x20(%rsp)
mov    %r14d,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %r14d,%edi
call   1080 <malloc@plt>
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   10b0 <EVP_des_ede3_cbc@plt>
lea    0x20(%rsp),%r8
mov    %rbp,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    %r13,0x18(%rsp)
mov    %r13,%rcx
call   1090 <EVP_DecryptInit_ex@plt>
mov    %rsp,%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
mov    %r14d,%r8d
call   10c0 <EVP_DecryptUpdate@plt>
test   %eax,%eax
je     12f7 <apple_des3_ede_unwrap_key+0x157>
movslq (%rsp),%rax
lea    (%rbx,%rax,4),%rsi
lea    0x4(%rsp),%rdx
mov    %rbp,%rdi
call   1030 <EVP_DecryptFinal_ex@plt>
test   %eax,%eax
je     130c <apple_des3_ede_unwrap_key+0x16c>
mov    0x4(%rsp),%eax
add    %eax,(%rsp)
mov    %rbp,%rdi
call   1050 <EVP_CIPHER_CTX_free@plt>
mov    (%rsp),%eax
test   %eax,%eax
mov    0x10(%rsp),%r14
jle    1408 <apple_des3_ede_unwrap_key+0x268>
cmp    $0x8,%eax
jae    1321 <apple_des3_ede_unwrap_key+0x181>
xor    %ecx,%ecx
mov    %rcx,%rdx
not    %rdx
test   $0x1,%al
je     12a4 <apple_des3_ede_unwrap_key+0x104>
mov    %ecx,%esi
not    %esi
add    %eax,%esi
movslq %esi,%rsi
mov    (%rbx,%rsi,4),%esi
mov    %esi,(%r15,%rcx,4)
or     $0x1,%rcx
add    %rax,%rdx
je     1408 <apple_des3_ede_unwrap_key+0x268>
mov    %eax,%esi
sub    %rcx,%rax
mov    %ecx,%edx
not    %edx
add    %esi,%edx
lea    (%r15,%rcx,4),%rcx
add    $0x4,%rcx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %edx,%rdx
mov    (%rbx,%rdx,4),%edi
mov    %edi,-0x4(%rcx,%rsi,4)
lea    -0x1(%rdx),%edi
movslq %edi,%rdi
mov    (%rbx,%rdi,4),%edi
mov    %edi,(%rcx,%rsi,4)
add    $0x2,%rsi
add    $0xfffffffe,%edx
cmp    %rsi,%rax
jne    12d0 <apple_des3_ede_unwrap_key+0x130>
jmp    1408 <apple_des3_ede_unwrap_key+0x268>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
lea    0xd19(%rip),%rsi
jmp    14cb <apple_des3_ede_unwrap_key+0x32b>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
jmp    14cb <apple_des3_ede_unwrap_key+0x32b>
lea    -0x1(%rax),%rdx
lea    -0x1(%rax),%esi
mov    %esi,%edi
sub    %edx,%edi
xor    %ecx,%ecx
cmp    %esi,%edi
jg     1286 <apple_des3_ede_unwrap_key+0xe6>
shr    $0x20,%rdx
jne    1286 <apple_des3_ede_unwrap_key+0xe6>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
lea    -0x8(%rcx),%rdx
mov    %rdx,%r8
shr    $0x3,%r8
add    $0x1,%r8
test   %rdx,%rdx
je     14e4 <apple_des3_ede_unwrap_key+0x344>
mov    %r8,%rdi
and    $0xfffffffffffffffe,%rdi
lea    -0x9(%rax),%ebp
xor    %edx,%edx
nopl   0x0(%rax)
lea    0x8(%rbp),%esi
movslq %esi,%rsi
movdqu -0x1c(%rbx,%rsi,4),%xmm0
movdqu -0xc(%rbx,%rsi,4),%xmm1
pshufd $0x1b,%xmm1,%xmm1
pshufd $0x1b,%xmm0,%xmm0
movdqu %xmm1,(%r15,%rdx,4)
movdqu %xmm0,0x10(%r15,%rdx,4)
movslq %ebp,%rbp
movdqu -0x1c(%rbx,%rbp,4),%xmm0
movdqu -0xc(%rbx,%rbp,4),%xmm1
pshufd $0x1b,%xmm1,%xmm1
pshufd $0x1b,%xmm0,%xmm0
movdqu %xmm1,0x20(%r15,%rdx,4)
movdqu %xmm0,0x30(%r15,%rdx,4)
add    $0x10,%rdx
add    $0xfffffff0,%ebp
add    $0xfffffffffffffffe,%rdi
jne    1370 <apple_des3_ede_unwrap_key+0x1d0>
test   $0x1,%r8b
je     13ff <apple_des3_ede_unwrap_key+0x25f>
mov    %edx,%esi
not    %esi
add    %eax,%esi
movslq %esi,%rsi
movdqu -0x1c(%rbx,%rsi,4),%xmm0
movdqu -0xc(%rbx,%rsi,4),%xmm1
pshufd $0x1b,%xmm1,%xmm1
pshufd $0x1b,%xmm0,%xmm0
movdqu %xmm1,(%r15,%rdx,4)
movdqu %xmm0,0x10(%r15,%rdx,4)
cmp    %rax,%rcx
jne    1286 <apple_des3_ede_unwrap_key+0xe6>
xor    %eax,%eax
call   10a0 <EVP_CIPHER_CTX_new@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   10b0 <EVP_des_ede3_cbc@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    0x18(%rsp),%rcx
mov    %r15,%r8
call   1090 <EVP_DecryptInit_ex@plt>
mov    %r15,%rcx
add    $0x20,%rcx
mov    (%rsp),%r8d
add    $0xfffffff8,%r8d
mov    %rsp,%rdx
mov    %rbp,%rdi
mov    %r14,%rsi
call   10c0 <EVP_DecryptUpdate@plt>
test   %eax,%eax
je     14a9 <apple_des3_ede_unwrap_key+0x309>
movslq (%rsp),%rax
lea    (%r14,%rax,4),%rsi
lea    0x4(%rsp),%rdx
mov    %rbp,%rdi
call   1030 <EVP_DecryptFinal_ex@plt>
test   %eax,%eax
je     14bb <apple_des3_ede_unwrap_key+0x31b>
mov    0x4(%rsp),%eax
add    %eax,(%rsp)
mov    %rbp,%rdi
call   1050 <EVP_CIPHER_CTX_free@plt>
mov    %r14,%rsi
add    $0x10,%rsi
mov    (%rsp),%edx
add    $0xfffffffc,%edx
mov    0x8(%rsp),%rdi
call   1070 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    14d5 <apple_des3_ede_unwrap_key+0x335>
mov    0x2b30(%rip),%rax
mov    (%rax),%edi
lea    0xbc9(%rip),%rsi
jmp    14cb <apple_des3_ede_unwrap_key+0x32b>
mov    0x2b1e(%rip),%rax
mov    (%rax),%edi
lea    0xbe8(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    13d3 <apple_des3_ede_unwrap_key+0x233>
jmp    13ff <apple_des3_ede_unwrap_key+0x25f>

LLVM IR (-O0):
@__const.apple_des3_ede_unwrap_key.IV = [8 x i32] [i32 74, i32 221, i32 162, i32 44, i32 121, i32 232, i32 33, i32 5]
@stderr = global i32 0
@.str = [49 x i8] c"internal error (1) during key unwrap operation!\0A\00"
@.str.1 = [49 x i8] c"internal error (2) during key unwrap operation!\0A\00"
@.str.2 = [49 x i8] c"internal error (3) during key unwrap operation!\0A\00"
@.str.3 = [49 x i8] c"internal error (4) during key unwrap operation!\0A\00"
define i32 @apple_des3_ede_unwrap_key(i32* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca [8 x i32]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%18 = call i32* (...) @EVP_CIPHER_CTX_new()
store i32* %18, i32** %10
%19 = bitcast [8 x i32]* %14 to i8*
%20 = load i32, i32* %7
%21 = call i32* @malloc(i32 %20)
store i32* %21, i32** %11
%22 = load i32, i32* %7
%23 = call i32* @malloc(i32 %22)
store i32* %23, i32** %12
%24 = load i32, i32* %7
%25 = call i32* @malloc(i32 %24)
store i32* %25, i32** %13
%26 = load i32*, i32** %10
%27 = call i32 (...) @EVP_des_ede3_cbc()
%28 = load i32*, i32** %8
%29 = getelementptr inbounds [8 x i32], [8 x i32]* %14, i64 0, i64 0
%30 = call i32 @EVP_DecryptInit_ex(i32* %26, i32 %27, i32* null, i32* %28, i32* %29)
%31 = load i32*, i32** %10
%32 = load i32*, i32** %11
%33 = load i32*, i32** %6
%34 = load i32, i32* %7
%35 = call i32 @EVP_DecryptUpdate(i32* %31, i32* %32, i32* %15, i32* %33, i32 %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %4
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %124
40: ; preds = %4
%41 = load i32*, i32** %10
%42 = load i32*, i32** %11
%43 = load i32, i32* %15
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = call i32 @EVP_DecryptFinal_ex(i32* %41, i32* %45, i32* %16)
%47 = icmp ne i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %40
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %124
51: ; preds = %40
%52 = load i32, i32* %16
%53 = load i32, i32* %15
%54 = add nsw i32 %53, %52
store i32 %54, i32* %15
%55 = load i32*, i32** %10
%56 = call i32 @EVP_CIPHER_CTX_free(i32* %55)
store i32 0, i32* %17
br label %57
57: ; preds = %74, %51
%58 = load i32, i32* %17
%59 = load i32, i32* %15
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %77
61: ; preds = %57
%62 = load i32*, i32** %11
%63 = load i32, i32* %15
%64 = load i32, i32* %17
%65 = sub nsw i32 %63, %64
%66 = sub nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %62, i64 %67
%69 = load i32, i32* %68
%70 = load i32*, i32** %12
%71 = load i32, i32* %17
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
store i32 %69, i32* %73
br label %74
74: ; preds = %61
%75 = load i32, i32* %17
%76 = add nsw i32 %75, 1
store i32 %76, i32* %17
br label %57
77: ; preds = %57
%78 = call i32* (...) @EVP_CIPHER_CTX_new()
store i32* %78, i32** %10
%79 = load i32*, i32** %10
%80 = call i32 (...) @EVP_des_ede3_cbc()
%81 = load i32*, i32** %8
%82 = load i32*, i32** %12
%83 = call i32 @EVP_DecryptInit_ex(i32* %79, i32 %80, i32* null, i32* %81, i32* %82)
%84 = load i32*, i32** %10
%85 = load i32*, i32** %13
%86 = load i32*, i32** %12
%87 = getelementptr inbounds i32, i32* %86, i64 8
%88 = load i32, i32* %15
%89 = sub nsw i32 %88, 8
%90 = call i32 @EVP_DecryptUpdate(i32* %84, i32* %85, i32* %15, i32* %87, i32 %89)
%91 = icmp ne i32 %90, 0
br i1 %91, label %95, label %92
92: ; preds = %77
%93 = load i32, i32* @stderr
%94 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %124
95: ; preds = %77
%96 = load i32*, i32** %10
%97 = load i32*, i32** %13
%98 = load i32, i32* %15
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i32, i32* %97, i64 %99
%101 = call i32 @EVP_DecryptFinal_ex(i32* %96, i32* %100, i32* %16)
%102 = icmp ne i32 %101, 0
br i1 %102, label %106, label %103
103: ; preds = %95
%104 = load i32, i32* @stderr
%105 = call i32 @fprintf(i32 %104, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %5
br label %124
106: ; preds = %95
%107 = load i32, i32* %16
%108 = load i32, i32* %15
%109 = add nsw i32 %108, %107
store i32 %109, i32* %15
%110 = load i32*, i32** %10
%111 = call i32 @EVP_CIPHER_CTX_free(i32* %110)
%112 = load i32*, i32** %9
%113 = load i32*, i32** %13
%114 = getelementptr inbounds i32, i32* %113, i64 4
%115 = load i32, i32* %15
%116 = sub nsw i32 %115, 4
%117 = call i32 @memcpy(i32* %112, i32* %114, i32 %116)
%118 = load i32*, i32** %11
%119 = call i32 @free(i32* %118)
%120 = load i32*, i32** %12
%121 = call i32 @free(i32* %120)
%122 = load i32*, i32** %13
%123 = call i32 @free(i32* %122)
store i32 0, i32* %5
br label %124
124: ; preds = %106, %103, %92, %48, %37
%125 = load i32, i32* %5
ret i32 %125
}

LLVM IR (-O2):
@__const.apple_des3_ede_unwrap_key.IV = [8 x i32] [i32 74, i32 221, i32 162, i32 44, i32 121, i32 232, i32 33, i32 5]
@stderr = global i32 0
@.str = [49 x i8] c"internal error (1) during key unwrap operation!\0A\00"
@.str.1 = [49 x i8] c"internal error (2) during key unwrap operation!\0A\00"
@.str.2 = [49 x i8] c"internal error (3) during key unwrap operation!\0A\00"
@.str.3 = [49 x i8] c"internal error (4) during key unwrap operation!\0A\00"
define i32 @apple_des3_ede_unwrap_key(i32* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca [8 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = tail call i32* (...) @EVP_CIPHER_CTX_new()
%9 = bitcast [8 x i32]* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = tail call i32* @malloc(i32 %1)
%13 = tail call i32* @malloc(i32 %1)
%14 = tail call i32* @malloc(i32 %1)
%15 = tail call i32 (...) @EVP_des_ede3_cbc()
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %5, i64 0, i64 0
%17 = call i32 @EVP_DecryptInit_ex(i32* %8, i32 %15, i32* null, i32* %2, i32* %16)
%18 = call i32 @EVP_DecryptUpdate(i32* %8, i32* %12, i32* %6, i32* %0, i32 %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %4
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %196
23: ; preds = %4
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %12, i64 %25
%27 = call i32 @EVP_DecryptFinal_ex(i32* %8, i32* %26, i32* %7)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %196
32: ; preds = %23
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = add nsw i32 %34, %33
store i32 %35, i32* %6
%36 = call i32 @EVP_CIPHER_CTX_free(i32* %8)
%37 = load i32, i32* %6
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %163
39: ; preds = %32
%40 = zext i32 %37 to i64
%41 = icmp ult i32 %37, 8
br i1 %41, label %126, label %42
42: ; preds = %39
%43 = add nsw i64 %40, -1
%44 = add i32 %37, -1
%45 = trunc i64 %43 to i32
%46 = sub i32 %44, %45
%47 = icmp sgt i32 %46, %44
%48 = icmp ugt i64 %43, 4294967295
%49 = or i1 %47, %48
br i1 %49, label %126, label %50
50: ; preds = %42
%51 = and i64 %40, 4294967288
%52 = add nsw i64 %51, -8
%53 = lshr exact i64 %52, 3
%54 = add nuw nsw i64 %53, 1
%55 = and i64 %54, 1
%56 = icmp eq i64 %52, 0
br i1 %56, label %102, label %57
57: ; preds = %50
%58 = and i64 %54, 4611686018427387902
br label %59
59: ; preds = %59, %57
%60 = phi i64 [ 0, %57 ], [ %99, %59 ]
%61 = phi i64 [ 0, %57 ], [ %100, %59 ]
%62 = trunc i64 %60 to i32
%63 = xor i32 %62, -1
%64 = add i32 %37, %63
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %12, i64 %65
%67 = getelementptr inbounds i32, i32* %66, i64 -3
%68 = bitcast i32* %67 to <4 x i32>*
%69 = load <4 x i32>, <4 x i32>* %68
%70 = shufflevector <4 x i32> %69, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%71 = getelementptr inbounds i32, i32* %66, i64 -4
%72 = getelementptr inbounds i32, i32* %71, i64 -3
%73 = bitcast i32* %72 to <4 x i32>*
%74 = load <4 x i32>, <4 x i32>* %73
%75 = shufflevector <4 x i32> %74, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%76 = getelementptr inbounds i32, i32* %13, i64 %60
%77 = bitcast i32* %76 to <4 x i32>*
store <4 x i32> %70, <4 x i32>* %77
%78 = getelementptr inbounds i32, i32* %76, i64 4
%79 = bitcast i32* %78 to <4 x i32>*
store <4 x i32> %75, <4 x i32>* %79
%80 = or i64 %60, 8
%81 = trunc i64 %80 to i32
%82 = xor i32 %81, -1
%83 = add i32 %37, %82
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %12, i64 %84
%86 = getelementptr inbounds i32, i32* %85, i64 -3
%87 = bitcast i32* %86 to <4 x i32>*
%88 = load <4 x i32>, <4 x i32>* %87
%89 = shufflevector <4 x i32> %88, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%90 = getelementptr inbounds i32, i32* %85, i64 -4
%91 = getelementptr inbounds i32, i32* %90, i64 -3
%92 = bitcast i32* %91 to <4 x i32>*
%93 = load <4 x i32>, <4 x i32>* %92
%94 = shufflevector <4 x i32> %93, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%95 = getelementptr inbounds i32, i32* %13, i64 %80
%96 = bitcast i32* %95 to <4 x i32>*
store <4 x i32> %89, <4 x i32>* %96
%97 = getelementptr inbounds i32, i32* %95, i64 4
%98 = bitcast i32* %97 to <4 x i32>*
store <4 x i32> %94, <4 x i32>* %98
%99 = add nuw i64 %60, 16
%100 = add i64 %61, 2
%101 = icmp eq i64 %100, %58
br i1 %101, label %102, label %59
102: ; preds = %59, %50
%103 = phi i64 [ 0, %50 ], [ %99, %59 ]
%104 = icmp eq i64 %55, 0
br i1 %104, label %124, label %105
105: ; preds = %102
%106 = trunc i64 %103 to i32
%107 = xor i32 %106, -1
%108 = add i32 %37, %107
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i32, i32* %12, i64 %109
%111 = getelementptr inbounds i32, i32* %110, i64 -3
%112 = bitcast i32* %111 to <4 x i32>*
%113 = load <4 x i32>, <4 x i32>* %112
%114 = shufflevector <4 x i32> %113, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%115 = getelementptr inbounds i32, i32* %110, i64 -4
%116 = getelementptr inbounds i32, i32* %115, i64 -3
%117 = bitcast i32* %116 to <4 x i32>*
%118 = load <4 x i32>, <4 x i32>* %117
%119 = shufflevector <4 x i32> %118, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%120 = getelementptr inbounds i32, i32* %13, i64 %103
%121 = bitcast i32* %120 to <4 x i32>*
store <4 x i32> %114, <4 x i32>* %121
%122 = getelementptr inbounds i32, i32* %120, i64 4
%123 = bitcast i32* %122 to <4 x i32>*
store <4 x i32> %119, <4 x i32>* %123
br label %124
124: ; preds = %102, %105
%125 = icmp eq i64 %51, %40
br i1 %125, label %163, label %126
126: ; preds = %42, %39, %124
%127 = phi i64 [ 0, %42 ], [ 0, %39 ], [ %51, %124 ]
%128 = xor i64 %127, -1
%129 = and i64 %40, 1
%130 = icmp eq i64 %129, 0
br i1 %130, label %140, label %131
131: ; preds = %126
%132 = trunc i64 %127 to i32
%133 = xor i32 %132, -1
%134 = add i32 %37, %133
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i32, i32* %12, i64 %135
%137 = load i32, i32* %136
%138 = getelementptr inbounds i32, i32* %13, i64 %127
store i32 %137, i32* %138
%139 = or i64 %127, 1
br label %140
140: ; preds = %131, %126
%141 = phi i64 [ %127, %126 ], [ %139, %131 ]
%142 = sub nsw i64 0, %40
%143 = icmp eq i64 %128, %142
br i1 %143, label %163, label %144
144: ; preds = %140, %144
%145 = phi i64 [ %161, %144 ], [ %141, %140 ]
%146 = trunc i64 %145 to i32
%147 = xor i32 %146, -1
%148 = add i32 %37, %147
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds i32, i32* %12, i64 %149
%151 = load i32, i32* %150
%152 = getelementptr inbounds i32, i32* %13, i64 %145
store i32 %151, i32* %152
%153 = add nuw nsw i64 %145, 1
%154 = trunc i64 %153 to i32
%155 = xor i32 %154, -1
%156 = add i32 %37, %155
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds i32, i32* %12, i64 %157
%159 = load i32, i32* %158
%160 = getelementptr inbounds i32, i32* %13, i64 %153
store i32 %159, i32* %160
%161 = add nuw nsw i64 %145, 2
%162 = icmp eq i64 %161, %40
br i1 %162, label %163, label %144
163: ; preds = %140, %144, %124, %32
%164 = call i32* (...) @EVP_CIPHER_CTX_new()
%165 = call i32 (...) @EVP_des_ede3_cbc()
%166 = call i32 @EVP_DecryptInit_ex(i32* %164, i32 %165, i32* null, i32* %2, i32* %13)
%167 = getelementptr inbounds i32, i32* %13, i64 8
%168 = load i32, i32* %6
%169 = add nsw i32 %168, -8
%170 = call i32 @EVP_DecryptUpdate(i32* %164, i32* %14, i32* %6, i32* %167, i32 %169)
%171 = icmp eq i32 %170, 0
br i1 %171, label %172, label %175
172: ; preds = %163
%173 = load i32, i32* @stderr
%174 = call i32 @fprintf(i32 %173, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
br label %196
175: ; preds = %163
%176 = load i32, i32* %6
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds i32, i32* %14, i64 %177
%179 = call i32 @EVP_DecryptFinal_ex(i32* %164, i32* %178, i32* %7)
%180 = icmp eq i32 %179, 0
br i1 %180, label %181, label %184
181: ; preds = %175
%182 = load i32, i32* @stderr
%183 = call i32 @fprintf(i32 %182, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %196
184: ; preds = %175
%185 = load i32, i32* %7
%186 = load i32, i32* %6
%187 = add nsw i32 %186, %185
store i32 %187, i32* %6
%188 = call i32 @EVP_CIPHER_CTX_free(i32* %164)
%189 = getelementptr inbounds i32, i32* %14, i64 4
%190 = load i32, i32* %6
%191 = add nsw i32 %190, -4
%192 = call i32 @memcpy(i32* %3, i32* %189, i32 %191)
%193 = call i32 @free(i32* %12)
%194 = call i32 @free(i32* %13)
%195 = call i32 @free(i32* %14)
br label %196
196: ; preds = %184, %181, %172, %29, %20
%197 = phi i32 [ 0, %184 ], [ -1, %181 ], [ -1, %172 ], [ -1, %29 ], [ -1, %20 ]
ret i32 %197
}