int read_test_2(int fd) {
  rewind_tape(fd);
  space_forward_filemark(fd, 3);
  read_block(fd, 64 * 1024);
  space_forward_block(fd, 1);
  read_block(fd, 64 * 1024);
  printf("%s: Did we error here ??\n", __func__);
  rewind_tape(fd);
  printf("%s: Block %d\n", __func__, read_block_position(fd));
  printf("%s: Note: following space_forward_filemark(100000)"
         " should error\n",
         __func__);
  space_forward_filemark(fd, 100000);
  printf("%s: Block %d\n", __func__, read_block_position(fd));
  space_back_filemark(fd, 2);
  printf("%s: Block %d\n", __func__, read_block_position(fd));
  space_back_block(fd, 1);
  printf("%s: Block %d\n", __func__, read_block_position(fd));
  read_block(fd, 64 * 1024);
  printf("%s: Block %d\n", __func__, read_block_position(fd));
  return 0;
}


x86 assembly (clang, -O0):
<read_test_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1050 <rewind_tape@plt>
mov    -0x4(%rbp),%edi
mov    $0x3,%esi
mov    $0x0,%al
call   1090 <space_forward_filemark@plt>
mov    -0x4(%rbp),%edi
mov    $0x10000,%esi
mov    $0x0,%al
call   10a0 <read_block@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
mov    $0x0,%al
call   1080 <space_forward_block@plt>
mov    -0x4(%rbp),%edi
mov    $0x10000,%esi
mov    $0x0,%al
call   10a0 <read_block@plt>
lea    0xe28(%rip),%rdi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1050 <rewind_tape@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1070 <read_block_position@plt>
mov    %eax,%edx
lea    0xe23(%rip),%rdi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe1c(%rip),%rdi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x186a0,%esi
mov    $0x0,%al
call   1090 <space_forward_filemark@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1070 <read_block_position@plt>
mov    %eax,%edx
lea    0xdde(%rip),%rdi
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
mov    $0x0,%al
call   1060 <space_back_filemark@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1070 <read_block_position@plt>
mov    %eax,%edx
lea    0xdae(%rip),%rdi
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <space_back_block@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1070 <read_block_position@plt>
mov    %eax,%edx
lea    0xd7e(%rip),%rdi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x10000,%esi
mov    $0x0,%al
call   10a0 <read_block@plt>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1070 <read_block_position@plt>
mov    %eax,%edx
lea    0xd4e(%rip),%rdi
lea    0xd3b(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_test_2>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <rewind_tape@plt>
mov    %ebx,%edi
mov    $0x3,%esi
xor    %eax,%eax
call   1090 <space_forward_filemark@plt>
mov    %ebx,%edi
mov    $0x10000,%esi
xor    %eax,%eax
call   10a0 <read_block@plt>
mov    %ebx,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1080 <space_forward_block@plt>
mov    %ebx,%edi
mov    $0x10000,%esi
xor    %eax,%eax
call   10a0 <read_block@plt>
lea    0xe33(%rip),%rdi
lea    0xe46(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <rewind_tape@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <read_block_position@plt>
lea    0xe2f(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe27(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x186a0,%esi
xor    %eax,%eax
call   1090 <space_forward_filemark@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <read_block_position@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1060 <space_back_filemark@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <read_block_position@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <space_back_block@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <read_block_position@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x10000,%esi
xor    %eax,%eax
call   10a0 <read_block@plt>
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <read_block_position@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"%s: Did we error here ??\0A\00"
@__func__.read_test_2 = [12 x i8] c"read_test_2\00"
@.str.1 = [14 x i8] c"%s: Block %d\0A\00"
@.str.2 = [65 x i8] c"%s: Note: following space_forward_filemark(100000) should error\0A\00"
define i32 @read_test_2(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 (i32, ...) bitcast (i32 (...)* @rewind_tape to i32 (i32, ...)*)(i32 %3)
%5 = load i32, i32* %2
%6 = call i32 (i32, i32, ...) bitcast (i32 (...)* @space_forward_filemark to i32 (i32, i32, ...)*)(i32 %5, i32 3)
%7 = load i32, i32* %2
%8 = call i32 (i32, i32, ...) bitcast (i32 (...)* @read_block to i32 (i32, i32, ...)*)(i32 %7, i32 65536)
%9 = load i32, i32* %2
%10 = call i32 (i32, i32, ...) bitcast (i32 (...)* @space_forward_block to i32 (i32, i32, ...)*)(i32 %9, i32 1)
%11 = load i32, i32* %2
%12 = call i32 (i32, i32, ...) bitcast (i32 (...)* @read_block to i32 (i32, i32, ...)*)(i32 %11, i32 65536)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0))
%14 = load i32, i32* %2
%15 = call i32 (i32, ...) bitcast (i32 (...)* @rewind_tape to i32 (i32, ...)*)(i32 %14)
%16 = load i32, i32* %2
%17 = call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0))
%20 = load i32, i32* %2
%21 = call i32 (i32, i32, ...) bitcast (i32 (...)* @space_forward_filemark to i32 (i32, i32, ...)*)(i32 %20, i32 100000)
%22 = load i32, i32* %2
%23 = call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %2
%26 = call i32 (i32, i32, ...) bitcast (i32 (...)* @space_back_filemark to i32 (i32, i32, ...)*)(i32 %25, i32 2)
%27 = load i32, i32* %2
%28 = call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %2
%31 = call i32 (i32, i32, ...) bitcast (i32 (...)* @space_back_block to i32 (i32, i32, ...)*)(i32 %30, i32 1)
%32 = load i32, i32* %2
%33 = call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %2
%36 = call i32 (i32, i32, ...) bitcast (i32 (...)* @read_block to i32 (i32, i32, ...)*)(i32 %35, i32 65536)
%37 = load i32, i32* %2
%38 = call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"%s: Did we error here ??\0A\00"
@__func__.read_test_2 = [12 x i8] c"read_test_2\00"
@.str.1 = [14 x i8] c"%s: Block %d\0A\00"
@.str.2 = [65 x i8] c"%s: Note: following space_forward_filemark(100000) should error\0A\00"
define i32 @read_test_2(i32 %0) {
%2 = tail call i32 (i32, ...) bitcast (i32 (...)* @rewind_tape to i32 (i32, ...)*)(i32 %0)
%3 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @space_forward_filemark to i32 (i32, i32, ...)*)(i32 %0, i32 3)
%4 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @read_block to i32 (i32, i32, ...)*)(i32 %0, i32 65536)
%5 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @space_forward_block to i32 (i32, i32, ...)*)(i32 %0, i32 1)
%6 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @read_block to i32 (i32, i32, ...)*)(i32 %0, i32 65536)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0))
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @rewind_tape to i32 (i32, ...)*)(i32 %0)
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0))
%12 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @space_forward_filemark to i32 (i32, i32, ...)*)(i32 %0, i32 100000)
%13 = tail call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %13)
%15 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @space_back_filemark to i32 (i32, i32, ...)*)(i32 %0, i32 2)
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %0)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %16)
%18 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @space_back_block to i32 (i32, i32, ...)*)(i32 %0, i32 1)
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %0)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %19)
%21 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @read_block to i32 (i32, i32, ...)*)(i32 %0, i32 65536)
%22 = tail call i32 (i32, ...) bitcast (i32 (...)* @read_block_position to i32 (i32, ...)*)(i32 %0)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__func__.read_test_2, i64 0, i64 0), i32 %22)
ret i32 0
}