#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 */
struct bf_ctx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ debug_save_buffer(char *, char *, unsigned int);
int /*<<< orphan*/ free(char *);
char *malloc(unsigned int);
int /*<<< orphan*/ nbl_decompress(char *, unsigned int, char *, unsigned int);
int /*<<< orphan*/ nbl_decrypt_buffer(struct bf_ctx *, char *, unsigned int);
int /*<<< orphan*/ nbl_decrypt_headers(struct bf_ctx *, char *, int);
int /*<<< orphan*/ nbl_extract_all(char *, char *, char *);
int nbl_get_data_pos(char *);
int nbl_get_tmll_pos(char *);
int /*<<< orphan*/ nbl_has_tmll(char *);
int nbl_is_compressed(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int extract(unsigned int uOptions, char *pstrBuffer, struct bf_ctx *pCtx,
            char *pstrDestPath) {
  char *pstrData;
  int iIsCompressed = 0;
  int iDataPos;
  int iTMLLPos;
  if (pCtx) {
    nbl_decrypt_headers(pCtx, pstrBuffer, 0x30);
    if (uOptions & 0x2)
      debug_save_buffer("decrypt-headers.dbg", pstrBuffer,
                        (*((unsigned int *)(pstrBuffer + 0x08))));
  }
  iDataPos = nbl_get_data_pos(pstrBuffer);
  iIsCompressed = nbl_is_compressed(pstrBuffer);
  if (uOptions & 0x4)
    printf("data=%x, compressed=%x, encrypted=%x\n", iDataPos, iIsCompressed,
           pCtx != NULL);
  if (iIsCompressed) {
    if (pCtx)
      nbl_decrypt_buffer(pCtx, pstrBuffer + iDataPos,
                         (*((unsigned int *)(pstrBuffer + 0x14))));
    if (uOptions & 0x2)
      debug_save_buffer("comp-decrypt.dbg", pstrBuffer + iDataPos,
                        (*((unsigned int *)(pstrBuffer + 0x14))));
    pstrData = malloc((*((unsigned int *)(pstrBuffer + 0x10))));
    if (pstrData == NULL)
      return -3;
    nbl_decompress(pstrBuffer + iDataPos,
                   (*((unsigned int *)(pstrBuffer + 0x14))), pstrData,
                   (*((unsigned int *)(pstrBuffer + 0x10))));
  } else {
    if (pCtx)
      nbl_decrypt_buffer(pCtx, pstrBuffer + iDataPos,
                         (*((unsigned int *)(pstrBuffer + 0x10))));
    pstrData = pstrBuffer + iDataPos;
  }
  if (uOptions & 0x2)
    debug_save_buffer("decomp-decrypt.dbg", pstrData,
                      (*((unsigned int *)(pstrBuffer + 0x10))));
  nbl_extract_all(pstrBuffer, pstrData, pstrDestPath);
  if (iIsCompressed)
    free(pstrData);
  if (!nbl_has_tmll(pstrBuffer))
    return 0;
  iTMLLPos = nbl_get_tmll_pos(pstrBuffer);
  if (uOptions & 0x4)
    printf("TMLL section found at position 0x%x!\n", iTMLLPos);
  if (pCtx)
    nbl_decrypt_headers(pCtx, pstrBuffer + iTMLLPos, 0x20);
  iDataPos = nbl_get_data_pos(pstrBuffer + iTMLLPos);
  iIsCompressed = nbl_is_compressed(pstrBuffer + iTMLLPos);
  if (uOptions & 0x4)
    printf("data=%x, compressed=%x, encrypted=%x\n", iDataPos, iIsCompressed,
           pCtx != NULL);
  if (iIsCompressed) {
    if (uOptions & 0x2)
      debug_save_buffer("tmll-comp-crypt.dbg", pstrBuffer + iTMLLPos,
                        (*((unsigned int *)(pstrBuffer + iTMLLPos + 0x14))));
    if (pCtx)
      nbl_decrypt_buffer(pCtx, pstrBuffer + iTMLLPos + iDataPos,
                         (*((unsigned int *)(pstrBuffer + iTMLLPos + 0x14))));
    if (uOptions & 0x2)
      debug_save_buffer("tmll-comp-decrypt.dbg", pstrBuffer + iTMLLPos,
                        (*((unsigned int *)(pstrBuffer + iTMLLPos + 0x14))));
    return 0;
    pstrData = malloc((*((unsigned int *)(pstrBuffer + iTMLLPos + 0x10))));
    if (pstrData == NULL) {
      free(pstrBuffer);
      return -3;
    }
    nbl_decompress(pstrBuffer + iTMLLPos + iDataPos,
                   (*((unsigned int *)(pstrBuffer + iTMLLPos + 0x14))),
                   pstrData,
                   (*((unsigned int *)(pstrBuffer + iTMLLPos + 0x10))));
  } else {
    if (pCtx)
      nbl_decrypt_buffer(pCtx, pstrBuffer + iTMLLPos + iDataPos,
                         (*((unsigned int *)(pstrBuffer + iTMLLPos + 0x10))));
    pstrData = pstrBuffer + iTMLLPos + iDataPos;
  }
  if (uOptions & 0x2)
    debug_save_buffer("tmll-decomp-decrypt.dbg", pstrData,
                      (*((unsigned int *)(pstrBuffer + iTMLLPos + 0x10))));
  nbl_extract_all(pstrBuffer + iTMLLPos, pstrData, pstrDestPath);
  if (iIsCompressed)
    free(pstrData);
  return 0;
}


x86 assembly (clang, -O0):
<extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1226 <extract+0x66>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x30,%edx
call   10d0 <nbl_decrypt_headers@plt>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1221 <extract+0x61>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xde4(%rip),%rdi
call   10c0 <debug_save_buffer@plt>
jmp    1226 <extract+0x66>
mov    -0x10(%rbp),%rdi
call   10a0 <nbl_get_data_pos@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <nbl_is_compressed@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     126e <extract+0xae>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1319 <extract+0x159>
cmpq   $0x0,-0x18(%rbp)
je     129e <extract+0xde>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x30(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%edx
call   1090 <nbl_decrypt_buffer@plt>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     12cb <extract+0x10b>
mov    -0x10(%rbp),%rsi
movslq -0x30(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%edx
lea    0xdb3(%rip),%rdi
call   10c0 <debug_save_buffer@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edi
call   10e0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12f2 <extract+0x132>
movl   $0xfffffffd,-0x4(%rbp)
jmp    15ad <extract+0x3ed>
mov    -0x10(%rbp),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%ecx
call   1050 <nbl_decompress@plt>
jmp    134e <extract+0x18e>
cmpq   $0x0,-0x18(%rbp)
je     133f <extract+0x17f>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x30(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edx
call   1090 <nbl_decrypt_buffer@plt>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1374 <extract+0x1b4>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%edx
lea    0xd20(%rip),%rdi
call   10c0 <debug_save_buffer@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <nbl_extract_all@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1398 <extract+0x1d8>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <nbl_has_tmll@plt>
cmp    $0x0,%eax
jne    13b6 <extract+0x1f6>
movl   $0x0,-0x4(%rbp)
jmp    15ad <extract+0x3ed>
mov    -0x10(%rbp),%rdi
call   1080 <nbl_get_tmll_pos@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     13e2 <extract+0x222>
mov    -0x34(%rbp),%esi
lea    0xc5f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     1406 <extract+0x246>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    $0x20,%edx
call   10d0 <nbl_decrypt_headers@plt>
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
call   10a0 <nbl_get_data_pos@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
call   1060 <nbl_is_compressed@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     145c <extract+0x29c>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xbbf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1508 <extract+0x348>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1498 <extract+0x2d8>
mov    -0x10(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    0x14(%rax,%rcx,1),%edx
lea    0xbcd(%rip),%rdi
call   10c0 <debug_save_buffer@plt>
cmpq   $0x0,-0x18(%rbp)
je     14ca <extract+0x30a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
movslq -0x30(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    0x14(%rax,%rcx,1),%edx
call   1090 <nbl_decrypt_buffer@plt>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     14fc <extract+0x33c>
mov    -0x10(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    0x14(%rax,%rcx,1),%edx
lea    0xb7d(%rip),%rdi
call   10c0 <debug_save_buffer@plt>
movl   $0x0,-0x4(%rbp)
jmp    15ad <extract+0x3ed>
cmpq   $0x0,-0x18(%rbp)
je     153a <extract+0x37a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
movslq -0x30(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    0x10(%rax,%rcx,1),%edx
call   1090 <nbl_decrypt_buffer@plt>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     157b <extract+0x3bb>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    0x10(%rax,%rcx,1),%edx
lea    0xb14(%rip),%rdi
call   10c0 <debug_save_buffer@plt>
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <nbl_extract_all@plt>
cmpl   $0x0,-0x2c(%rbp)
je     15a6 <extract+0x3e6>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r14d
test   %rdx,%rdx
je     1207 <extract+0x47>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x30,%edx
call   10d0 <nbl_decrypt_headers@plt>
test   $0x2,%r14b
je     1207 <extract+0x47>
mov    0x8(%rbx),%edx
lea    0xe01(%rip),%rdi
mov    %rbx,%rsi
call   10c0 <debug_save_buffer@plt>
mov    %rbx,%rdi
call   10a0 <nbl_get_data_pos@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <nbl_is_compressed@plt>
mov    %eax,%r12d
test   $0x4,%r14b
je     123d <extract+0x7d>
xor    %ecx,%ecx
test   %r15,%r15
setne  %cl
lea    0xde3(%rip),%rdi
mov    %ebp,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
test   %r12d,%r12d
je     12bf <extract+0xff>
mov    %r14d,0xc(%rsp)
movslq %ebp,%r14
test   %r15,%r15
je     125e <extract+0x9e>
lea    (%rbx,%r14,1),%rsi
mov    0x14(%rbx),%edx
mov    %r15,%rdi
call   1090 <nbl_decrypt_buffer@plt>
mov    %r13,0x10(%rsp)
mov    0xc(%rsp),%eax
and    $0x2,%eax
mov    %eax,0x8(%rsp)
je     1283 <extract+0xc3>
lea    (%rbx,%r14,1),%rsi
mov    0x14(%rbx),%edx
lea    0xdfb(%rip),%rdi
call   10c0 <debug_save_buffer@plt>
mov    0x10(%rbx),%r13d
mov    %r13d,%edi
call   10e0 <malloc@plt>
test   %rax,%rax
je     13ec <extract+0x22c>
mov    %rax,%rbp
add    %rbx,%r14
mov    0x14(%rbx),%esi
mov    %r14,%rdi
mov    %rax,%rdx
mov    %r13d,%ecx
call   1050 <nbl_decompress@plt>
mov    0x10(%rsp),%r13
mov    0xc(%rsp),%r14d
mov    0x8(%rsp),%eax
jmp    12df <extract+0x11f>
movslq %ebp,%rbp
test   %r15,%r15
je     12d6 <extract+0x116>
lea    (%rbx,%rbp,1),%rsi
mov    0x10(%rbx),%edx
mov    %r15,%rdi
call   1090 <nbl_decrypt_buffer@plt>
add    %rbx,%rbp
mov    %r14d,%eax
and    $0x2,%eax
mov    %eax,0x8(%rsp)
test   %eax,%eax
je     12f9 <extract+0x139>
mov    0x10(%rbx),%edx
lea    0xd9e(%rip),%rdi
mov    %rbp,%rsi
call   10c0 <debug_save_buffer@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1030 <nbl_extract_all@plt>
test   %r12d,%r12d
je     1314 <extract+0x154>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   10b0 <nbl_has_tmll@plt>
xor    %ecx,%ecx
test   %eax,%eax
je     1436 <extract+0x276>
mov    %rbx,%rdi
call   1080 <nbl_get_tmll_pos@plt>
mov    %eax,%ebp
test   $0x4,%r14b
je     1346 <extract+0x186>
lea    0xcfd(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movslq %ebp,%rbp
test   %r15,%r15
je     135f <extract+0x19f>
lea    (%rbx,%rbp,1),%rsi
mov    %r15,%rdi
mov    $0x20,%edx
call   10d0 <nbl_decrypt_headers@plt>
add    %rbp,%rbx
mov    %rbx,%rdi
call   10a0 <nbl_get_data_pos@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1060 <nbl_is_compressed@plt>
mov    %eax,%ebp
test   $0x4,%r14b
je     1398 <extract+0x1d8>
xor    %ecx,%ecx
test   %r15,%r15
setne  %cl
lea    0xc88(%rip),%rdi
mov    %r12d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
test   %ebp,%ebp
je     13f3 <extract+0x233>
mov    0x8(%rsp),%eax
test   %eax,%eax
je     13ba <extract+0x1fa>
mov    0x14(%rbx),%edx
lea    0xcb2(%rip),%rdi
mov    %rbx,%rsi
call   10c0 <debug_save_buffer@plt>
mov    0x8(%rsp),%eax
test   %r15,%r15
je     13d4 <extract+0x214>
movslq %r12d,%rsi
add    %rbx,%rsi
mov    0x14(%rbx),%edx
mov    %r15,%rdi
call   1090 <nbl_decrypt_buffer@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
je     1434 <extract+0x274>
mov    0x14(%rbx),%edx
lea    0xc92(%rip),%rdi
mov    %rbx,%rsi
call   10c0 <debug_save_buffer@plt>
jmp    1434 <extract+0x274>
mov    $0xfffffffd,%ecx
jmp    1436 <extract+0x276>
movslq %r12d,%rbp
test   %r15,%r15
je     140a <extract+0x24a>
lea    (%rbx,%rbp,1),%rsi
mov    0x10(%rbx),%edx
mov    %r15,%rdi
call   1090 <nbl_decrypt_buffer@plt>
add    %rbx,%rbp
cmpl   $0x0,0x8(%rsp)
je     1426 <extract+0x266>
mov    0x10(%rbx),%edx
lea    0xc6c(%rip),%rdi
mov    %rbp,%rsi
call   10c0 <debug_save_buffer@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1030 <nbl_extract_all@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bf_ctx = type { i32 }
@.str = [20 x i8] c"decrypt-headers.dbg\00"
@.str.1 = [38 x i8] c"data=%x, compressed=%x, encrypted=%x\0A\00"
@.str.2 = [17 x i8] c"comp-decrypt.dbg\00"
@.str.3 = [19 x i8] c"decomp-decrypt.dbg\00"
@.str.4 = [38 x i8] c"TMLL section found at position 0x%x!\0A\00"
@.str.5 = [20 x i8] c"tmll-comp-crypt.dbg\00"
@.str.6 = [22 x i8] c"tmll-comp-decrypt.dbg\00"
@.str.7 = [24 x i8] c"tmll-decomp-decrypt.dbg\00"
define i32 @extract(i32 %0, i8* %1, %struct.bf_ctx* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.bf_ctx*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store %struct.bf_ctx* %2, %struct.bf_ctx** %8
store i8* %3, i8** %9
store i32 0, i32* %11
%14 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%15 = icmp ne %struct.bf_ctx* %14, null
br i1 %15, label %16, label %31
16: ; preds = %4
%17 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%18 = load i8*, i8** %7
%19 = call i32 @nbl_decrypt_headers(%struct.bf_ctx* %17, i8* %18, i32 48)
%20 = load i32, i32* %6
%21 = and i32 %20, 2
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %16
%24 = load i8*, i8** %7
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i64 8
%27 = bitcast i8* %26 to i32*
%28 = load i32, i32* %27
%29 = call i32 @debug_save_buffer(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %28)
br label %30
30: ; preds = %23, %16
br label %31
31: ; preds = %30, %4
%32 = load i8*, i8** %7
%33 = call i32 @nbl_get_data_pos(i8* %32)
store i32 %33, i32* %12
%34 = load i8*, i8** %7
%35 = call i32 @nbl_is_compressed(i8* %34)
store i32 %35, i32* %11
%36 = load i32, i32* %6
%37 = and i32 %36, 4
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %31
%40 = load i32, i32* %12
%41 = load i32, i32* %11
%42 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%43 = icmp ne %struct.bf_ctx* %42, null
%44 = zext i1 %43 to i32
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %41, i32 %44)
br label %46
46: ; preds = %39, %31
%47 = load i32, i32* %11
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %101
49: ; preds = %46
%50 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%51 = icmp ne %struct.bf_ctx* %50, null
br i1 %51, label %52, label %63
52: ; preds = %49
%53 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%54 = load i8*, i8** %7
%55 = load i32, i32* %12
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8*, i8** %7
%59 = getelementptr inbounds i8, i8* %58, i64 20
%60 = bitcast i8* %59 to i32*
%61 = load i32, i32* %60
%62 = call i32 @nbl_decrypt_buffer(%struct.bf_ctx* %53, i8* %57, i32 %61)
br label %63
63: ; preds = %52, %49
%64 = load i32, i32* %6
%65 = and i32 %64, 2
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %77
67: ; preds = %63
%68 = load i8*, i8** %7
%69 = load i32, i32* %12
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8*, i8** %7
%73 = getelementptr inbounds i8, i8* %72, i64 20
%74 = bitcast i8* %73 to i32*
%75 = load i32, i32* %74
%76 = call i32 @debug_save_buffer(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %71, i32 %75)
br label %77
77: ; preds = %67, %63
%78 = load i8*, i8** %7
%79 = getelementptr inbounds i8, i8* %78, i64 16
%80 = bitcast i8* %79 to i32*
%81 = load i32, i32* %80
%82 = call i8* @malloc(i32 %81)
store i8* %82, i8** %10
%83 = load i8*, i8** %10
%84 = icmp eq i8* %83, null
br i1 %84, label %85, label %86
85: ; preds = %77
store i32 -3, i32* %5
br label %300
86: ; preds = %77
%87 = load i8*, i8** %7
%88 = load i32, i32* %12
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
%91 = load i8*, i8** %7
%92 = getelementptr inbounds i8, i8* %91, i64 20
%93 = bitcast i8* %92 to i32*
%94 = load i32, i32* %93
%95 = load i8*, i8** %10
%96 = load i8*, i8** %7
%97 = getelementptr inbounds i8, i8* %96, i64 16
%98 = bitcast i8* %97 to i32*
%99 = load i32, i32* %98
%100 = call i32 @nbl_decompress(i8* %90, i32 %94, i8* %95, i32 %99)
br label %120
101: ; preds = %46
%102 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%103 = icmp ne %struct.bf_ctx* %102, null
br i1 %103, label %104, label %115
104: ; preds = %101
%105 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%106 = load i8*, i8** %7
%107 = load i32, i32* %12
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %106, i64 %108
%110 = load i8*, i8** %7
%111 = getelementptr inbounds i8, i8* %110, i64 16
%112 = bitcast i8* %111 to i32*
%113 = load i32, i32* %112
%114 = call i32 @nbl_decrypt_buffer(%struct.bf_ctx* %105, i8* %109, i32 %113)
br label %115
115: ; preds = %104, %101
%116 = load i8*, i8** %7
%117 = load i32, i32* %12
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i8, i8* %116, i64 %118
store i8* %119, i8** %10
br label %120
120: ; preds = %115, %86
%121 = load i32, i32* %6
%122 = and i32 %121, 2
%123 = icmp ne i32 %122, 0
br i1 %123, label %124, label %131
124: ; preds = %120
%125 = load i8*, i8** %10
%126 = load i8*, i8** %7
%127 = getelementptr inbounds i8, i8* %126, i64 16
%128 = bitcast i8* %127 to i32*
%129 = load i32, i32* %128
%130 = call i32 @debug_save_buffer(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %125, i32 %129)
br label %131
131: ; preds = %124, %120
%132 = load i8*, i8** %7
%133 = load i8*, i8** %10
%134 = load i8*, i8** %9
%135 = call i32 @nbl_extract_all(i8* %132, i8* %133, i8* %134)
%136 = load i32, i32* %11
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %141
138: ; preds = %131
%139 = load i8*, i8** %10
%140 = call i32 @free(i8* %139)
br label %141
141: ; preds = %138, %131
%142 = load i8*, i8** %7
%143 = call i32 @nbl_has_tmll(i8* %142)
%144 = icmp ne i32 %143, 0
br i1 %144, label %146, label %145
145: ; preds = %141
store i32 0, i32* %5
br label %300
146: ; preds = %141
%147 = load i8*, i8** %7
%148 = call i32 @nbl_get_tmll_pos(i8* %147)
store i32 %148, i32* %13
%149 = load i32, i32* %6
%150 = and i32 %149, 4
%151 = icmp ne i32 %150, 0
br i1 %151, label %152, label %155
152: ; preds = %146
%153 = load i32, i32* %13
%154 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %153)
br label %155
155: ; preds = %152, %146
%156 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%157 = icmp ne %struct.bf_ctx* %156, null
br i1 %157, label %158, label %165
158: ; preds = %155
%159 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%160 = load i8*, i8** %7
%161 = load i32, i32* %13
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds i8, i8* %160, i64 %162
%164 = call i32 @nbl_decrypt_headers(%struct.bf_ctx* %159, i8* %163, i32 32)
br label %165
165: ; preds = %158, %155
%166 = load i8*, i8** %7
%167 = load i32, i32* %13
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i8, i8* %166, i64 %168
%170 = call i32 @nbl_get_data_pos(i8* %169)
store i32 %170, i32* %12
%171 = load i8*, i8** %7
%172 = load i32, i32* %13
%173 = sext i32 %172 to i64
%174 = getelementptr inbounds i8, i8* %171, i64 %173
%175 = call i32 @nbl_is_compressed(i8* %174)
store i32 %175, i32* %11
%176 = load i32, i32* %6
%177 = and i32 %176, 4
%178 = icmp ne i32 %177, 0
br i1 %178, label %179, label %186
179: ; preds = %165
%180 = load i32, i32* %12
%181 = load i32, i32* %11
%182 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%183 = icmp ne %struct.bf_ctx* %182, null
%184 = zext i1 %183 to i32
%185 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %180, i32 %181, i32 %184)
br label %186
186: ; preds = %179, %165
%187 = load i32, i32* %11
%188 = icmp ne i32 %187, 0
br i1 %188, label %189, label %244
189: ; preds = %186
%190 = load i32, i32* %6
%191 = and i32 %190, 2
%192 = icmp ne i32 %191, 0
br i1 %192, label %193, label %206
193: ; preds = %189
%194 = load i8*, i8** %7
%195 = load i32, i32* %13
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i8, i8* %194, i64 %196
%198 = load i8*, i8** %7
%199 = load i32, i32* %13
%200 = sext i32 %199 to i64
%201 = getelementptr inbounds i8, i8* %198, i64 %200
%202 = getelementptr inbounds i8, i8* %201, i64 20
%203 = bitcast i8* %202 to i32*
%204 = load i32, i32* %203
%205 = call i32 @debug_save_buffer(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %197, i32 %204)
br label %206
206: ; preds = %193, %189
%207 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%208 = icmp ne %struct.bf_ctx* %207, null
br i1 %208, label %209, label %226
209: ; preds = %206
%210 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%211 = load i8*, i8** %7
%212 = load i32, i32* %13
%213 = sext i32 %212 to i64
%214 = getelementptr inbounds i8, i8* %211, i64 %213
%215 = load i32, i32* %12
%216 = sext i32 %215 to i64
%217 = getelementptr inbounds i8, i8* %214, i64 %216
%218 = load i8*, i8** %7
%219 = load i32, i32* %13
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds i8, i8* %218, i64 %220
%222 = getelementptr inbounds i8, i8* %221, i64 20
%223 = bitcast i8* %222 to i32*
%224 = load i32, i32* %223
%225 = call i32 @nbl_decrypt_buffer(%struct.bf_ctx* %210, i8* %217, i32 %224)
br label %226
226: ; preds = %209, %206
%227 = load i32, i32* %6
%228 = and i32 %227, 2
%229 = icmp ne i32 %228, 0
br i1 %229, label %230, label %243
230: ; preds = %226
%231 = load i8*, i8** %7
%232 = load i32, i32* %13
%233 = sext i32 %232 to i64
%234 = getelementptr inbounds i8, i8* %231, i64 %233
%235 = load i8*, i8** %7
%236 = load i32, i32* %13
%237 = sext i32 %236 to i64
%238 = getelementptr inbounds i8, i8* %235, i64 %237
%239 = getelementptr inbounds i8, i8* %238, i64 20
%240 = bitcast i8* %239 to i32*
%241 = load i32, i32* %240
%242 = call i32 @debug_save_buffer(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %234, i32 %241)
br label %243
243: ; preds = %230, %226
store i32 0, i32* %5
br label %300
244: ; preds = %186
%245 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%246 = icmp ne %struct.bf_ctx* %245, null
br i1 %246, label %247, label %264
247: ; preds = %244
%248 = load %struct.bf_ctx*, %struct.bf_ctx** %8
%249 = load i8*, i8** %7
%250 = load i32, i32* %13
%251 = sext i32 %250 to i64
%252 = getelementptr inbounds i8, i8* %249, i64 %251
%253 = load i32, i32* %12
%254 = sext i32 %253 to i64
%255 = getelementptr inbounds i8, i8* %252, i64 %254
%256 = load i8*, i8** %7
%257 = load i32, i32* %13
%258 = sext i32 %257 to i64
%259 = getelementptr inbounds i8, i8* %256, i64 %258
%260 = getelementptr inbounds i8, i8* %259, i64 16
%261 = bitcast i8* %260 to i32*
%262 = load i32, i32* %261
%263 = call i32 @nbl_decrypt_buffer(%struct.bf_ctx* %248, i8* %255, i32 %262)
br label %264
264: ; preds = %247, %244
%265 = load i8*, i8** %7
%266 = load i32, i32* %13
%267 = sext i32 %266 to i64
%268 = getelementptr inbounds i8, i8* %265, i64 %267
%269 = load i32, i32* %12
%270 = sext i32 %269 to i64
%271 = getelementptr inbounds i8, i8* %268, i64 %270
store i8* %271, i8** %10
br label %272
272: ; preds = %264
%273 = load i32, i32* %6
%274 = and i32 %273, 2
%275 = icmp ne i32 %274, 0
br i1 %275, label %276, label %286
276: ; preds = %272
%277 = load i8*, i8** %10
%278 = load i8*, i8** %7
%279 = load i32, i32* %13
%280 = sext i32 %279 to i64
%281 = getelementptr inbounds i8, i8* %278, i64 %280
%282 = getelementptr inbounds i8, i8* %281, i64 16
%283 = bitcast i8* %282 to i32*
%284 = load i32, i32* %283
%285 = call i32 @debug_save_buffer(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %277, i32 %284)
br label %286
286: ; preds = %276, %272
%287 = load i8*, i8** %7
%288 = load i32, i32* %13
%289 = sext i32 %288 to i64
%290 = getelementptr inbounds i8, i8* %287, i64 %289
%291 = load i8*, i8** %10
%292 = load i8*, i8** %9
%293 = call i32 @nbl_extract_all(i8* %290, i8* %291, i8* %292)
%294 = load i32, i32* %11
%295 = icmp ne i32 %294, 0
br i1 %295, label %296, label %299
296: ; preds = %286
%297 = load i8*, i8** %10
%298 = call i32 @free(i8* %297)
br label %299
299: ; preds = %296, %286
store i32 0, i32* %5
br label %300
300: ; preds = %299, %243, %145, %85
%301 = load i32, i32* %5
ret i32 %301
}

LLVM IR (-O2):
%struct.bf_ctx = type { i32 }
@.str = [20 x i8] c"decrypt-headers.dbg\00"
@.str.1 = [38 x i8] c"data=%x, compressed=%x, encrypted=%x\0A\00"
@.str.2 = [17 x i8] c"comp-decrypt.dbg\00"
@.str.3 = [19 x i8] c"decomp-decrypt.dbg\00"
@.str.4 = [38 x i8] c"TMLL section found at position 0x%x!\0A\00"
@.str.5 = [20 x i8] c"tmll-comp-crypt.dbg\00"
@.str.6 = [22 x i8] c"tmll-comp-decrypt.dbg\00"
@.str.7 = [24 x i8] c"tmll-decomp-decrypt.dbg\00"
define i32 @extract(i32 %0, i8* %1, %struct.bf_ctx* %2, i8* %3) {
%5 = icmp ne %struct.bf_ctx* %2, null
br i1 %5, label %6, label %15
6: ; preds = %4
%7 = tail call i32 @nbl_decrypt_headers(%struct.bf_ctx* %2, i8* %1, i32 48)
%8 = and i32 %0, 2
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %1, i64 8
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
%14 = tail call i32 @debug_save_buffer(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %13)
br label %15
15: ; preds = %6, %10, %4
%16 = tail call i32 @nbl_get_data_pos(i8* %1)
%17 = tail call i32 @nbl_is_compressed(i8* %1)
%18 = and i32 %0, 4
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = zext i1 %5 to i32
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17, i32 %21)
br label %23
23: ; preds = %20, %15
%24 = icmp eq i32 %17, 0
br i1 %24, label %56, label %25
25: ; preds = %23
br i1 %5, label %26, label %33
26: ; preds = %25
%27 = sext i32 %16 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = getelementptr inbounds i8, i8* %1, i64 20
%30 = bitcast i8* %29 to i32*
%31 = load i32, i32* %30
%32 = tail call i32 @nbl_decrypt_buffer(%struct.bf_ctx* %2, i8* %28, i32 %31)
br label %33
33: ; preds = %26, %25
%34 = and i32 %0, 2
%35 = icmp eq i32 %34, 0
br i1 %35, label %43, label %36
36: ; preds = %33
%37 = sext i32 %16 to i64
%38 = getelementptr inbounds i8, i8* %1, i64 %37
%39 = getelementptr inbounds i8, i8* %1, i64 20
%40 = bitcast i8* %39 to i32*
%41 = load i32, i32* %40
%42 = tail call i32 @debug_save_buffer(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %38, i32 %41)
br label %43
43: ; preds = %36, %33
%44 = getelementptr inbounds i8, i8* %1, i64 16
%45 = bitcast i8* %44 to i32*
%46 = load i32, i32* %45
%47 = tail call i8* @malloc(i32 %46)
%48 = icmp eq i8* %47, null
br i1 %48, label %138, label %49
49: ; preds = %43
%50 = sext i32 %16 to i64
%51 = getelementptr inbounds i8, i8* %1, i64 %50
%52 = getelementptr inbounds i8, i8* %1, i64 20
%53 = bitcast i8* %52 to i32*
%54 = load i32, i32* %53
%55 = tail call i32 @nbl_decompress(i8* %51, i32 %54, i8* %47, i32 %46)
br label %67
56: ; preds = %23
%57 = sext i32 %16 to i64
br i1 %5, label %58, label %64
58: ; preds = %56
%59 = getelementptr inbounds i8, i8* %1, i64 %57
%60 = getelementptr inbounds i8, i8* %1, i64 16
%61 = bitcast i8* %60 to i32*
%62 = load i32, i32* %61
%63 = tail call i32 @nbl_decrypt_buffer(%struct.bf_ctx* %2, i8* %59, i32 %62)
br label %64
64: ; preds = %56, %58
%65 = getelementptr inbounds i8, i8* %1, i64 %57
%66 = and i32 %0, 2
br label %67
67: ; preds = %64, %49
%68 = phi i32 [ %66, %64 ], [ %34, %49 ]
%69 = phi i8* [ %65, %64 ], [ %47, %49 ]
%70 = icmp eq i32 %68, 0
br i1 %70, label %76, label %71
71: ; preds = %67
%72 = getelementptr inbounds i8, i8* %1, i64 16
%73 = bitcast i8* %72 to i32*
%74 = load i32, i32* %73
%75 = tail call i32 @debug_save_buffer(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %69, i32 %74)
br label %76
76: ; preds = %71, %67
%77 = tail call i32 @nbl_extract_all(i8* %1, i8* %69, i8* %3)
br i1 %24, label %80, label %78
78: ; preds = %76
%79 = tail call i32 @free(i8* %69)
br label %80
80: ; preds = %78, %76
%81 = tail call i32 @nbl_has_tmll(i8* %1)
%82 = icmp eq i32 %81, 0
br i1 %82, label %138, label %83
83: ; preds = %80
%84 = tail call i32 @nbl_get_tmll_pos(i8* %1)
br i1 %19, label %87, label %85
85: ; preds = %83
%86 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %84)
br label %87
87: ; preds = %85, %83
%88 = sext i32 %84 to i64
br i1 %5, label %89, label %92
89: ; preds = %87
%90 = getelementptr inbounds i8, i8* %1, i64 %88
%91 = tail call i32 @nbl_decrypt_headers(%struct.bf_ctx* %2, i8* %90, i32 32)
br label %92
92: ; preds = %87, %89
%93 = getelementptr inbounds i8, i8* %1, i64 %88
%94 = tail call i32 @nbl_get_data_pos(i8* %93)
%95 = tail call i32 @nbl_is_compressed(i8* %93)
br i1 %19, label %99, label %96
96: ; preds = %92
%97 = zext i1 %5 to i32
%98 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %94, i32 %95, i32 %97)
br label %99
99: ; preds = %96, %92
%100 = icmp eq i32 %95, 0
br i1 %100, label %121, label %101
101: ; preds = %99
br i1 %70, label %107, label %102
102: ; preds = %101
%103 = getelementptr inbounds i8, i8* %93, i64 20
%104 = bitcast i8* %103 to i32*
%105 = load i32, i32* %104
%106 = tail call i32 @debug_save_buffer(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %93, i32 %105)
br label %107
107: ; preds = %102, %101
br i1 %5, label %108, label %115
108: ; preds = %107
%109 = sext i32 %94 to i64
%110 = getelementptr inbounds i8, i8* %93, i64 %109
%111 = getelementptr inbounds i8, i8* %93, i64 20
%112 = bitcast i8* %111 to i32*
%113 = load i32, i32* %112
%114 = tail call i32 @nbl_decrypt_buffer(%struct.bf_ctx* %2, i8* %110, i32 %113)
br label %115
115: ; preds = %108, %107
br i1 %70, label %138, label %116
116: ; preds = %115
%117 = getelementptr inbounds i8, i8* %93, i64 20
%118 = bitcast i8* %117 to i32*
%119 = load i32, i32* %118
%120 = tail call i32 @debug_save_buffer(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %93, i32 %119)
br label %138
121: ; preds = %99
%122 = sext i32 %94 to i64
br i1 %5, label %123, label %129
123: ; preds = %121
%124 = getelementptr inbounds i8, i8* %93, i64 %122
%125 = getelementptr inbounds i8, i8* %93, i64 16
%126 = bitcast i8* %125 to i32*
%127 = load i32, i32* %126
%128 = tail call i32 @nbl_decrypt_buffer(%struct.bf_ctx* %2, i8* %124, i32 %127)
br label %129
129: ; preds = %121, %123
%130 = getelementptr inbounds i8, i8* %93, i64 %122
br i1 %70, label %136, label %131
131: ; preds = %129
%132 = getelementptr inbounds i8, i8* %93, i64 16
%133 = bitcast i8* %132 to i32*
%134 = load i32, i32* %133
%135 = tail call i32 @debug_save_buffer(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %130, i32 %134)
br label %136
136: ; preds = %131, %129
%137 = tail call i32 @nbl_extract_all(i8* %93, i8* %130, i8* %3)
br label %138
138: ; preds = %115, %116, %80, %43, %136
%139 = phi i32 [ 0, %136 ], [ -3, %43 ], [ 0, %80 ], [ 0, %116 ], [ 0, %115 ]
ret i32 %139
}