main(argc, argv) char *argv[];
{
  int in, out, startrestore, endrestore, i, nbytes, nread, npoles, frsize;
  char *input, *output;
  float buffer[10000];
  if (argc != 5) {
    printf("usage: restorelpc inputlpc outputlpc framefirst framelast\n");
    exit(0);
  }
  input = argv[1];
  output = argv[2];
  startrestore = atoi(argv[3]);
  endrestore = atoi(argv[4]);
  frsize = 8;
  printf("%d %d\n", startrestore, endrestore);
  if ((in = open(input, 2)) < 0) {
    printf("cant open inputfile \n");
    exit(-1);
  }
  if ((out = open(output, 2)) < 0) {
    printf("cant open outputfile\n");
    exit(-1);
  }
  if ((lseek(in, startrestore * frsize, 0)) < 0) {
    printf("bad lseek on inputfile\n");
    exit(-1);
  }
  if ((lseek(out, startrestore * frsize, 0)) < 0) {
    printf("bad lseek on outputfile");
    exit(-1);
  }
  nbytes = (endrestore - startrestore + 1) * frsize;
  printf("nbytestoread = %d\n", nbytes);
  if (nread = read(in, (char *)buffer, nbytes) != nbytes) {
    printf("bad read on inputfile %d\n", nread);
    exit(-1);
  }
  if (nread = write(out, (char *)buffer, nbytes) != nbytes) {
    printf("bad write on outputfile %d\n", nread);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x4(%rbp)
je     11a1 <main+0x31>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    $0x0,%al
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    $0x0,%al
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
movl   $0x8,-0x34(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    122c <main+0xbc>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x48(%rbp),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1260 <main+0xf0>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
imul   -0x34(%rbp),%esi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <lseek@plt>
cmp    $0x0,%eax
jge    1294 <main+0x124>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
imul   -0x34(%rbp),%esi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <lseek@plt>
cmp    $0x0,%eax
jge    12c8 <main+0x158>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
add    $0x1,%eax
imul   -0x34(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x9c90(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    $0x0,%al
call   1060 <read@plt>
cmp    -0x28(%rbp),%eax
setne  %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x2c(%rbp)
test   $0x1,%al
jne    131b <main+0x1ab>
jmp    1336 <main+0x1c6>
mov    -0x2c(%rbp),%esi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x9c90(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    -0x28(%rbp),%eax
setne  %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x2c(%rbp)
test   $0x1,%al
jne    1368 <main+0x1f8>
jmp    1383 <main+0x213>
mov    -0x2c(%rbp),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x9c90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x9c40,%rsp
cmp    $0x5,%edi
jne    128b <main+0x10b>
mov    %rsi,%rbx
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%r15
mov    0x18(%rsi),%rdi
xor    %eax,%eax
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    0x20(%rbx),%rdi
xor    %eax,%eax
call   1090 <atoi@plt>
mov    %eax,%ebx
lea    0xe3b(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1080 <open@plt>
test   %eax,%eax
js     129e <main+0x11e>
mov    %eax,%r12d
mov    %r15,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1080 <open@plt>
test   %eax,%eax
js     12a7 <main+0x127>
mov    %eax,%r15d
lea    0x0(,%r14,8),%ebp
mov    %r12d,%edi
mov    %ebp,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <lseek@plt>
test   %eax,%eax
js     12b0 <main+0x130>
mov    %r15d,%edi
mov    %ebp,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <lseek@plt>
test   %eax,%eax
js     12c6 <main+0x146>
sub    %r14d,%ebx
lea    0x8(,%rbx,8),%ebx
lea    0xdd5(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <read@plt>
cmp    %ebx,%eax
jne    12de <main+0x15e>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <write@plt>
cmp    %ebx,%eax
jne    12e7 <main+0x167>
xor    %eax,%eax
add    $0x9c40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdef(%rip),%rdi
jmp    12b7 <main+0x137>
lea    0xdd1(%rip),%rdi
jmp    12b7 <main+0x137>
lea    0xdb1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xd3a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xd4d(%rip),%rdi
jmp    12ee <main+0x16e>
lea    0xd5e(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [59 x i8] c"usage: restorelpc inputlpc outputlpc framefirst framelast\0A\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
@.str.2 = [22 x i8] c"cant open inputfile \0A\00"
@.str.3 = [22 x i8] c"cant open outputfile\0A\00"
@.str.4 = [24 x i8] c"bad lseek on inputfile\0A\00"
@.str.5 = [24 x i8] c"bad lseek on outputfile\00"
@.str.6 = [19 x i8] c"nbytestoread = %d\0A\00"
@.str.7 = [26 x i8] c"bad read on inputfile %d\0A\00"
@.str.8 = [28 x i8] c"bad write on outputfile %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca [10000 x float]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 5
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %14
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %15
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %30)
store i32 %31, i32* %7
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 4
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %34)
store i32 %35, i32* %8
store i32 8, i32* %13
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %37)
%39 = load i8*, i8** %14
%40 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %39, i32 2)
store i32 %40, i32* %5
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %21
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
unreachable
44: ; preds = %21
%45 = load i8*, i8** %15
%46 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %45, i32 2)
store i32 %46, i32* %6
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
unreachable
50: ; preds = %44
%51 = load i32, i32* %5
%52 = load i32, i32* %7
%53 = load i32, i32* %13
%54 = mul nsw i32 %52, %53
%55 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @lseek to i32 (i32, i32, i32, ...)*)(i32 %51, i32 %54, i32 0)
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %50
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
unreachable
59: ; preds = %50
%60 = load i32, i32* %6
%61 = load i32, i32* %7
%62 = load i32, i32* %13
%63 = mul nsw i32 %61, %62
%64 = call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @lseek to i32 (i32, i32, i32, ...)*)(i32 %60, i32 %63, i32 0)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %59
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
unreachable
68: ; preds = %59
%69 = load i32, i32* %8
%70 = load i32, i32* %7
%71 = sub nsw i32 %69, %70
%72 = add nsw i32 %71, 1
%73 = load i32, i32* %13
%74 = mul nsw i32 %72, %73
store i32 %74, i32* %10
%75 = load i32, i32* %10
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %5
%78 = getelementptr inbounds [10000 x float], [10000 x float]* %16, i64 0, i64 0
%79 = bitcast float* %78 to i8*
%80 = load i32, i32* %10
%81 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %77, i8* %79, i32 %80)
%82 = load i32, i32* %10
%83 = icmp ne i32 %81, %82
%84 = zext i1 %83 to i32
store i32 %84, i32* %11
br i1 %83, label %85, label %88
85: ; preds = %68
%86 = load i32, i32* %11
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %86)
unreachable
88: ; preds = %68
%89 = load i32, i32* %6
%90 = getelementptr inbounds [10000 x float], [10000 x float]* %16, i64 0, i64 0
%91 = bitcast float* %90 to i8*
%92 = load i32, i32* %10
%93 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %89, i8* %91, i32 %92)
%94 = load i32, i32* %10
%95 = icmp ne i32 %93, %94
%96 = zext i1 %95 to i32
store i32 %96, i32* %11
br i1 %95, label %97, label %100
97: ; preds = %88
%98 = load i32, i32* %11
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 %98)
unreachable
100: ; preds = %88
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%d %d\0A\00"
@.str.5 = [24 x i8] c"bad lseek on outputfile\00"
@.str.6 = [19 x i8] c"nbytestoread = %d\0A\00"
@.str.7 = [26 x i8] c"bad read on inputfile %d\0A\00"
@.str.8 = [28 x i8] c"bad write on outputfile %d\0A\00"
@str = [23 x i8] c"bad lseek on inputfile\00"
@str.9 = [21 x i8] c"cant open outputfile\00"
@str.10 = [21 x i8] c"cant open inputfile \00"
@str.11 = [58 x i8] c"usage: restorelpc inputlpc outputlpc framefirst framelast\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10000 x float]
%4 = bitcast [10000 x float]* %3 to i8*
%5 = icmp eq i32 %0, 5
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.11, i64 0, i64 0))
tail call void @exit(i32 0)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %18)
%20 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %10, i32 2)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %8
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
tail call void @exit(i32 -1)
unreachable
24: ; preds = %8
%25 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %12, i32 2)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
tail call void @exit(i32 -1)
unreachable
29: ; preds = %24
%30 = shl nsw i32 %15, 3
%31 = tail call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @lseek to i32 (i32, i32, i32, ...)*)(i32 %20, i32 %30, i32 0)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
tail call void @exit(i32 -1)
unreachable
35: ; preds = %29
%36 = tail call i32 (i32, i32, i32, ...) bitcast (i32 (...)* @lseek to i32 (i32, i32, i32, ...)*)(i32 %25, i32 %30, i32 0)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
tail call void @exit(i32 -1)
unreachable
40: ; preds = %35
%41 = sub nsw i32 %18, %15
%42 = shl i32 %41, 3
%43 = add i32 %42, 8
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %43)
%45 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %20, i8* %4, i32 %43)
%46 = icmp eq i32 %45, %43
br i1 %46, label %49, label %47
47: ; preds = %40
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 1)
unreachable
49: ; preds = %40
%50 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %25, i8* %4, i32 %43)
%51 = icmp eq i32 %50, %43
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 1)
unreachable
54: ; preds = %49
ret i32 0
}