#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*/ full_path_name;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
void *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
int write_file(char *, void *, int);
bool extract_file(FILE *pak_file, const char *dest_dir_name, const char *name,
                  int file_pos, int len_bytes) {
  void *buffer = malloc(len_bytes);
  if (buffer == NULL) {
    fprintf(stderr, "Out-of-memory in extract_file!\n");
    return false;
  }
  fseek(pak_file, file_pos, SEEK_SET);
  fread(buffer, 1, len_bytes, pak_file);
  if (ferror(pak_file)) {
    fprintf(stderr, "Error reading file data block for %s!\n", name);
    free(buffer);
    return false;
  }
  char full_path_name[512];
  snprintf(full_path_name, sizeof(full_path_name), "%s/%s", dest_dir_name,
           name);
  bool result = write_file(full_path_name, buffer, len_bytes);
  free(buffer);
  return result;
}


x86 assembly (clang, -O0):
<extract_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d8 <extract_file+0x58>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1290 <extract_file+0x110>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1245 <extract_file+0xc5>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1290 <extract_file+0x110>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0x200,%esi
lea    0xde7(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x230(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1060 <write_file@plt>
mov    %eax,-0x234(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x234(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %r8d,%r12d
mov    %ecx,%r13d
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %r8d,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1202 <extract_file+0x82>
mov    %rax,%rbx
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    %r13d,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbp,%rcx
call   1050 <fread@plt>
mov    %rbp,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     121d <extract_file+0x9d>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    124a <extract_file+0xca>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1252 <extract_file+0xd2>
lea    0xe23(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1070 <snprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1060 <write_file@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Out-of-memory in extract_file!\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [39 x i8] c"Error reading file data block for %s!\0A\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @extract_file(i32* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca [512 x i8]
%14 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%15 = load i32, i32* %11
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %12
%17 = load i8*, i8** %12
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %52
22: ; preds = %5
%23 = load i32*, i32** %7
%24 = load i32, i32* %10
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i32* %23, i32 %24, i32 %25)
%27 = load i8*, i8** %12
%28 = load i32, i32* %11
%29 = load i32*, i32** %7
%30 = call i32 @fread(i8* %27, i32 1, i32 %28, i32* %29)
%31 = load i32*, i32** %7
%32 = call i64 @ferror(i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %22
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %9
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %12
%39 = call i32 @free(i8* %38)
store i32 0, i32* %6
br label %52
40: ; preds = %22
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%42 = load i8*, i8** %8
%43 = load i8*, i8** %9
%44 = call i32 @snprintf(i8* %41, i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %43)
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%46 = load i8*, i8** %12
%47 = load i32, i32* %11
%48 = call i32 @write_file(i8* %45, i8* %46, i32 %47)
store i32 %48, i32* %14
%49 = load i8*, i8** %12
%50 = call i32 @free(i8* %49)
%51 = load i32, i32* %14
store i32 %51, i32* %6
br label %52
52: ; preds = %40, %34, %19
%53 = load i32, i32* %6
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Out-of-memory in extract_file!\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [39 x i8] c"Error reading file data block for %s!\0A\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @extract_file(i32* nocapture %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca [512 x i8]
%7 = tail call i8* @malloc(i32 %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %27
12: ; preds = %5
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %0, i32 %3, i32 %13)
%15 = tail call i32 @fread(i8* %7, i32 1, i32 %4, i32* %0)
%16 = tail call i64 @ferror(i32* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%21 = tail call i32 @free(i8* %7)
br label %27
22: ; preds = %12
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%24 = call i32 @snprintf(i8* %23, i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
%25 = call i32 @write_file(i8* %23, i8* %7, i32 %4)
%26 = call i32 @free(i8* %7)
br label %27
27: ; preds = %22, %18, %9
%28 = phi i32 [ 0, %9 ], [ 0, %18 ], [ %25, %22 ]
ret i32 %28
}