#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_SET;
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open_rdwr(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int execute_lseek() {
  int fd = open_rdwr("syscalls.txt");
  write(fd, "abcdefghijklmnopqrstuvwxyz", 26);
  char buffer[10];
  lseek(fd, 1, SEEK_SET);
  read(fd, buffer, 10);
  lseek(fd, 5, SEEK_CUR);
  read(fd, buffer, 10);
  return 0;
}


x86 assembly (clang, -O0):
<execute_lseek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1050 <open_rdwr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0xeac(%rip),%rsi
mov    $0x1a,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1040 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    -0x4(%rbp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1040 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_lseek>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeb2(%rip),%rdi
call   1050 <open_rdwr@plt>
mov    %eax,%ebx
lea    0xeb1(%rip),%rsi
mov    %eax,%edi
mov    $0x1a,%edx
call   1030 <write@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x1,%esi
call   1040 <lseek@plt>
lea    0xe(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x5,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"syscalls.txt\00"
@.str.1 = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define i32 @execute_lseek() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = call i32 @open_rdwr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = call i32 @write(i32 %4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 26)
%6 = load i32, i32* %1
%7 = load i32, i32* @SEEK_SET
%8 = call i32 @lseek(i32 %6, i32 1, i32 %7)
%9 = load i32, i32* %1
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 10)
%12 = load i32, i32* %1
%13 = load i32, i32* @SEEK_CUR
%14 = call i32 @lseek(i32 %12, i32 5, i32 %13)
%15 = load i32, i32* %1
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"syscalls.txt\00"
@.str.1 = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define i32 @execute_lseek() {
%1 = alloca [10 x i8]
%2 = tail call i32 @open_rdwr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 26)
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @lseek(i32 %2, i32 1, i32 %5)
%7 = call i32 @read(i32 %2, i8* %4, i32 10)
%8 = load i32, i32* @SEEK_CUR
%9 = tail call i32 @lseek(i32 %2, i32 5, i32 %8)
%10 = call i32 @read(i32 %2, i8* %4, i32 10)
ret i32 0
}