// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-zoe/dat-extract.c
// Function: processDirectory
void processDirectory( FILE *f, tocDirectoryEntry entry, char *curpath, unsigned int tgsfix ) {
	memset( completeName, 0, 48 );
	tocDirectoryEntry workentry;
	unsigned int i;
	char *newpath = NULL;
	
	if(!curpath) {
		newpath = malloc(sizeof("ZOE")+1);
		sprintf(newpath, "ZOE");
	}
	else {
		newpath = malloc(strlen(curpath)+1+strlen(entry.name)+1);
		sprintf(newpath, "%s/%s", curpath, entry.name);
	}
	
	printf("processDirectory - Current directory: %s at %08lx\n", newpath, ftell(f) );
	createDirectory( newpath );
	
	for( i = 0; i < entry.subDirCount; i++ ) {
		fseek( f, entry.subDirOffset+(i*32), SEEK_SET );
		fread( &workentry, sizeof(workentry), 1, f );
		if( tgsfix && workentry.subFileOffset ) workentry.subFileOffset -= 0x18;
		if( workentry.subDirCount ) processDirectory( f, workentry, newpath, tgsfix );
		else processDirectoryListing( f, workentry, newpath, tgsfix );
	}
	
	free(newpath);
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
leaq 0x2b5b(%rip), %rdi      # 0x40b0
xorl %esi, %esi
movl $0x30, %edx
callq 0x1090
movq $0x0, -0x48(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x1592
movl $0x5, %edi
callq 0x10b0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
leaq 0xb64(%rip), %rsi       # 0x20ed
movb $0x0, %al
callq 0x10f0
jmp 0x15da
movq -0x10(%rbp), %rdi
callq 0x1070
movq -0x50(%rbp), %rdi
addq $0x1, %rax
movq %rax, -0x58(%rbp)
callq 0x1070
movq -0x58(%rbp), %rdi
addq %rax, %rdi
addq $0x1, %rdi
callq 0x10b0
movq -0x50(%rbp), %rcx
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0xae1(%rip), %rsi       # 0x20b4
movb $0x0, %al
callq 0x10f0
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10a0
movq -0x60(%rbp), %rsi
movq %rax, %rdx
leaq 0xaf8(%rip), %rdi       # 0x20f1
movb $0x0, %al
callq 0x1080
movq -0x48(%rbp), %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x1040
movl $0x0, -0x3c(%rbp)
movq -0x50(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x8(%rcx), %eax
jae 0x16f3
movq -0x50(%rbp), %rax
movq -0x8(%rbp), %rdi
movl 0xc(%rax), %eax
movl -0x3c(%rbp), %ecx
shll $0x5, %ecx
addl %ecx, %eax
movl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10c0
movq -0x8(%rbp), %rcx
leaq -0x38(%rbp), %rdi
movl $0x20, %esi
movl $0x1, %edx
callq 0x1050
cmpl $0x0, -0x14(%rbp)
je 0x166f
cmpl $0x0, -0x24(%rbp)
je 0x166f
movl -0x24(%rbp), %eax
subl $0x18, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x16ad
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x38(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0x1530
jmp 0x16e3
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x38(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0x1350
jmp 0x16e5
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1615
movq -0x48(%rbp), %rdi
callq 0x1030
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)