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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
void extract_file(FILE *fdres, char *fname, uint32_t fbegin, uint32_t fsize) {
  FILE *fdext;
  uint8_t *buf;
  buf = malloc(sizeof(*buf) * fsize);
  if (buf == NULL)
    exit(1);
  fdext = fopen(fname, "w+");
  fseek(fdres, fbegin, SEEK_SET);
  fread(buf, sizeof(uint8_t), fsize, fdres);
  fwrite(buf, sizeof(uint8_t), fsize, fdext);
  free(buf);
  fclose(fdext);
}


x86 assembly (clang, -O0):
<extract_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11be <extract_file+0x3e>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   10a0 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     120d <extract_file+0x8d>
mov    %rax,%rbx
lea    0xe50(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbp
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %r12d,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r14d,%edx
mov    %rbp,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@SEEK_SET = global i32 0
define void @extract_file(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = sext i32 %11 to i64
%13 = mul i64 4, %12
%14 = trunc i64 %13 to i32
%15 = call i32* @malloc(i32 %14)
store i32* %15, i32** %10
%16 = load i32*, i32** %10
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %9
%23 = load i32*, i32** %5
%24 = load i32, i32* %7
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i32* %23, i32 %24, i32 %25)
%27 = load i32*, i32** %10
%28 = load i32, i32* %8
%29 = load i32*, i32** %5
%30 = call i32 @fread(i32* %27, i32 4, i32 %28, i32* %29)
%31 = load i32*, i32** %10
%32 = load i32, i32* %8
%33 = load i32*, i32** %9
%34 = call i32 @fwrite(i32* %31, i32 4, i32 %32, i32* %33)
%35 = load i32*, i32** %10
%36 = call i32 @free(i32* %35)
%37 = load i32*, i32** %9
%38 = call i32 @fclose(i32* %37)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@SEEK_SET = global i32 0
define void @extract_file(i32* nocapture %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = shl i32 %3, 2
%6 = tail call i32* @malloc(i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %4
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @fseek(i32* %0, i32 %2, i32 %12)
%14 = tail call i32 @fread(i32* %6, i32 4, i32 %3, i32* %0)
%15 = tail call i32 @fwrite(i32* %6, i32 4, i32 %3, i32* %11)
%16 = tail call i32 @free(i32* %6)
%17 = tail call i32 @fclose(i32* %11)
ret void
}