#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, unsigned int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void nbl_extract_all(char *pstrBuffer, char *pstrData, char *pstrDestPath) {
  int i, iNbChunks, iLen;
  FILE *pFile;
  char *pstrFilename;
  if (pstrDestPath == NULL) {
    iLen = 0;
    pstrFilename = malloc(iLen + 0x20 + 1);
  } else {
    iLen = strlen(pstrDestPath);
    pstrFilename = malloc(iLen + 0x20 + 1);
    strcpy(pstrFilename, pstrDestPath);
    if (pstrDestPath[iLen - 1] != '/' && pstrDestPath[iLen - 1] != '\\')
      pstrFilename[iLen++] = '/';
  }
  iNbChunks = (*((int *)(pstrBuffer + 0x0C)));
  for (i = 0; i < iNbChunks; i++) {
    strncpy(pstrFilename + iLen, pstrBuffer + 0x40 + i * 0x60, 0x20);
    pFile = fopen(pstrFilename, "wb");
    if (pFile) {
      fwrite(pstrData + (*((unsigned int *)(pstrBuffer + 0x60 + i * 0x60))), 1,
             (*((unsigned int *)(pstrBuffer + 0x64 + i * 0x60))), pFile);
      fclose(pFile);
    }
  }
  free(pstrFilename);
}


x86 assembly (clang, -O0):
<nbl_extract_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bd <nbl_extract_all+0x3d>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x20,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
jmp    1237 <nbl_extract_all+0xb7>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x20,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1232 <nbl_extract_all+0xb2>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     1232 <nbl_extract_all+0xb2>
mov    -0x38(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
jmp    1237 <nbl_extract_all+0xb7>
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12e8 <nbl_extract_all+0x168>
mov    -0x38(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
add    $0x40,%rsi
imul   $0x60,-0x1c(%rbp),%eax
cltq
add    %rax,%rsi
mov    $0x20,%edx
call   1040 <strncpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xd7b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12d5 <nbl_extract_all+0x155>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
imul   $0x60,-0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    0x60(%rax,%rcx,1),%eax
add    %rax,%rdi
mov    -0x8(%rbp),%rax
imul   $0x60,-0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    0x64(%rax,%rcx,1),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
jmp    12da <nbl_extract_all+0x15a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1248 <nbl_extract_all+0xc8>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nbl_extract_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
mov    %rdi,%rbx
test   %rdx,%rdx
je     11da <nbl_extract_all+0x5a>
mov    %rdx,%r13
mov    %rdx,%rdi
call   1070 <strlen@plt>
mov    %eax,%r12d
lea    0x21(%r12),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r13,%rsi
call   1050 <strcpy@plt>
movslq %r12d,%rax
mov    -0x1(%rax,%r13,1),%cl
cmp    $0x2f,%cl
je     11ea <nbl_extract_all+0x6a>
cmp    $0x5c,%cl
je     11ea <nbl_extract_all+0x6a>
lea    0x1(%rax),%r12d
movb   $0x2f,(%r15,%rax,1)
jmp    11ea <nbl_extract_all+0x6a>
mov    $0x21,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
xor    %r12d,%r12d
mov    0xc(%rbx),%r14d
test   %r14d,%r14d
jle    125e <nbl_extract_all+0xde>
movslq %r12d,%r12
add    %r15,%r12
add    $0x40,%rbx
lea    0xdfc(%rip),%r13
jmp    121a <nbl_extract_all+0x9a>
cs nopw 0x0(%rax,%rax,1)
add    $0x60,%rbx
add    $0xffffffffffffffff,%r14
je     125e <nbl_extract_all+0xde>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1210 <nbl_extract_all+0x90>
mov    %rax,%rbp
mov    0x20(%rbx),%edi
mov    0x24(%rbx),%edx
add    (%rsp),%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
jmp    1210 <nbl_extract_all+0x90>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define void @nbl_extract_all(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %3
store i32 0, i32* %9
%15 = load i32, i32* %9
%16 = add nsw i32 %15, 32
%17 = add nsw i32 %16, 1
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %11
br label %53
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = add nsw i32 %22, 32
%24 = add nsw i32 %23, 1
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %11
%26 = load i8*, i8** %11
%27 = load i8*, i8** %6
%28 = call i32 @strcpy(i8* %26, i8* %27)
%29 = load i8*, i8** %6
%30 = load i32, i32* %9
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 47
br i1 %36, label %37, label %52
37: ; preds = %19
%38 = load i8*, i8** %6
%39 = load i32, i32* %9
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 92
br i1 %45, label %46, label %52
46: ; preds = %37
%47 = load i8*, i8** %11
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
store i8 47, i8* %51
br label %52
52: ; preds = %46, %37, %19
br label %53
53: ; preds = %52, %14
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i64 12
%56 = bitcast i8* %55 to i32*
%57 = load i32, i32* %56
store i32 %57, i32* %8
store i32 0, i32* %7
br label %58
58: ; preds = %103, %53
%59 = load i32, i32* %7
%60 = load i32, i32* %8
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %106
62: ; preds = %58
%63 = load i8*, i8** %11
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i8*, i8** %4
%68 = getelementptr inbounds i8, i8* %67, i64 64
%69 = load i32, i32* %7
%70 = mul nsw i32 %69, 96
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
%73 = call i32 @strncpy(i8* %66, i8* %72, i32 32)
%74 = load i8*, i8** %11
%75 = call i32* @fopen(i8* %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %75, i32** %10
%76 = load i32*, i32** %10
%77 = icmp ne i32* %76, null
br i1 %77, label %78, label %102
78: ; preds = %62
%79 = load i8*, i8** %5
%80 = load i8*, i8** %4
%81 = getelementptr inbounds i8, i8* %80, i64 96
%82 = load i32, i32* %7
%83 = mul nsw i32 %82, 96
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %81, i64 %84
%86 = bitcast i8* %85 to i32*
%87 = load i32, i32* %86
%88 = zext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %79, i64 %88
%90 = load i8*, i8** %4
%91 = getelementptr inbounds i8, i8* %90, i64 100
%92 = load i32, i32* %7
%93 = mul nsw i32 %92, 96
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %91, i64 %94
%96 = bitcast i8* %95 to i32*
%97 = load i32, i32* %96
%98 = load i32*, i32** %10
%99 = call i32 @fwrite(i8* %89, i32 1, i32 %97, i32* %98)
%100 = load i32*, i32** %10
%101 = call i32 @fclose(i32* %100)
br label %102
102: ; preds = %78, %62
br label %103
103: ; preds = %102
%104 = load i32, i32* %7
%105 = add nsw i32 %104, 1
store i32 %105, i32* %7
br label %58
106: ; preds = %58
%107 = load i8*, i8** %11
%108 = call i32 @free(i8* %107)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define void @nbl_extract_all(i8* %0, i8* nocapture %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call dereferenceable_or_null(33) i8* @malloc(i32 33)
br label %20
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %2)
%9 = add nsw i32 %8, 33
%10 = tail call i8* @malloc(i32 %9)
%11 = tail call i32 @strcpy(i8* %10, i8* %2)
%12 = add nsw i32 %8, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %2, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %16 [
i8 47, label %20
i8 92, label %20
]
16: ; preds = %7
%17 = add nsw i32 %8, 1
%18 = sext i32 %8 to i64
%19 = getelementptr inbounds i8, i8* %10, i64 %18
store i8 47, i8* %19
br label %20
20: ; preds = %7, %7, %16, %5
%21 = phi i32 [ 0, %5 ], [ %17, %16 ], [ %8, %7 ], [ %8, %7 ]
%22 = phi i8* [ %6, %5 ], [ %10, %16 ], [ %10, %7 ], [ %10, %7 ]
%23 = getelementptr inbounds i8, i8* %0, i64 12
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %55
27: ; preds = %20
%28 = sext i32 %21 to i64
%29 = getelementptr inbounds i8, i8* %22, i64 %28
%30 = getelementptr inbounds i8, i8* %0, i64 64
%31 = getelementptr inbounds i8, i8* %0, i64 96
%32 = getelementptr inbounds i8, i8* %0, i64 100
%33 = zext i32 %25 to i64
br label %34
34: ; preds = %27, %52
%35 = phi i64 [ 0, %27 ], [ %53, %52 ]
%36 = mul nuw nsw i64 %35, 96
%37 = getelementptr inbounds i8, i8* %30, i64 %36
%38 = tail call i32 @strncpy(i8* %29, i8* %37, i32 32)
%39 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%40 = icmp eq i32* %39, null
br i1 %40, label %52, label %41
41: ; preds = %34
%42 = getelementptr inbounds i8, i8* %31, i64 %36
%43 = bitcast i8* %42 to i32*
%44 = load i32, i32* %43
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %1, i64 %45
%47 = getelementptr inbounds i8, i8* %32, i64 %36
%48 = bitcast i8* %47 to i32*
%49 = load i32, i32* %48
%50 = tail call i32 @fwrite(i8* %46, i32 1, i32 %49, i32* %39)
%51 = tail call i32 @fclose(i32* %39)
br label %52
52: ; preds = %34, %41
%53 = add nuw nsw i64 %35, 1
%54 = icmp eq i64 %53, %33
br i1 %54, label %55, label %34
55: ; preds = %52, %20
%56 = tail call i32 @free(i8* %22)
ret void
}