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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int extract(FILE *f, int offset, int size, char *fname) {
  long curr_pos = ftell(f);
  fseek(f, offset, SEEK_SET);
  FILE *fo = fopen(fname, "w");
  uint32_t i;
  for (i = 0; i < size; i++) {
    char c = fgetc(f);
    fputc(c, fo);
  }
  fclose(fo);
  fseek(f, curr_pos, SEEK_SET);
  return 0;
}


x86 assembly (clang, -O0):
<extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rsi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e9 <extract+0x89>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b4 <extract+0x54>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r15
call   1060 <ftell@plt>
mov    %rax,%r14
movslq %ebx,%rsi
mov    0x2e59(%rip),%r13
mov    0x0(%r13),%edx
mov    %r15,%rdi
call   1070 <fseek@plt>
lea    0xe66(%rip),%rsi
mov    %r12,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    11c8 <extract+0x68>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <fgetc@plt>
movsbl %al,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0xffffffff,%ebp
jne    11b0 <extract+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <fseek@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [2 x i8] c"w\00"
define i32 @extract(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%13 = load i32*, i32** %5
%14 = call i64 @ftell(i32* %13)
store i64 %14, i64* %9
%15 = load i32*, i32** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32* %15, i64 %17, i32 %18)
%20 = load i8*, i8** %8
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %10
store i32 0, i32* %11
br label %22
22: ; preds = %32, %4
%23 = load i32, i32* %11
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load i32*, i32** %5
%28 = call signext i8 @fgetc(i32* %27)
store i8 %28, i8* %12
%29 = load i8, i8* %12
%30 = load i32*, i32** %10
%31 = call i32 @fputc(i8 signext %29, i32* %30)
br label %32
32: ; preds = %26
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 1
store i32 %34, i32* %11
br label %22
35: ; preds = %22
%36 = load i32*, i32** %10
%37 = call i32 @fclose(i32* %36)
%38 = load i32*, i32** %5
%39 = load i64, i64* %9
%40 = load i32, i32* @SEEK_SET
%41 = call i32 @fseek(i32* %38, i64 %39, i32 %40)
ret i32 0
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [2 x i8] c"w\00"
define i32 @extract(i32* nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = tail call i64 @ftell(i32* %0)
%6 = sext i32 %1 to i64
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %0, i64 %6, i32 %7)
%9 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %17
11: ; preds = %4, %11
%12 = phi i32 [ %15, %11 ], [ 0, %4 ]
%13 = tail call signext i8 @fgetc(i32* %0)
%14 = tail call i32 @fputc(i8 signext %13, i32* %9)
%15 = add nuw nsw i32 %12, 1
%16 = icmp eq i32 %15, %2
br i1 %16, label %17, label %11
17: ; preds = %11, %4
%18 = tail call i32 @fclose(i32* %9)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @fseek(i32* %0, i64 %5, i32 %19)
ret i32 0
}