#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 compress(FILE *f, int offset, int size, char *fname) {
  uint32_t i;
  long curr_pos = ftell(f);
  fseek(f, offset, SEEK_SET);
  FILE *fi = fopen(fname, "r");
  fseek(fi, 0, SEEK_SET);
  for (i = 0; i < size; i++) {
    char c = fgetc(fi);
    fputc(c, f);
  }
  fclose(fi);
  fseek(f, curr_pos, SEEK_SET);
  return 0;
}


x86 assembly (clang, -O0):
<compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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,-0x28(%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,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ff <compress+0x9f>
mov    -0x30(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <compress+0x6a>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress>:
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
mov    0x0(%r13),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
test   %ebp,%ebp
jle    11d8 <compress+0x78>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
movsbl %al,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
add    $0xffffffff,%ebp
jne    11c0 <compress+0x60>
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"r\00"
define i32 @compress(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%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* %10
%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** %11
%22 = load i32*, i32** %11
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %22, i64 0, i32 %23)
store i32 0, i32* %9
br label %25
25: ; preds = %35, %4
%26 = load i32, i32* %9
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i32*, i32** %11
%31 = call signext i8 @fgetc(i32* %30)
store i8 %31, i8* %12
%32 = load i8, i8* %12
%33 = load i32*, i32** %5
%34 = call i32 @fputc(i8 signext %32, i32* %33)
br label %35
35: ; preds = %29
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %25
38: ; preds = %25
%39 = load i32*, i32** %11
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %5
%42 = load i64, i64* %10
%43 = load i32, i32* @SEEK_SET
%44 = call i32 @fseek(i32* %41, i64 %42, i32 %43)
ret i32 0
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [2 x i8] c"r\00"
define i32 @compress(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 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %9, i64 0, i32 %10)
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %19
13: ; preds = %4, %13
%14 = phi i32 [ %17, %13 ], [ 0, %4 ]
%15 = tail call signext i8 @fgetc(i32* %9)
%16 = tail call i32 @fputc(i8 signext %15, i32* %0)
%17 = add nuw nsw i32 %14, 1
%18 = icmp eq i32 %17, %2
br i1 %18, label %19, label %13
19: ; preds = %13, %4
%20 = tail call i32 @fclose(i32* %9)
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @fseek(i32* %0, i64 %5, i32 %21)
ret i32 0
}