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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
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 main(int argc, char *argv[]) {
  int fd, offset;
  char buf[10];
  fd = open("feilunzhou.txt", O_RDWR);
  printf("please input your offset!\n");
  scanf("%d", &offset);
  lseek(fd, offset, SEEK_SET);
  if (read(fd, buf, 10) != 10)
    perror("read error!");
  printf("%s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe87(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
cmp    $0xa,%eax
je     11e6 <main+0x86>
lea    0xe4c(%rip),%rdi
call   1080 <perror@plt>
lea    -0x22(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe80(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
mov    (%rsp),%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1040 <lseek@plt>
lea    0x6(%rsp),%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1050 <read@plt>
cmp    $0xa,%eax
jne    11d2 <main+0x72>
lea    0x6(%rsp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe39(%rip),%rdi
call   1080 <perror@plt>
jmp    11c0 <main+0x60>

LLVM IR (-O0):
@.str = [15 x i8] c"feilunzhou.txt\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"please input your offset!\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"read error!\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @lseek(i32 %13, i32 %14, i32 %15)
%17 = load i32, i32* %6
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 10)
%20 = icmp ne i32 %19, 10
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %2
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"feilunzhou.txt\00"
@O_RDWR = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"read error!\00"
@str = [26 x i8] c"please input your offset!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, 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 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @lseek(i32 %8, i32 %11, i32 %12)
%14 = call i32 @read(i32 %8, i8* %6, i32 10)
%15 = icmp eq i32 %14, 10
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = call i32 @puts(i8* %6)
ret i32 0
}