#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*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ my_err(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int my_read(int fd) {
  int len;
  int ret;
  int i;
  char read_buf[64];
  if (lseek(fd, 0, SEEK_END) == -1) {
    my_err("lseek", 83);
  }
  if ((len = lseek(fd, 0, SEEK_CUR)) == -1) {
    my_err("lseek", 86);
  }
  if (lseek(fd, 0, SEEK_SET) == -1) {
    my_err("lseek", 89);
  }
  printf("len:%d\n", len);
  if ((ret = read(fd, read_buf, len)) < 0) {
    my_err("read", 95);
  }
  for (i = 0; i < len; i++) {
    printf("%c", read_buf[i]);
  }
  printf("\n");
  return ret;
}


x86 assembly (clang, -O0):
<my_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1178 <my_read+0x38>
lea    0xe92(%rip),%rdi
mov    $0x53,%esi
call   1060 <my_err@plt>
mov    -0x4(%rbp),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11a8 <my_read+0x68>
lea    0xe62(%rip),%rdi
mov    $0x56,%esi
call   1060 <my_err@plt>
mov    -0x4(%rbp),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11d5 <my_read+0x95>
lea    0xe35(%rip),%rdi
mov    $0x59,%esi
call   1060 <my_err@plt>
mov    -0x8(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1212 <my_read+0xd2>
lea    0xe06(%rip),%rdi
mov    $0x5f,%esi
call   1060 <my_err@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    124a <my_read+0x10a>
movslq -0x10(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1219 <my_read+0xd9>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_read>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %edi,%ebx
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1180 <my_read+0x30>
lea    0xe8a(%rip),%rdi
mov    $0x53,%esi
call   1070 <my_err@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11aa <my_read+0x5a>
lea    0xe60(%rip),%rdi
mov    $0x56,%esi
call   1070 <my_err@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11d2 <my_read+0x82>
lea    0xe38(%rip),%rdi
mov    $0x59,%esi
call   1070 <my_err@plt>
lea    0xe2d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1060 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
js     11fb <my_read+0xab>
test   %ebp,%ebp
jg     1210 <my_read+0xc0>
jmp    1232 <my_read+0xe2>
lea    0xe0c(%rip),%rdi
mov    $0x5f,%esi
call   1070 <my_err@plt>
test   %ebp,%ebp
jle    1232 <my_read+0xe2>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rsp,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1220 <my_read+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [6 x i8] c"lseek\00"
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [8 x i8] c"len:%d\0A\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @my_read(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [64 x i8]
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = load i32, i32* @SEEK_END
%9 = call i32 @lseek(i32 %7, i32 0, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 83)
br label %13
13: ; preds = %11, %1
%14 = load i32, i32* %2
%15 = load i32, i32* @SEEK_CUR
%16 = call i32 @lseek(i32 %14, i32 0, i32 %15)
store i32 %16, i32* %3
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 86)
br label %20
20: ; preds = %18, %13
%21 = load i32, i32* %2
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @lseek(i32 %21, i32 0, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 89)
br label %27
27: ; preds = %25, %20
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %2
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%32 = load i32, i32* %3
%33 = call i32 @read(i32 %30, i8* %31, i32 %32)
store i32 %33, i32* %4
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %27
%36 = call i32 @my_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 95)
br label %37
37: ; preds = %35, %27
store i32 0, i32* %5
br label %38
38: ; preds = %49, %37
%39 = load i32, i32* %5
%40 = load i32, i32* %3
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
br label %38
52: ; preds = %38
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [6 x i8] c"lseek\00"
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [8 x i8] c"len:%d\0A\00"
@.str.2 = [5 x i8] c"read\00"
define i32 @my_read(i32 %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @lseek(i32 %0, i32 0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 83)
br label %9
9: ; preds = %7, %1
%10 = load i32, i32* @SEEK_CUR
%11 = tail call i32 @lseek(i32 %0, i32 0, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 86)
br label %15
15: ; preds = %13, %9
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @lseek(i32 %0, i32 0, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 89)
br label %21
21: ; preds = %19, %15
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%23 = call i32 @read(i32 %0, i8* %3, i32 %11)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @my_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 95)
br label %27
27: ; preds = %25, %21
%28 = icmp sgt i32 %11, 0
br i1 %28, label %29, label %39
29: ; preds = %27
%30 = zext i32 %11 to i64
br label %31
31: ; preds = %29, %31
%32 = phi i64 [ 0, %29 ], [ %37, %31 ]
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = tail call i32 @putchar(i32 %35)
%37 = add nuw nsw i64 %32, 1
%38 = icmp eq i64 %37, %30
br i1 %38, label %39, label %31
39: ; preds = %31, %27
%40 = tail call i32 @putchar(i32 10)
ret i32 %23
}