#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_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ read(int, char *, int);
int main() {
  int handle = open("lseek.txt", O_RDONLY);
  int len = lseek(handle, 0, SEEK_END);
  int i = 0;
  char ch;
  lseek(handle, 0, SEEK_SET);
  for (; i < len; i++) {
    read(handle, &ch, 1);
    printf("%d:%c\n", i, ch);
  }
  printf("len :%d\n", len);
  close(handle);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e7 <main+0x97>
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    -0x10(%rbp),%esi
movsbl -0x11(%rbp),%edx
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a7 <main+0x57>
mov    -0xc(%rbp),%esi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r12d
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,%ebp
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %ebp,%ebp
jle    11d8 <main+0x88>
lea    0xf(%rsp),%r14
lea    0xe5e(%rip),%r15
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl 0xf(%rsp),%edx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    11b0 <main+0x60>
lea    0xe32(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"lseek.txt\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [7 x i8] c"%d:%c\0A\00"
@.str.2 = [9 x i8] c"len :%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = load i32, i32* @SEEK_END
%10 = call i32 @lseek(i32 %8, i32 0, i32 %9)
store i32 %10, i32* %3
store i32 0, i32* %4
%11 = load i32, i32* %2
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @lseek(i32 %11, i32 0, i32 %12)
br label %14
14: ; preds = %25, %0
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = load i32, i32* %2
%20 = call i32 @read(i32 %19, i8* %5, i32 1)
%21 = load i32, i32* %4
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %23)
br label %25
25: ; preds = %18
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %14
28: ; preds = %14
%29 = load i32, i32* %3
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %2
%32 = call i32 @close(i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"lseek.txt\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [7 x i8] c"%d:%c\0A\00"
@.str.2 = [9 x i8] c"len :%d\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @lseek(i32 %3, i32 0, i32 %4)
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @lseek(i32 %3, i32 0, i32 %6)
%8 = icmp sgt i32 %5, 0
br i1 %8, label %9, label %17
9: ; preds = %0, %9
%10 = phi i32 [ %15, %9 ], [ 0, %0 ]
%11 = call i32 @read(i32 %3, i8* %1, i32 1)
%12 = load i8, i8* %1
%13 = sext i8 %12 to i32
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %13)
%15 = add nuw nsw i32 %10, 1
%16 = icmp eq i32 %15, %5
br i1 %16, label %17, label %9
17: ; preds = %9, %0
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%19 = tail call i32 @close(i32 %3)
ret i32 0
}