main(argc, argv) char *argv[];
{
  int in, out, startrestore, endrestore, i, nbytes, nread, npoles = 0, frsize;
  char *input, *output;
  float buffer[10000];
  if (argc != 6) {
    printf(
        "usage: restorelpc inputlpc outputlpc framefirst framelast npoles\n");
    exit(0);
  }
  input = argv[1];
  output = argv[2];
  startrestore = atoi(argv[3]);
  endrestore = atoi(argv[4]);
  npoles = atoi(argv[5]);
  frsize = (npoles + 4) * 4;
  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, (0) + startrestore * frsize, 0)) < 0) {
    printf("bad lseek on inputfile\n");
    exit(-1);
  }
  if ((lseek(out, (0) + 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)
movl   $0x0,-0x30(%rbp)
cmpl   $0x6,-0x4(%rbp)
je     11a8 <main+0x38>
lea    0xe66(%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)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
mov    $0x0,%al
call   1080 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
add    $0x4,%eax
shl    $0x2,%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe33(%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    124a <main+0xda>
lea    0xe10(%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    127e <main+0x10e>
lea    0xdf2(%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
add    $0x0,%esi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <lseek@plt>
cmp    $0x0,%eax
jge    12b5 <main+0x145>
lea    0xdd1(%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
add    $0x0,%esi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <lseek@plt>
cmp    $0x0,%eax
jge    12ec <main+0x17c>
lea    0xdb2(%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    0xd9f(%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    133f <main+0x1cf>
jmp    135a <main+0x1ea>
mov    -0x2c(%rbp),%esi
lea    0xd6f(%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    138c <main+0x21c>
jmp    13a7 <main+0x237>
mov    -0x2c(%rbp),%esi
lea    0xd3c(%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   %r13
push   %r12
push   %rbx
sub    $0x9c48,%rsp
cmp    $0x6,%edi
jne    12a4 <main+0x124>
mov    %rsi,%rbx
mov    0x8(%rsi),%r12
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,%r13d
mov    0x28(%rbx),%rdi
xor    %eax,%eax
call   1090 <atoi@plt>
mov    %eax,%ebx
lea    0xe2b(%rip),%rdi
mov    %r14d,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1080 <open@plt>
test   %eax,%eax
js     12b7 <main+0x137>
mov    %eax,%r12d
mov    %r15,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1080 <open@plt>
test   %eax,%eax
js     12c0 <main+0x140>
mov    %eax,%r15d
lea    0x10(,%rbx,4),%ebp
mov    %ebp,%ebx
imul   %r14d,%ebx
mov    %r12d,%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <lseek@plt>
test   %eax,%eax
js     12c9 <main+0x149>
mov    %r15d,%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <lseek@plt>
test   %eax,%eax
js     12df <main+0x15f>
sub    %r14d,%r13d
add    $0x1,%r13d
imul   %r13d,%ebp
lea    0xdbe(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <read@plt>
cmp    %ebp,%eax
jne    12f7 <main+0x177>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <write@plt>
cmp    %ebp,%eax
jne    1300 <main+0x180>
xor    %eax,%eax
add    $0x9c48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdd6(%rip),%rdi
jmp    12d0 <main+0x150>
lea    0xdb8(%rip),%rdi
jmp    12d0 <main+0x150>
lea    0xd98(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xd21(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xd34(%rip),%rdi
jmp    1307 <main+0x187>
lea    0xd45(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

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