#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 off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, long, scalar_t__, char *);
int /*<<< orphan*/ stop();
char *strerrno(scalar_t__);
int test_lseek() {
  int fd;
  off_t ret = 0;
  errno = 0;
  fd = open("foo.fileio.test", O_RDONLY);
  if (fd >= 0) {
    errno = 0;
    ret = lseek(fd, 0, SEEK_CUR);
    printf("lseek 1: ret = %ld, errno = %d, %s\n", (long)ret, errno,
           ret == 0 ? "OK" : "");
    stop();
    errno = 0;
    ret = lseek(fd, 0, SEEK_END);
    printf("lseek 2: ret = %ld, errno = %d, %s\n", (long)ret, errno,
           ret == 11 ? "OK" : "");
    stop();
    errno = 0;
    ret = lseek(fd, 3, SEEK_SET);
    printf("lseek 3: ret = %ld, errno = %d, %s\n", (long)ret, errno,
           ret == 3 ? "OK" : "");
    close(fd);
  } else {
    printf("lseek 1: ret = %ld, errno = %d %s\n", (long)ret, errno,
           strerrno(errno));
    stop();
    printf("lseek 2: ret = %ld, errno = %d %s\n", (long)ret, errno,
           strerrno(errno));
    stop();
    printf("lseek 3: ret = %ld, errno = %d %s\n", (long)ret, errno,
           strerrno(errno));
  }
  stop();
}


x86 assembly (clang, -O0):
<test_lseek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0xc(%rbp)
mov    0x2e52(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe73(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     12bf <test_lseek+0x15f>
mov    0x2e22(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rsi
mov    0x2dfa(%rip),%rax
mov    (%rax),%rdx
mov    -0xc(%rbp),%edi
lea    0xe58(%rip),%rcx
lea    0xe52(%rip),%rax
cmp    $0x0,%edi
cmove  %rax,%rcx
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <stop@plt>
mov    0x2dc5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rsi
mov    0x2d9d(%rip),%rax
mov    (%rax),%rdx
mov    -0xc(%rbp),%edi
lea    0xdfb(%rip),%rcx
lea    0xdf5(%rip),%rax
cmp    $0xb,%edi
cmove  %rax,%rcx
lea    0xdea(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <stop@plt>
mov    0x2d68(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%edx
mov    $0x3,%esi
call   1050 <lseek@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rsi
mov    0x2d3d(%rip),%rax
mov    (%rax),%rdx
mov    -0xc(%rbp),%edi
lea    0xd9b(%rip),%rcx
lea    0xd95(%rip),%rax
cmp    $0x3,%edi
cmove  %rax,%rcx
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
jmp    1381 <test_lseek+0x221>
movslq -0xc(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2cec(%rip),%rax
mov    (%rax),%rdi
call   1030 <strerrno@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd89(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <stop@plt>
movslq -0xc(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cb7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2ca9(%rip),%rax
mov    (%rax),%rdi
call   1030 <strerrno@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xd69(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <stop@plt>
movslq -0xc(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c74(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2c66(%rip),%rax
mov    (%rax),%rdi
call   1030 <strerrno@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xd49(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <stop@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_lseek>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e5a(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     125a <test_lseek+0xfa>
mov    %eax,%ebp
movq   $0x0,(%r14)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
movslq %eax,%rsi
mov    (%r14),%rdx
test   %esi,%esi
lea    0xe78(%rip),%r15
lea    0xe70(%rip),%rbx
mov    %rbx,%rcx
cmove  %r15,%rcx
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <stop@plt>
movq   $0x0,(%r14)
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
movslq %eax,%rsi
mov    (%r14),%rdx
cmp    $0xb,%esi
mov    %rbx,%rcx
cmove  %r15,%rcx
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <stop@plt>
movq   $0x0,(%r14)
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x3,%esi
call   1050 <lseek@plt>
movslq %eax,%rsi
mov    (%r14),%rdx
cmp    $0x3,%esi
cmove  %r15,%rbx
lea    0xe12(%rip),%rdi
mov    %rbx,%rcx
call   1040 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    12c5 <test_lseek+0x165>
mov    (%r14),%rbx
mov    %rbx,%rdi
call   1030 <strerrno@plt>
lea    0xe13(%rip),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <stop@plt>
mov    (%r14),%rbx
mov    %rbx,%rdi
call   1030 <strerrno@plt>
lea    0xe10(%rip),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <stop@plt>
mov    (%r14),%rbx
mov    %rbx,%rdi
call   1030 <strerrno@plt>
lea    0xe0d(%rip),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <stop@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [16 x i8] c"foo.fileio.test\00"
@O_RDONLY = global i32 0
@SEEK_CUR = global i32 0
@.str.1 = [36 x i8] c"lseek 1: ret = %ld, errno = %d, %s\0A\00"
@.str.2 = [3 x i8] c"OK\00"
@.str.3 = [1 x i8] zeroinitializer
@SEEK_END = global i32 0
@.str.4 = [36 x i8] c"lseek 2: ret = %ld, errno = %d, %s\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [36 x i8] c"lseek 3: ret = %ld, errno = %d, %s\0A\00"
@.str.6 = [35 x i8] c"lseek 1: ret = %ld, errno = %d %s\0A\00"
@.str.7 = [35 x i8] c"lseek 2: ret = %ld, errno = %d %s\0A\00"
@.str.8 = [35 x i8] c"lseek 3: ret = %ld, errno = %d %s\0A\00"
define i32 @test_lseek() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
store i64 0, i64* @errno
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %46
8: ; preds = %0
store i64 0, i64* @errno
%9 = load i32, i32* %2
%10 = load i32, i32* @SEEK_CUR
%11 = call i32 @lseek(i32 %9, i32 0, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = load i64, i64* @errno
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%19 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %13, i64 %14, i8* %18)
%20 = call i32 (...) @stop()
store i64 0, i64* @errno
%21 = load i32, i32* %2
%22 = load i32, i32* @SEEK_END
%23 = call i32 @lseek(i32 %21, i32 0, i32 %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = load i64, i64* @errno
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 11
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%31 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i64 %25, i64 %26, i8* %30)
%32 = call i32 (...) @stop()
store i64 0, i64* @errno
%33 = load i32, i32* %2
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @lseek(i32 %33, i32 3, i32 %34)
store i32 %35, i32* %3
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = load i64, i64* @errno
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, 3
%41 = zext i1 %40 to i64
%42 = select i1 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%43 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i64 %37, i64 %38, i8* %42)
%44 = load i32, i32* %2
%45 = call i32 @close(i32 %44)
br label %67
46: ; preds = %0
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = load i64, i64* @errno
%50 = load i64, i64* @errno
%51 = call i8* @strerrno(i64 %50)
%52 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i64 %48, i64 %49, i8* %51)
%53 = call i32 (...) @stop()
%54 = load i32, i32* %3
%55 = sext i32 %54 to i64
%56 = load i64, i64* @errno
%57 = load i64, i64* @errno
%58 = call i8* @strerrno(i64 %57)
%59 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i64 %55, i64 %56, i8* %58)
%60 = call i32 (...) @stop()
%61 = load i32, i32* %3
%62 = sext i32 %61 to i64
%63 = load i64, i64* @errno
%64 = load i64, i64* @errno
%65 = call i8* @strerrno(i64 %64)
%66 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i64 %62, i64 %63, i8* %65)
br label %67
67: ; preds = %46, %8
%68 = call i32 (...) @stop()
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [16 x i8] c"foo.fileio.test\00"
@O_RDONLY = global i32 0
@SEEK_CUR = global i32 0
@.str.1 = [36 x i8] c"lseek 1: ret = %ld, errno = %d, %s\0A\00"
@.str.2 = [3 x i8] c"OK\00"
@.str.3 = [1 x i8] zeroinitializer
@SEEK_END = global i32 0
@.str.4 = [36 x i8] c"lseek 2: ret = %ld, errno = %d, %s\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [36 x i8] c"lseek 3: ret = %ld, errno = %d, %s\0A\00"
@.str.6 = [35 x i8] c"lseek 1: ret = %ld, errno = %d %s\0A\00"
@.str.7 = [35 x i8] c"lseek 2: ret = %ld, errno = %d %s\0A\00"
@.str.8 = [35 x i8] c"lseek 3: ret = %ld, errno = %d %s\0A\00"
define i32 @test_lseek() {
store i64 0, i64* @errno
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp sgt i32 %2, -1
br i1 %3, label %4, label %29
4: ; preds = %0
store i64 0, i64* @errno
%5 = load i32, i32* @SEEK_CUR
%6 = tail call i32 @lseek(i32 %2, i32 0, i32 %5)
%7 = sext i32 %6 to i64
%8 = load i64, i64* @errno
%9 = icmp eq i32 %6, 0
%10 = select i1 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %7, i64 %8, i8* %10)
%12 = tail call i32 (...) @stop()
store i64 0, i64* @errno
%13 = load i32, i32* @SEEK_END
%14 = tail call i32 @lseek(i32 %2, i32 0, i32 %13)
%15 = sext i32 %14 to i64
%16 = load i64, i64* @errno
%17 = icmp eq i32 %14, 11
%18 = select i1 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i64 %15, i64 %16, i8* %18)
%20 = tail call i32 (...) @stop()
store i64 0, i64* @errno
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @lseek(i32 %2, i32 3, i32 %21)
%23 = sext i32 %22 to i64
%24 = load i64, i64* @errno
%25 = icmp eq i32 %22, 3
%26 = select i1 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i64 %23, i64 %24, i8* %26)
%28 = tail call i32 @close(i32 %2)
br label %41
29: ; preds = %0
%30 = load i64, i64* @errno
%31 = tail call i8* @strerrno(i64 %30)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i64 0, i64 %30, i8* %31)
%33 = tail call i32 (...) @stop()
%34 = load i64, i64* @errno
%35 = tail call i8* @strerrno(i64 %34)
%36 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i64 0, i64 %34, i8* %35)
%37 = tail call i32 (...) @stop()
%38 = load i64, i64* @errno
%39 = tail call i8* @strerrno(i64 %38)
%40 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i64 0, i64 %38, i8* %39)
br label %41
41: ; preds = %29, %4
%42 = tail call i32 (...) @stop()
ret i32 undef
}