#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char **);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void main() {
  int i = 0, j = 0, start = 0;
  char file[30];
  char key[30];
  FILE *data;
  data = fopen("data.txt", "r");
  fscanf(data, "%s", &file);
  fscanf(data, "%s", &key);
  fclose(data);
  FILE *fp;
  FILE *out;
  fp = fopen(file, "rb");
  out = fopen("output.bmp", "wb");
  fseek(fp, 0, SEEK_END);
  j = (ftell(fp));
  rewind(fp);
  fseek(fp, 10, SEEK_SET);
  fread(&start, 1, 1, fp);
  rewind(fp);
  printf("Starting at %d\nOut of %d bytes\n", start, j);
  if (start > j)
    printf("Error in start point!\n");
  rewind(fp);
  int in;
  char thro;
  for (i = 0; i < start; i++) {
    fread(&in, 1, 1, fp);
    fwrite(&in, 1, 1, out);
  }
  for (i = start; i < j; i++) {
    fread(&in, 1, 1, fp);
    fwrite(&in, 1, 1, out);
  }
  fclose(fp);
  fclose(out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe4c(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe38(%rip),%rsi
call   1070 <fscanf@plt>
mov    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1070 <fscanf@plt>
mov    -0x58(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x30(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x60(%rbp)
lea    0xe01(%rip),%rdi
lea    0xe05(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rdi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x60(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x8(%rbp)
mov    -0x60(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x60(%rbp),%rdi
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1090 <fseek@plt>
mov    -0x60(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x60(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    12ab <main+0x11b>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1060 <rewind@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12fd <main+0x16d>
mov    -0x60(%rbp),%rcx
lea    -0x6c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x68(%rbp),%rcx
lea    -0x6c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10b0 <fwrite@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12bb <main+0x12b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1345 <main+0x1b5>
mov    -0x60(%rbp),%rcx
lea    -0x6c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x68(%rbp),%rcx
lea    -0x6c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10b0 <fwrite@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <main+0x173>
mov    -0x60(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x68(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe43(%rip),%rdi
lea    0xe45(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0xe38(%rip),%rbp
lea    0x30(%rsp),%r14
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1080 <fscanf@plt>
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <fscanf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe09(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r13
lea    0xdfa(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r13,%rdi
call   10a0 <ftell@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1070 <rewind@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    $0xa,%esi
call   10b0 <fseek@plt>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
mov    %r13,%rdi
call   1070 <rewind@plt>
mov    0xc(%rsp),%r15d
lea    0xd93(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %ebp,%r15d
jle    12a9 <main+0x109>
lea    0xd9b(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1070 <rewind@plt>
test   %r15d,%r15d
jle    12e7 <main+0x147>
lea    0x8(%rsp),%r12
mov    %r15d,%ebx
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
movsbl 0x8(%rsp),%edi
mov    %r14,%rsi
call   1090 <fputc@plt>
add    $0xffffffff,%ebx
jne    12c0 <main+0x120>
cmp    %ebp,%r15d
jge    1327 <main+0x187>
sub    %r15d,%ebp
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
movsbl 0x8(%rsp),%edi
mov    %r14,%rsi
call   1090 <fputc@plt>
add    $0xffffffff,%ebp
jne    1300 <main+0x160>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [11 x i8] c"output.bmp\00"
@.str.5 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [32 x i8] c"Starting at %d\0AOut of %d bytes\0A\00"
@.str.7 = [23 x i8] c"Error in start point!\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [30 x i8]
%5 = alloca [30 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%11 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = bitcast [30 x i8]* %4 to i8**
%14 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %13)
%15 = load i32*, i32** %6
%16 = bitcast [30 x i8]* %5 to i8**
%17 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %16)
%18 = load i32*, i32** %6
%19 = call i32 @fclose(i32* %18)
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %21, i32** %7
%22 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %22, i32** %8
%23 = load i32*, i32** %7
%24 = load i32, i32* @SEEK_END
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
%26 = load i32*, i32** %7
%27 = call i32 @ftell(i32* %26)
store i32 %27, i32* %2
%28 = load i32*, i32** %7
%29 = call i32 @rewind(i32* %28)
%30 = load i32*, i32** %7
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @fseek(i32* %30, i32 10, i32 %31)
%33 = load i32*, i32** %7
%34 = call i32 @fread(i32* %3, i32 1, i32 1, i32* %33)
%35 = load i32*, i32** %7
%36 = call i32 @rewind(i32* %35)
%37 = load i32, i32* %3
%38 = load i32, i32* %2
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %37, i32 %38)
%40 = load i32, i32* %3
%41 = load i32, i32* %2
%42 = icmp sgt i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %45
45: ; preds = %43, %0
%46 = load i32*, i32** %7
%47 = call i32 @rewind(i32* %46)
store i32 0, i32* %1
br label %48
48: ; preds = %57, %45
%49 = load i32, i32* %1
%50 = load i32, i32* %3
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %60
52: ; preds = %48
%53 = load i32*, i32** %7
%54 = call i32 @fread(i32* %9, i32 1, i32 1, i32* %53)
%55 = load i32*, i32** %8
%56 = call i32 @fwrite(i32* %9, i32 1, i32 1, i32* %55)
br label %57
57: ; preds = %52
%58 = load i32, i32* %1
%59 = add nsw i32 %58, 1
store i32 %59, i32* %1
br label %48
60: ; preds = %48
%61 = load i32, i32* %3
store i32 %61, i32* %1
br label %62
62: ; preds = %71, %60
%63 = load i32, i32* %1
%64 = load i32, i32* %2
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %74
66: ; preds = %62
%67 = load i32*, i32** %7
%68 = call i32 @fread(i32* %9, i32 1, i32 1, i32* %67)
%69 = load i32*, i32** %8
%70 = call i32 @fwrite(i32* %9, i32 1, i32 1, i32* %69)
br label %71
71: ; preds = %66
%72 = load i32, i32* %1
%73 = add nsw i32 %72, 1
store i32 %73, i32* %1
br label %62
74: ; preds = %62
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
%77 = load i32*, i32** %8
%78 = call i32 @fclose(i32* %77)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [11 x i8] c"output.bmp\00"
@.str.5 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [32 x i8] c"Starting at %d\0AOut of %d bytes\0A\00"
@str = [22 x i8] c"Error in start point!\00"
define void @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca [30 x i8]
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = bitcast [30 x i8]* %2 to i8**
%10 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %9)
%11 = bitcast [30 x i8]* %3 to i8**
%12 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %11)
%13 = call i32 @fclose(i32* %8)
%14 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %14, i32 0, i32 %16)
%18 = call i32 @ftell(i32* %14)
%19 = call i32 @rewind(i32* %14)
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %14, i32 10, i32 %20)
%22 = call i32 @fread(i32* %1, i32 1, i32 1, i32* %14)
%23 = call i32 @rewind(i32* %14)
%24 = load i32, i32* %1
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %24, i32 %18)
%26 = icmp sgt i32 %24, %18
br i1 %26, label %27, label %29
27: ; preds = %0
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %27, %0
%30 = call i32 @rewind(i32* %14)
%31 = bitcast i32* %4 to i8*
%32 = icmp sgt i32 %24, 0
br i1 %32, label %35, label %33
33: ; preds = %35, %29
%34 = icmp slt i32 %24, %18
br i1 %34, label %43, label %51
35: ; preds = %29, %35
%36 = phi i32 [ %41, %35 ], [ 0, %29 ]
%37 = call i32 @fread(i32* %4, i32 1, i32 1, i32* %14)
%38 = load i8, i8* %31
%39 = sext i8 %38 to i32
%40 = call i32 @fputc(i32 %39, i32* %15)
%41 = add nuw nsw i32 %36, 1
%42 = icmp eq i32 %41, %24
br i1 %42, label %33, label %35
43: ; preds = %33, %43
%44 = phi i32 [ %49, %43 ], [ %24, %33 ]
%45 = call i32 @fread(i32* %4, i32 1, i32 1, i32* %14)
%46 = load i8, i8* %31
%47 = sext i8 %46 to i32
%48 = call i32 @fputc(i32 %47, i32* %15)
%49 = add i32 %44, 1
%50 = icmp eq i32 %49, %18
br i1 %50, label %51, label %43
51: ; preds = %43, %33
%52 = call i32 @fclose(i32* %14)
%53 = call i32 @fclose(i32* %15)
ret void
}