#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 */
char EOF;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(char);
int main() {
  FILE *fp = fopen("out", "r+");
  if (fp == NULL) {
    printf("open file error");
    return 1;
  }
  char c10, c20;
  fseek(fp, 9, SEEK_SET);
  c10 = getc(fp);
  fseek(fp, 9, SEEK_CUR);
  c20 = getc(fp);
  fseek(fp, -11, SEEK_CUR);
  putc(c20, fp);
  fseek(fp, -8, SEEK_END);
  putc(c10, fp);
  fseek(fp, 0, SEEK_SET);
  char c;
  while ((c = fgetc(fp)) != EOF) {
    putchar(c);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c9 <main+0x49>
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ae <main+0x12e>
mov    -0x10(%rbp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    $0x9,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <getc@plt>
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
mov    $0x9,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <getc@plt>
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff5,%esi
call   1080 <fseek@plt>
mov    -0x12(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1070 <putc@plt>
mov    -0x10(%rbp),%rdi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff8,%esi
call   1080 <fseek@plt>
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1070 <putc@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d62(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x13(%rbp)
movsbl %al,%eax
mov    0x2d53(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     129e <main+0x11e>
movsbl -0x13(%rbp),%edi
call   1030 <putchar@plt>
jmp    126f <main+0xef>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe71(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     126f <main+0xef>
mov    %rax,%rbx
mov    0x2e1a(%rip),%r15
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0x9,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <getc@plt>
mov    %eax,%r12d
mov    0x2e10(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <getc@plt>
mov    %eax,%r14d
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0xfffffff5,%esi
call   1080 <fseek@plt>
movsbl %r14b,%edi
mov    %rbx,%rsi
call   1070 <putc@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xfffffff8,%esi
call   1080 <fseek@plt>
movsbl %r12b,%edi
mov    %rbx,%rsi
call   1070 <putc@plt>
mov    (%r15),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2d90(%rip),%rbp
cmp    0x0(%rbp),%al
je     1265 <main+0xe5>
nopl   (%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%rbp),%al
jne    1250 <main+0xd0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1281 <main+0x101>
lea    0xd91(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"out\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [16 x i8] c"open file error\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %50
11: ; preds = %0
%12 = load i32*, i32** %2
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @fseek(i32* %12, i32 9, i32 %13)
%15 = load i32*, i32** %2
%16 = call signext i8 @getc(i32* %15)
store i8 %16, i8* %3
%17 = load i32*, i32** %2
%18 = load i32, i32* @SEEK_CUR
%19 = call i32 @fseek(i32* %17, i32 9, i32 %18)
%20 = load i32*, i32** %2
%21 = call signext i8 @getc(i32* %20)
store i8 %21, i8* %4
%22 = load i32*, i32** %2
%23 = load i32, i32* @SEEK_CUR
%24 = call i32 @fseek(i32* %22, i32 -11, i32 %23)
%25 = load i8, i8* %4
%26 = load i32*, i32** %2
%27 = call i32 @putc(i8 signext %25, i32* %26)
%28 = load i32*, i32** %2
%29 = load i32, i32* @SEEK_END
%30 = call i32 @fseek(i32* %28, i32 -8, i32 %29)
%31 = load i8, i8* %3
%32 = load i32*, i32** %2
%33 = call i32 @putc(i8 signext %31, i32* %32)
%34 = load i32*, i32** %2
%35 = load i32, i32* @SEEK_SET
%36 = call i32 @fseek(i32* %34, i32 0, i32 %35)
br label %37
37: ; preds = %44, %11
%38 = load i32*, i32** %2
%39 = call signext i8 @fgetc(i32* %38)
store i8 %39, i8* %5
%40 = sext i8 %39 to i32
%41 = load i8, i8* @EOF
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %40, %42
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = load i8, i8* %5
%46 = call i32 @putchar(i8 signext %45)
br label %37
47: ; preds = %37
%48 = load i32*, i32** %2
%49 = call i32 @fclose(i32* %48)
store i32 0, i32* %1
br label %50
50: ; preds = %47, %9
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [4 x i8] c"out\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [16 x i8] c"open file error\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@EOF = global i8 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %31
5: ; preds = %0
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i32* %1, i32 9, i32 %6)
%8 = tail call signext i8 @getc(i32* %1)
%9 = load i32, i32* @SEEK_CUR
%10 = tail call i32 @fseek(i32* %1, i32 9, i32 %9)
%11 = tail call signext i8 @getc(i32* %1)
%12 = load i32, i32* @SEEK_CUR
%13 = tail call i32 @fseek(i32* %1, i32 -11, i32 %12)
%14 = tail call i32 @putc(i8 signext %11, i32* %1)
%15 = load i32, i32* @SEEK_END
%16 = tail call i32 @fseek(i32* %1, i32 -8, i32 %15)
%17 = tail call i32 @putc(i8 signext %8, i32* %1)
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @fseek(i32* %1, i32 0, i32 %18)
%20 = tail call signext i8 @fgetc(i32* %1)
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %20, %21
br i1 %22, label %29, label %23
23: ; preds = %5, %23
%24 = phi i8 [ %26, %23 ], [ %20, %5 ]
%25 = tail call i32 @putchar(i8 signext %24)
%26 = tail call signext i8 @fgetc(i32* %1)
%27 = load i8, i8* @EOF
%28 = icmp eq i8 %26, %27
br i1 %28, label %29, label %23
29: ; preds = %23, %5
%30 = tail call i32 @fclose(i32* %1)
br label %31
31: ; preds = %29, %3
%32 = phi i32 [ 1, %3 ], [ 0, %29 ]
ret i32 %32
}