#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*/ input;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int STDOUT_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ scanf(char *, int *, int *);
int write(int, ...);
int main(void) {
  int n, fd, k, input;
  char buf[4096];
  fd = open("feilunzhou.txt", O_RDWR);
  while ((n = read(fd, buf, 4096)) > 0)
    if (write(STDOUT_FILENO, buf, n) != n)
      perror("write error");
  input = 0;
  printf("please input your number and offset\n");
  scanf("%d %d", &input, &k);
  printf("the size of your input string is %d", sizeof(input));
  lseek(fd, k, SEEK_SET);
  write(fd, &input, sizeof(input));
  if (n < 0)
    perror("read error");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11fe <main+0x7e>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    -0x8(%rbp),%eax
je     11f9 <main+0x79>
lea    0xe1b(%rip),%rdi
call   1090 <perror@plt>
jmp    11aa <main+0x2a>
movl   $0x0,-0x14(%rbp)
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe26(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1070 <scanf@plt>
lea    0xe18(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    -0xc(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmpl   $0x0,-0x8(%rbp)
jge    1277 <main+0xf7>
lea    0xdf8(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1010,%rsp
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0xe51(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1224 <main+0x94>
mov    0x2e1b(%rip),%r12
lea    0x10(%rsp),%rbx
lea    0xe2e(%rip),%r15
jmp    1206 <main+0x76>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1224 <main+0x94>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <write@plt>
cmp    %ebp,%eax
je     11f0 <main+0x60>
mov    %r15,%rdi
call   10a0 <perror@plt>
jmp    11f0 <main+0x60>
movl   $0x0,0x8(%rsp)
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
lea    0xddc(%rip),%rdi
lea    0x8(%rsp),%rbx
lea    0xc(%rsp),%rdx
mov    %rbx,%rsi
call   1080 <scanf@plt>
lea    0xdc9(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x2d61(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
call   1060 <lseek@plt>
mov    $0x4,%edx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <write@plt>
test   %ebp,%ebp
jns    129b <main+0x10b>
lea    0xdaf(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"feilunzhou.txt\00"
@O_RDWR = global i32 0
@STDOUT_FILENO = global i32 0
@.str.1 = [12 x i8] c"write error\00"
@.str.2 = [37 x i8] c"please input your number and offset\0A\00"
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [36 x i8] c"the size of your input string is %d\00"
@SEEK_SET = global i32 0
@.str.5 = [11 x i8] c"read error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4096 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %3
br label %9
9: ; preds = %23, %0
%10 = load i32, i32* %3
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 4096)
store i32 %12, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = load i32, i32* @STDOUT_FILENO
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* %2
%18 = call i32 (i32, ...) @write(i32 %15, i8* %16, i32 %17)
%19 = load i32, i32* %2
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
br label %9
24: ; preds = %9
store i32 0, i32* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %5, i32* %4)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i64 4)
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @lseek(i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* %3
%33 = call i32 (i32, ...) @write(i32 %32, i32* %5, i64 4)
%34 = load i32, i32* %2
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %24
%37 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %36, %24
%39 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [15 x i8] c"feilunzhou.txt\00"
@O_RDWR = global i32 0
@STDOUT_FILENO = global i32 0
@.str.1 = [12 x i8] c"write error\00"
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [36 x i8] c"the size of your input string is %d\00"
@SEEK_SET = global i32 0
@.str.5 = [11 x i8] c"read error\00"
@str = [36 x i8] c"please input your number and offset\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4096 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @read(i32 %8, i8* %6, i32 4096)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %0, %18
%12 = phi i32 [ %19, %18 ], [ %9, %0 ]
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 (i32, ...) @write(i32 %13, i8* %6, i32 %12)
%15 = icmp eq i32 %14, %12
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = call i32 @read(i32 %8, i8* %6, i32 4096)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %11, label %21
21: ; preds = %18, %0
%22 = phi i32 [ %9, %0 ], [ %19, %18 ]
store i32 0, i32* %2
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32* %1)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i64 4)
%26 = load i32, i32* %1
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @lseek(i32 %8, i32 %26, i32 %27)
%29 = call i32 (i32, ...) @write(i32 %8, i32* %2, i64 4)
%30 = icmp slt i32 %22, 0
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %33
33: ; preds = %31, %21
%34 = call i32 @exit(i32 0)
unreachable
}