#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 /*<<< orphan*/ tests;
typedef int off_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long, int, ...);
int fseek(int /*<<< orphan*/ *, int, int);
int fseeko(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int lseek(int, int, int);
int /*<<< orphan*/ memset(char *, int, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
int main(void) {
  struct {
    off_t offset;
    int whence;
  } tests[] = {{0x00, SEEK_SET}, {0x01, SEEK_SET}, {0xFF, SEEK_SET}};
  char buf[2000];
  off_t ret;
  int i, fd;
  FILE *fp;
  int tmp;
  fd = open("lseek.out", O_RDWR | O_CREAT, 0600);
  if (fd == -1) {
    perror("open(lseek.out) failed");
    return 1;
  }
  unlink("lseek.out");
  fp = fdopen(fd, "rw");
  if (fp == NULL) {
    perror("fopen(lseek.out) failed");
    return 1;
  }
  memset(buf, 0xAB, sizeof(buf));
  ret = write(fd, buf, sizeof(buf));
  if (ret != sizeof(buf)) {
    fprintf(stderr,
            "write() failed to write %zi bytes (wrote %li): ", sizeof(buf),
            (long)ret);
    perror("");
    return 1;
  }
  tmp = fseeko(fp, 1024, SEEK_SET);
  assert(tmp == 0);
  tmp = fseeko(fp, (off_t)-16, SEEK_CUR);
  assert(tmp == 0);
  ret = ftell(fp);
  if (ret != (1024 - 16)) {
    fprintf(stderr,
            "ftell() failed, we wanted pos %i but got %li: ", (1024 - 16),
            (long)ret);
    perror("");
    return 1;
  }
  for (i = 0; i < (sizeof(tests) / sizeof(*tests)); ++i) {
    ret = lseek(fd, tests[i].offset, tests[i].whence);
    if (ret != tests[i].offset) {
      fprintf(stderr, "lseek(%li,%i) failed (wanted %li, got %li): ",
              (long)tests[i].offset, tests[i].whence, (long)tests[i].offset,
              (long)ret);
      perror("");
      return 1;
    }
    ret = fseek(fp, tests[i].offset, tests[i].whence);
    if (ret != 0) {
      fprintf(stderr, "fseek(%li,%i) failed (wanted 0, got %li): ",
              (long)tests[i].offset, tests[i].whence, (long)ret);
      perror("");
      return 1;
    }
  }
  fclose(fp);
  close(fd);
  printf("Success!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x18(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0xff,-0x10(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
mov    0x2dad(%rip),%rax
or     (%rax),%esi
lea    0xdac(%rip),%rdi
mov    $0x180,%edx
call   10f0 <open@plt>
mov    %eax,-0x7fc(%rbp)
cmpl   $0xffffffff,-0x7fc(%rbp)
jne    1289 <main+0x99>
lea    0xd96(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1595 <main+0x3a5>
lea    0xd70(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x7fc(%rbp),%edi
lea    0xd68(%rip),%rsi
call   10e0 <fdopen@plt>
mov    %rax,-0x808(%rbp)
cmpq   $0x0,-0x808(%rbp)
jne    12d4 <main+0xe4>
lea    0xd4a(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1595 <main+0x3a5>
lea    -0x7f0(%rbp),%rdi
mov    $0xab,%esi
mov    $0x7d0,%edx
call   1080 <memset@plt>
mov    -0x7fc(%rbp),%edi
lea    -0x7f0(%rbp),%rsi
mov    $0x7d0,%edx
call   1040 <write@plt>
mov    %eax,-0x7f4(%rbp)
movslq -0x7f4(%rbp),%rax
cmp    $0x7d0,%rax
je     1357 <main+0x167>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
movslq -0x7f4(%rbp),%rax
mov    %eax,%ecx
lea    0xcf2(%rip),%rsi
mov    $0x7d0,%edx
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    0xd9f(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1595 <main+0x3a5>
mov    -0x808(%rbp),%rdi
mov    0x2c5b(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1100 <fseeko@plt>
mov    %eax,-0x80c(%rbp)
cmpl   $0x0,-0x80c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x808(%rbp),%rdi
mov    0x2c3f(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff0,%esi
call   1100 <fseeko@plt>
mov    %eax,-0x80c(%rbp)
cmpl   $0x0,-0x80c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x808(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %eax,-0x7f4(%rbp)
cmpl   $0x3f0,-0x7f4(%rbp)
je     141e <main+0x22e>
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
movslq -0x7f4(%rbp),%rax
mov    %eax,%ecx
lea    0xc5b(%rip),%rsi
mov    $0x3f0,%edx
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    0xcd8(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1595 <main+0x3a5>
movl   $0x0,-0x7f8(%rbp)
movslq -0x7f8(%rbp),%rax
cmp    $0x3,%rax
jae    156b <main+0x37b>
mov    -0x7fc(%rbp),%edi
movslq -0x7f8(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%esi
movslq -0x7f8(%rbp),%rax
mov    -0x1c(%rbp,%rax,8),%edx
call   1070 <lseek@plt>
mov    %eax,-0x7f4(%rbp)
mov    -0x7f4(%rbp),%eax
movslq -0x7f8(%rbp),%rcx
cmp    -0x20(%rbp,%rcx,8),%eax
je     14d0 <main+0x2e0>
mov    0x2b4a(%rip),%rax
mov    (%rax),%edi
movslq -0x7f8(%rbp),%rax
movslq -0x20(%rbp,%rax,8),%rdx
movslq -0x7f8(%rbp),%rax
mov    -0x1c(%rbp,%rax,8),%ecx
movslq -0x7f8(%rbp),%rax
movslq -0x20(%rbp,%rax,8),%r8
movslq -0x7f4(%rbp),%r9
lea    0xbd3(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    0xc26(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1595 <main+0x3a5>
mov    -0x808(%rbp),%rdi
movslq -0x7f8(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%esi
movslq -0x7f8(%rbp),%rax
mov    -0x1c(%rbp,%rax,8),%edx
call   10d0 <fseek@plt>
mov    %eax,-0x7f4(%rbp)
cmpl   $0x0,-0x7f4(%rbp)
je     1552 <main+0x362>
mov    0x2abc(%rip),%rax
mov    (%rax),%edi
movslq -0x7f8(%rbp),%rax
movslq -0x20(%rbp,%rax,8),%rdx
movslq -0x7f8(%rbp),%rax
mov    -0x1c(%rbp,%rax,8),%ecx
movslq -0x7f4(%rbp),%r8
lea    0xb7e(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    0xba4(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1595 <main+0x3a5>
jmp    1557 <main+0x367>
mov    -0x7f8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7f8(%rbp)
jmp    1428 <main+0x238>
mov    -0x808(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x7fc(%rbp),%edi
call   1090 <close@plt>
lea    0xb53(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x7d0,%rsp
mov    0x2dba(%rip),%r15
mov    (%r15),%r14d
mov    0x2dd0(%rip),%rax
mov    0x2de1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xdde(%rip),%rdi
mov    $0x180,%edx
call   10f0 <open@plt>
cmp    $0xffffffff,%eax
je     1399 <main+0x1a9>
mov    %eax,%r12d
lea    0xdc1(%rip),%rdi
call   1030 <unlink@plt>
lea    0xdbf(%rip),%rsi
mov    %r12d,%edi
call   10e0 <fdopen@plt>
test   %rax,%rax
je     13a5 <main+0x1b5>
mov    %rax,%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0xab,%esi
mov    $0x7d0,%edx
call   1080 <memset@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x7d0,%edx
call   1050 <write@plt>
cmp    $0x7d0,%eax
jne    13b1 <main+0x1c1>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1100 <fseeko@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xfffffff0,%esi
call   1100 <fseeko@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
call   10c0 <ftell@plt>
cmp    $0x3f0,%eax
jne    13c8 <main+0x1d8>
xor    %r15d,%r15d
mov    %r12d,%edi
xor    %esi,%esi
mov    %r14d,%edx
call   1070 <lseek@plt>
test   %eax,%eax
jne    13fe <main+0x20e>
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   10d0 <fseek@plt>
test   %eax,%eax
jne    1429 <main+0x239>
mov    %r12d,%edi
mov    $0x1,%esi
mov    %r14d,%edx
call   1070 <lseek@plt>
cmp    $0x1,%eax
jne    13e8 <main+0x1f8>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
call   10d0 <fseek@plt>
test   %eax,%eax
jne    13f0 <main+0x200>
mov    %r12d,%edi
mov    $0xff,%esi
mov    %r14d,%edx
call   1070 <lseek@plt>
cmp    $0xff,%eax
jne    13f8 <main+0x208>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14d,%edx
call   10d0 <fseek@plt>
test   %eax,%eax
jne    1423 <main+0x233>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r12d,%edi
call   1090 <close@plt>
lea    0xd4f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    145a <main+0x26a>
lea    0xc6e(%rip),%rdi
jmp    1450 <main+0x260>
lea    0xc61(%rip),%rdi
jmp    1450 <main+0x260>
mov    0x2c10(%rip),%rcx
mov    (%rcx),%edi
lea    0xc64(%rip),%rsi
mov    $0x7d0,%edx
jmp    13dd <main+0x1ed>
mov    0x2bf9(%rip),%rcx
mov    (%rcx),%edi
lea    0xc7d(%rip),%rsi
mov    $0x3f0,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1449 <main+0x259>
mov    $0x1,%r15d
jmp    13fe <main+0x20e>
mov    $0x1,%r15d
jmp    1429 <main+0x239>
mov    $0xff,%r15d
mov    0x2bc3(%rip),%rcx
mov    (%rcx),%edi
movslq %eax,%r9
lea    0xc73(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %r15,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1449 <main+0x259>
mov    $0xff,%r15d
mov    0x2b98(%rip),%rcx
mov    (%rcx),%edi
movslq %eax,%r8
lea    0xc75(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0xc04(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%eax
add    $0x7d0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.anon = type { i32, i32 }
@SEEK_SET = global i32 0
@.str = [10 x i8] c"lseek.out\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [23 x i8] c"open(lseek.out) failed\00"
@.str.2 = [3 x i8] c"rw\00"
@.str.3 = [24 x i8] c"fopen(lseek.out) failed\00"
@stderr = global i32 0
@.str.4 = [48 x i8] c"write() failed to write %zi bytes (wrote %li): \00"
@.str.5 = [1 x i8] zeroinitializer
@SEEK_CUR = global i32 0
@.str.6 = [47 x i8] c"ftell() failed, we wanted pos %i but got %li: \00"
@.str.7 = [45 x i8] c"lseek(%li,%i) failed (wanted %li, got %li): \00"
@.str.8 = [43 x i8] c"fseek(%li,%i) failed (wanted 0, got %li): \00"
@.str.9 = [10 x i8] c"Success!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x %struct.anon]
%3 = alloca [2000 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %1
%9 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 0
%10 = getelementptr inbounds %struct.anon, %struct.anon* %9, i32 0, i32 0
store i32 0, i32* %10
%11 = getelementptr inbounds %struct.anon, %struct.anon* %9, i32 0, i32 1
%12 = load i32, i32* @SEEK_SET
store i32 %12, i32* %11
%13 = getelementptr inbounds %struct.anon, %struct.anon* %9, i64 1
%14 = getelementptr inbounds %struct.anon, %struct.anon* %13, i32 0, i32 0
store i32 1, i32* %14
%15 = getelementptr inbounds %struct.anon, %struct.anon* %13, i32 0, i32 1
%16 = load i32, i32* @SEEK_SET
store i32 %16, i32* %15
%17 = getelementptr inbounds %struct.anon, %struct.anon* %13, i64 1
%18 = getelementptr inbounds %struct.anon, %struct.anon* %17, i32 0, i32 0
store i32 255, i32* %18
%19 = getelementptr inbounds %struct.anon, %struct.anon* %17, i32 0, i32 1
%20 = load i32, i32* @SEEK_SET
store i32 %20, i32* %19
%21 = load i32, i32* @O_RDWR
%22 = load i32, i32* @O_CREAT
%23 = or i32 %21, %22
%24 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %23, i32 384)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %0
%28 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %169
29: ; preds = %0
%30 = call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* %6
%32 = call i32* @fdopen(i32 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %169
37: ; preds = %29
%38 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%39 = call i32 @memset(i8* %38, i32 171, i32 2000)
%40 = load i32, i32* %6
%41 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%42 = call i32 @write(i32 %40, i8* %41, i32 2000)
store i32 %42, i32* %4
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = icmp ne i64 %44, 2000
br i1 %45, label %46, label %53
46: ; preds = %37
%47 = load i32, i32* @stderr
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = trunc i64 %49 to i32
%51 = call i32 (i32, i8*, i64, i32, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i64 2000, i32 %50)
%52 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %169
53: ; preds = %37
%54 = load i32*, i32** %7
%55 = load i32, i32* @SEEK_SET
%56 = call i32 @fseeko(i32* %54, i32 1024, i32 %55)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = icmp eq i32 %57, 0
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load i32*, i32** %7
%62 = load i32, i32* @SEEK_CUR
%63 = call i32 @fseeko(i32* %61, i32 -16, i32 %62)
store i32 %63, i32* %8
%64 = load i32, i32* %8
%65 = icmp eq i32 %64, 0
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = load i32*, i32** %7
%69 = call i32 @ftell(i32* %68)
store i32 %69, i32* %4
%70 = load i32, i32* %4
%71 = icmp ne i32 %70, 1008
br i1 %71, label %72, label %79
72: ; preds = %53
%73 = load i32, i32* @stderr
%74 = load i32, i32* %4
%75 = sext i32 %74 to i64
%76 = trunc i64 %75 to i32
%77 = call i32 (i32, i8*, i64, i32, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i64 1008, i32 %76)
%78 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %169
79: ; preds = %53
store i32 0, i32* %5
br label %80
80: ; preds = %160, %79
%81 = load i32, i32* %5
%82 = sext i32 %81 to i64
%83 = icmp ult i64 %82, 3
br i1 %83, label %84, label %163
84: ; preds = %80
%85 = load i32, i32* %6
%86 = load i32, i32* %5
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %87
%89 = getelementptr inbounds %struct.anon, %struct.anon* %88, i32 0, i32 0
%90 = load i32, i32* %89
%91 = load i32, i32* %5
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %92
%94 = getelementptr inbounds %struct.anon, %struct.anon* %93, i32 0, i32 1
%95 = load i32, i32* %94
%96 = call i32 @lseek(i32 %85, i32 %90, i32 %95)
store i32 %96, i32* %4
%97 = load i32, i32* %4
%98 = load i32, i32* %5
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %99
%101 = getelementptr inbounds %struct.anon, %struct.anon* %100, i32 0, i32 0
%102 = load i32, i32* %101
%103 = icmp ne i32 %97, %102
br i1 %103, label %104, label %127
104: ; preds = %84
%105 = load i32, i32* @stderr
%106 = load i32, i32* %5
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %107
%109 = getelementptr inbounds %struct.anon, %struct.anon* %108, i32 0, i32 0
%110 = load i32, i32* %109
%111 = sext i32 %110 to i64
%112 = load i32, i32* %5
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %113
%115 = getelementptr inbounds %struct.anon, %struct.anon* %114, i32 0, i32 1
%116 = load i32, i32* %115
%117 = load i32, i32* %5
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %118
%120 = getelementptr inbounds %struct.anon, %struct.anon* %119, i32 0, i32 0
%121 = load i32, i32* %120
%122 = sext i32 %121 to i64
%123 = load i32, i32* %4
%124 = sext i32 %123 to i64
%125 = call i32 (i32, i8*, i64, i32, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i64 %111, i32 %116, i64 %122, i64 %124)
%126 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %169
127: ; preds = %84
%128 = load i32*, i32** %7
%129 = load i32, i32* %5
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %130
%132 = getelementptr inbounds %struct.anon, %struct.anon* %131, i32 0, i32 0
%133 = load i32, i32* %132
%134 = load i32, i32* %5
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %135
%137 = getelementptr inbounds %struct.anon, %struct.anon* %136, i32 0, i32 1
%138 = load i32, i32* %137
%139 = call i32 @fseek(i32* %128, i32 %133, i32 %138)
store i32 %139, i32* %4
%140 = load i32, i32* %4
%141 = icmp ne i32 %140, 0
br i1 %141, label %142, label %159
142: ; preds = %127
%143 = load i32, i32* @stderr
%144 = load i32, i32* %5
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %145
%147 = getelementptr inbounds %struct.anon, %struct.anon* %146, i32 0, i32 0
%148 = load i32, i32* %147
%149 = sext i32 %148 to i64
%150 = load i32, i32* %5
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %2, i64 0, i64 %151
%153 = getelementptr inbounds %struct.anon, %struct.anon* %152, i32 0, i32 1
%154 = load i32, i32* %153
%155 = load i32, i32* %4
%156 = sext i32 %155 to i64
%157 = call i32 (i32, i8*, i64, i32, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i64 %149, i32 %154, i64 %156)
%158 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %169
159: ; preds = %127
br label %160
160: ; preds = %159
%161 = load i32, i32* %5
%162 = add nsw i32 %161, 1
store i32 %162, i32* %5
br label %80
163: ; preds = %80
%164 = load i32*, i32** %7
%165 = call i32 @fclose(i32* %164)
%166 = load i32, i32* %6
%167 = call i32 @close(i32 %166)
%168 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %1
br label %169
169: ; preds = %163, %142, %104, %72, %46, %35, %27
%170 = load i32, i32* %1
ret i32 %170
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [10 x i8] c"lseek.out\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [23 x i8] c"open(lseek.out) failed\00"
@.str.2 = [3 x i8] c"rw\00"
@.str.3 = [24 x i8] c"fopen(lseek.out) failed\00"
@stderr = global i32 0
@.str.4 = [48 x i8] c"write() failed to write %zi bytes (wrote %li): \00"
@.str.5 = [1 x i8] zeroinitializer
@SEEK_CUR = global i32 0
@.str.6 = [47 x i8] c"ftell() failed, we wanted pos %i but got %li: \00"
@.str.7 = [45 x i8] c"lseek(%li,%i) failed (wanted %li, got %li): \00"
@.str.8 = [43 x i8] c"fseek(%li,%i) failed (wanted 0, got %li): \00"
@str = [9 x i8] c"Success!\00"
define i32 @main() {
%1 = alloca [2000 x i8]
%2 = load i32, i32* @SEEK_SET
%3 = getelementptr inbounds [2000 x i8], [2000 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6, i32 384)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %78
11: ; preds = %0
%12 = tail call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32* @fdopen(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %78
17: ; preds = %11
%18 = call i32 @memset(i8* %3, i32 171, i32 2000)
%19 = call i32 @write(i32 %7, i8* %3, i32 2000)
%20 = icmp eq i32 %19, 2000
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, i64, i32, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i64 2000, i32 %19)
%24 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
br label %78
25: ; preds = %17
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseeko(i32* %13, i32 1024, i32 %26)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* @SEEK_CUR
%32 = call i32 @fseeko(i32* %13, i32 -16, i32 %31)
%33 = icmp eq i32 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i32 @ftell(i32* %13)
%37 = icmp eq i32 %36, 1008
br i1 %37, label %38, label %41
38: ; preds = %25
%39 = call i32 @lseek(i32 %7, i32 0, i32 %2)
%40 = icmp eq i32 %39, 0
br i1 %40, label %68, label %61
41: ; preds = %25
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, i64, i32, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i64 1008, i32 %36)
%44 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
br label %78
45: ; preds = %68
%46 = call i32 @lseek(i32 %7, i32 1, i32 %2)
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %61
48: ; preds = %45
%49 = call i32 @fseek(i32* %13, i32 1, i32 %2)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %71
51: ; preds = %48
%52 = call i32 @lseek(i32 %7, i32 255, i32 %2)
%53 = icmp eq i32 %52, 255
br i1 %53, label %54, label %61
54: ; preds = %51
%55 = call i32 @fseek(i32* %13, i32 255, i32 %2)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %71
57: ; preds = %54
%58 = call i32 @fclose(i32* %13)
%59 = call i32 @close(i32 %7)
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %78
61: ; preds = %51, %45, %38
%62 = phi i64 [ 0, %38 ], [ 1, %45 ], [ 255, %51 ]
%63 = phi i32 [ %39, %38 ], [ %46, %45 ], [ %52, %51 ]
%64 = load i32, i32* @stderr
%65 = sext i32 %63 to i64
%66 = call i32 (i32, i8*, i64, i32, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i64 %62, i32 %2, i64 %62, i64 %65)
%67 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
br label %78
68: ; preds = %38
%69 = call i32 @fseek(i32* %13, i32 0, i32 %2)
%70 = icmp eq i32 %69, 0
br i1 %70, label %45, label %71
71: ; preds = %54, %48, %68
%72 = phi i32 [ %69, %68 ], [ %49, %48 ], [ %55, %54 ]
%73 = phi i64 [ 0, %68 ], [ 1, %48 ], [ 255, %54 ]
%74 = load i32, i32* @stderr
%75 = sext i32 %72 to i64
%76 = call i32 (i32, i8*, i64, i32, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i64 %73, i32 %2, i64 %75)
%77 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
br label %78
78: ; preds = %57, %71, %61, %41, %21, %15, %9
%79 = phi i32 [ 1, %9 ], [ 1, %15 ], [ 1, %21 ], [ 1, %41 ], [ 1, %61 ], [ 1, %71 ], [ 0, %57 ]
ret i32 %79
}