#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 afs_get_filenames_pos(char *);
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 afs_extract_all(char *pstrBuffer, char *pstrDestPath) {
  int i, iFilenamesPos, 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++] = '/';
  }
  iFilenamesPos = afs_get_filenames_pos(pstrBuffer);
  iNbChunks = (*((int *)(pstrBuffer + 0x04)));
  for (i = 0; i < iNbChunks; i++) {
    strncpy(pstrFilename + iLen, pstrBuffer + iFilenamesPos + i * 0x30, 0x20);
    pFile = fopen(pstrFilename, "wb");
    if (pFile) {
      fwrite(pstrBuffer +
                 (*((unsigned int *)(pstrBuffer + 0x08 + i * 0x08 + 0x00))),
             1, (*((unsigned int *)(pstrBuffer + 0x08 + i * 0x08 + 0x04))),
             pFile);
      fclose(pFile);
    }
  }
  free(pstrFilename);
}


x86 assembly (clang, -O0):
<afs_extract_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c9 <afs_extract_all+0x39>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%edi
add    $0x20,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
jmp    1243 <afs_extract_all+0xb3>
mov    -0x10(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
add    $0x20,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     123e <afs_extract_all+0xae>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     123e <afs_extract_all+0xae>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
jmp    1243 <afs_extract_all+0xb3>
mov    -0x8(%rbp),%rdi
call   1060 <afs_get_filenames_pos@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1307 <afs_extract_all+0x177>
mov    -0x30(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
imul   $0x30,-0x14(%rbp),%eax
cltq
add    %rax,%rsi
mov    $0x20,%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xd60(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12f4 <afs_extract_all+0x164>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x3,%ecx
movslq %ecx,%rcx
mov    0x8(%rax,%rcx,1),%eax
add    %rax,%rdi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x3,%ecx
movslq %ecx,%rcx
mov    0xc(%rax,%rcx,1),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
jmp    12f9 <afs_extract_all+0x169>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1260 <afs_extract_all+0xd0>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<afs_extract_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
test   %rsi,%rsi
je     11e8 <afs_extract_all+0x58>
mov    %rsi,%rbx
mov    %rsi,%rdi
call   1080 <strlen@plt>
mov    %eax,%r15d
lea    0x21(%r15),%edi
call   1090 <malloc@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
movslq %r15d,%rax
mov    -0x1(%rax,%rbx,1),%cl
cmp    $0x2f,%cl
je     11f9 <afs_extract_all+0x69>
cmp    $0x5c,%cl
je     11f9 <afs_extract_all+0x69>
lea    0x1(%rax),%r15d
mov    (%rsp),%rcx
movb   $0x2f,(%rcx,%rax,1)
jmp    11f9 <afs_extract_all+0x69>
mov    $0x21,%edi
call   1090 <malloc@plt>
mov    %rax,(%rsp)
xor    %r15d,%r15d
mov    %r12,%rdi
call   1060 <afs_get_filenames_pos@plt>
mov    0x4(%r12),%r13d
test   %r13d,%r13d
jle    128f <afs_extract_all+0xff>
movslq %r15d,%r15
add    (%rsp),%r15
movslq %eax,%rbx
add    %r12,%rbx
shl    $0x3,%r13
xor    %r14d,%r14d
jmp    123d <afs_extract_all+0xad>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x8,%r14
add    $0x30,%rbx
cmp    %r14,%r13
je     128f <afs_extract_all+0xff>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1040 <strncpy@plt>
mov    (%rsp),%rdi
lea    0xda8(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1230 <afs_extract_all+0xa0>
mov    %rax,%rbp
mov    %r14d,%eax
and    $0xfffffff8,%eax
mov    0x8(%r12,%rax,1),%edi
mov    0xc(%r12,%rax,1),%edx
add    %r12,%rdi
mov    $0x1,%esi
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
mov    %rbp,%rdi
call   1070 <fclose@plt>
jmp    1230 <afs_extract_all+0xa0>
mov    (%rsp),%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 @afs_extract_all(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %2
store i32 0, i32* %8
%14 = load i32, i32* %8
%15 = add nsw i32 %14, 32
%16 = add nsw i32 %15, 1
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %10
br label %52
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 32
%23 = add nsw i32 %22, 1
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = load i8*, i8** %4
%27 = call i32 @strcpy(i8* %25, i8* %26)
%28 = load i8*, i8** %4
%29 = load i32, i32* %8
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 47
br i1 %35, label %36, label %51
36: ; preds = %18
%37 = load i8*, i8** %4
%38 = load i32, i32* %8
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 92
br i1 %44, label %45, label %51
45: ; preds = %36
%46 = load i8*, i8** %10
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
store i8 47, i8* %50
br label %51
51: ; preds = %45, %36, %18
br label %52
52: ; preds = %51, %13
%53 = load i8*, i8** %3
%54 = call i32 @afs_get_filenames_pos(i8* %53)
store i32 %54, i32* %6
%55 = load i8*, i8** %3
%56 = getelementptr inbounds i8, i8* %55, i64 4
%57 = bitcast i8* %56 to i32*
%58 = load i32, i32* %57
store i32 %58, i32* %7
store i32 0, i32* %5
br label %59
59: ; preds = %108, %52
%60 = load i32, i32* %5
%61 = load i32, i32* %7
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %111
63: ; preds = %59
%64 = load i8*, i8** %10
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8*, i8** %3
%69 = load i32, i32* %6
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i32, i32* %5
%73 = mul nsw i32 %72, 48
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %71, i64 %74
%76 = call i32 @strncpy(i8* %67, i8* %75, i32 32)
%77 = load i8*, i8** %10
%78 = call i32* @fopen(i8* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %78, i32** %9
%79 = load i32*, i32** %9
%80 = icmp ne i32* %79, null
br i1 %80, label %81, label %107
81: ; preds = %63
%82 = load i8*, i8** %3
%83 = load i8*, i8** %3
%84 = getelementptr inbounds i8, i8* %83, i64 8
%85 = load i32, i32* %5
%86 = mul nsw i32 %85, 8
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %84, i64 %87
%89 = getelementptr inbounds i8, i8* %88, i64 0
%90 = bitcast i8* %89 to i32*
%91 = load i32, i32* %90
%92 = zext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %82, i64 %92
%94 = load i8*, i8** %3
%95 = getelementptr inbounds i8, i8* %94, i64 8
%96 = load i32, i32* %5
%97 = mul nsw i32 %96, 8
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %95, i64 %98
%100 = getelementptr inbounds i8, i8* %99, i64 4
%101 = bitcast i8* %100 to i32*
%102 = load i32, i32* %101
%103 = load i32*, i32** %9
%104 = call i32 @fwrite(i8* %93, i32 1, i32 %102, i32* %103)
%105 = load i32*, i32** %9
%106 = call i32 @fclose(i32* %105)
br label %107
107: ; preds = %81, %63
br label %108
108: ; preds = %107
%109 = load i32, i32* %5
%110 = add nsw i32 %109, 1
store i32 %110, i32* %5
br label %59
111: ; preds = %59
%112 = load i8*, i8** %10
%113 = call i32 @free(i8* %112)
ret void
}

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