#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_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void file_seek(void) {
  FILE *f;
  int i;
  if ((f = fopen("tmp", "wb+")) == NULL) {
    printf("IO error\n");
    exit(0);
  }
  for (i = 1; i <= 10; i++)
    fwrite(&i, sizeof(int), 1, f);
  fseek(f, 3 * sizeof(int), SEEK_SET);
  fread(&i, sizeof(int), 1, f);
  printf("%d ", i);
  fseek(f, 4 * sizeof(int), SEEK_CUR);
  fread(&i, sizeof(int), 1, f);
  printf("%d ", i);
  fseek(f, -4 * sizeof(int), SEEK_END);
  fread(&i, sizeof(int), 1, f);
  printf("%d\n", i);
}


x86 assembly (clang, -O0):
<file_seek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    119e <file_seek+0x3e>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jg     11d4 <file_seek+0x74>
mov    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a5 <file_seek+0x45>
mov    -0x8(%rbp),%rdi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0xc(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2dc2(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0xc(%rbp),%esi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2d8b(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff0,%esi
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0xc(%rbp),%esi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_seek>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe80(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1299 <file_seek+0x129>
mov    %rax,%r15
movl   $0x1,0xc(%rsp)
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    0xc(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0xa,%eax
jl     11b0 <file_seek+0x40>
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0xc,%esi
call   1060 <fseek@plt>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    0xc(%rsp),%esi
lea    0xdf8(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x10,%esi
call   1060 <fseek@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0xfffffff0,%esi
call   1060 <fseek@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    0xc(%rsp),%esi
lea    0xd83(%rip),%rdi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <printf@plt>
lea    0xd70(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"tmp\00"
@.str.1 = [4 x i8] c"wb+\00"
@.str.2 = [10 x i8] c"IO error\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [4 x i8] c"%d \00"
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@.str.4 = [4 x i8] c"%d\0A\00"
define void @file_seek() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @exit(i32 0)
unreachable
8: ; preds = %0
store i32 1, i32* %2
br label %9
9: ; preds = %15, %8
%10 = load i32, i32* %2
%11 = icmp sle i32 %10, 10
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i32*, i32** %1
%14 = call i32 @fwrite(i32* %2, i32 4, i32 1, i32* %13)
br label %15
15: ; preds = %12
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %9
18: ; preds = %9
%19 = load i32*, i32** %1
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %19, i32 12, i32 %20)
%22 = load i32*, i32** %1
%23 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %22)
%24 = load i32, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32*, i32** %1
%27 = load i32, i32* @SEEK_CUR
%28 = call i32 @fseek(i32* %26, i32 16, i32 %27)
%29 = load i32*, i32** %1
%30 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %29)
%31 = load i32, i32* %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %1
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 -16, i32 %34)
%36 = load i32*, i32** %1
%37 = call i32 @fread(i32* %2, i32 4, i32 1, i32* %36)
%38 = load i32, i32* %2
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %38)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"tmp\00"
@.str.1 = [4 x i8] c"wb+\00"
@SEEK_SET = global i32 0
@.str.3 = [4 x i8] c"%d \00"
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@.str.4 = [4 x i8] c"%d\0A\00"
@str = [9 x i8] c"IO error\00"
define void @file_seek() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %6, label %5
5: ; preds = %0
store i32 1, i32* %1
br label %9
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %5, %9
%10 = call i32 @fwrite(i32* %1, i32 4, i32 1, i32* %3)
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
store i32 %12, i32* %1
%13 = icmp slt i32 %11, 10
br i1 %13, label %9, label %14
14: ; preds = %9
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %3, i32 12, i32 %15)
%17 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %3)
%18 = load i32, i32* %1
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @SEEK_CUR
%21 = tail call i32 @fseek(i32* %3, i32 16, i32 %20)
%22 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %3)
%23 = load i32, i32* %1
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @SEEK_END
%26 = tail call i32 @fseek(i32* %3, i32 -16, i32 %25)
%27 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %3)
%28 = load i32, i32* %1
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %28)
ret void
}