#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_SET;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd, n, bad, i;
  const char *result = "  02 05        15  19    25   ";
  char buf[10000];
  fd = creat("test-seek.out", 0777);
  write(fd, "                              ", 30);
  lseek(fd, 5, SEEK_SET);
  write(fd, "05", 2);
  lseek(fd, 15, SEEK_SET);
  write(fd, "15", 2);
  lseek(fd, 25, SEEK_SET);
  write(fd, "25", 2);
  lseek(fd, 2, SEEK_SET);
  write(fd, "02", 2);
  lseek(fd, 19, SEEK_SET);
  write(fd, "19", 2);
  close(fd);
  fd = open("test-seek.out", O_RDONLY);
  n = read(fd, buf, sizeof buf);
  buf[n] == 0;
  bad = 0;
  for (i = 0; i < n; i++) {
    if (result[i] != buf[i]) {
      printf("%2d: %d %d\n", i, result[i], buf[i]);
      bad = 0;
    }
  }
  if (bad > 0) {
    printf("%d bad characters\n", bad);
    exit(1);
  } else {
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe74(%rip),%rdi
mov    $0x1ff,%esi
call   1090 <creat@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    0xe6b(%rip),%rsi
mov    $0x1e,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    0xe60(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
mov    $0xf,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    0xe39(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
mov    $0x19,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    0xe12(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    0xdeb(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2d5a(%rip),%rax
mov    (%rax),%edx
mov    $0x13,%esi
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    0xdc4(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
lea    0xd69(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x2740(%rbp),%rsi
mov    $0x2710,%edx
call   1070 <read@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1352 <main+0x1d2>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movslq -0x20(%rbp),%rcx
movsbl -0x2740(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
je     133f <main+0x1bf>
mov    -0x20(%rbp),%esi
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
movslq -0x20(%rbp),%rax
movsbl -0x2740(%rbp,%rax,1),%ecx
ff
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1344 <main+0x1c4>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12e3 <main+0x163>
cmpl   $0x0,-0x1c(%rbp)
jle    1377 <main+0x1f7>
mov    -0x1c(%rbp),%esi
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2718,%rsp
lea    0xe8b(%rip),%r14
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1090 <creat@plt>
mov    %eax,%ebp
lea    0xe83(%rip),%rsi
mov    %eax,%edi
mov    $0x1e,%edx
call   1030 <write@plt>
mov    0x2e1b(%rip),%rbx
mov    (%rbx),%edx
mov    %ebp,%edi
mov    $0x5,%esi
call   1050 <lseek@plt>
lea    0xe7a(%rip),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    (%rbx),%edx
mov    %ebp,%edi
mov    $0xf,%esi
call   1050 <lseek@plt>
lea    0xe5c(%rip),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    (%rbx),%edx
mov    %ebp,%edi
mov    $0x19,%esi
call   1050 <lseek@plt>
lea    0xe3e(%rip),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    (%rbx),%edx
mov    %ebp,%edi
mov    $0x2,%esi
call   1050 <lseek@plt>
lea    0xe20(%rip),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    (%rbx),%edx
mov    %ebp,%edi
mov    $0x13,%esi
call   1050 <lseek@plt>
lea    0xe02(%rip),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <open@plt>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x2710,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    12d5 <main+0x155>
mov    %eax,%ebx
lea    0xd6a(%rip),%r15
lea    0xdbe(%rip),%r14
xor    %ebp,%ebp
jmp    12b9 <main+0x139>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     12d5 <main+0x155>
movsbl 0x0(%rbp,%r15,1),%edx
movsbl (%rsp,%rbp,1),%ecx
cmp    %cl,%dl
je     12b0 <main+0x130>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12b0 <main+0x130>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c" 02 05 15 19 25 \00"
@.str.1 = [14 x i8] c"test-seek.out\00"
@.str.2 = [31 x i8] c" \00"
@SEEK_SET = global i32 0
@.str.3 = [3 x i8] c"05\00"
@.str.4 = [3 x i8] c"15\00"
@.str.5 = [3 x i8] c"25\00"
@.str.6 = [3 x i8] c"02\00"
@.str.7 = [3 x i8] c"19\00"
@O_RDONLY = global i32 0
@.str.8 = [12 x i8] c"%2d: %d %d\0A\00"
@.str.9 = [19 x i8] c"%d bad characters\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [10000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8** %10
%12 = call i32 @creat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 511)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 30)
%15 = load i32, i32* %6
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @lseek(i32 %15, i32 5, i32 %16)
%18 = load i32, i32* %6
%19 = call i32 @write(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%20 = load i32, i32* %6
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %20, i32 15, i32 %21)
%23 = load i32, i32* %6
%24 = call i32 @write(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%25 = load i32, i32* %6
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @lseek(i32 %25, i32 25, i32 %26)
%28 = load i32, i32* %6
%29 = call i32 @write(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%30 = load i32, i32* %6
%31 = load i32, i32* @SEEK_SET
%32 = call i32 @lseek(i32 %30, i32 2, i32 %31)
%33 = load i32, i32* %6
%34 = call i32 @write(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%35 = load i32, i32* %6
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @lseek(i32 %35, i32 19, i32 %36)
%38 = load i32, i32* %6
%39 = call i32 @write(i32 %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2)
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* @O_RDONLY
%43 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %42)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 10000)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 0
%53 = zext i1 %52 to i32
store i32 0, i32* %8
store i32 0, i32* %9
br label %54
54: ; preds = %86, %2
%55 = load i32, i32* %9
%56 = load i32, i32* %7
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %89
58: ; preds = %54
%59 = load i8*, i8** %10
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 %66
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %64, %69
br i1 %70, label %71, label %85
71: ; preds = %58
%72 = load i32, i32* %9
%73 = load i8*, i8** %10
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = load i32, i32* %9
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 %80
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %72, i32 %78, i32 %83)
store i32 0, i32* %8
br label %85
85: ; preds = %71, %58
br label %86
86: ; preds = %85
%87 = load i32, i32* %9
%88 = add nsw i32 %87, 1
store i32 %88, i32* %9
br label %54
89: ; preds = %54
%90 = load i32, i32* %8
%91 = icmp sgt i32 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %89
%93 = load i32, i32* %8
%94 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %93)
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %89
%97 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [31 x i8] c" 02 05 15 19 25 \00"
@.str.1 = [14 x i8] c"test-seek.out\00"
@.str.2 = [31 x i8] c" \00"
@SEEK_SET = global i32 0
@.str.3 = [3 x i8] c"05\00"
@.str.4 = [3 x i8] c"15\00"
@.str.5 = [3 x i8] c"25\00"
@.str.6 = [3 x i8] c"02\00"
@.str.7 = [3 x i8] c"19\00"
@O_RDONLY = global i32 0
@.str.8 = [12 x i8] c"%2d: %d %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10000 x i8]
%4 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @creat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 511)
%6 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 30)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @lseek(i32 %5, i32 5, i32 %7)
%9 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @lseek(i32 %5, i32 15, i32 %10)
%12 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @lseek(i32 %5, i32 25, i32 %13)
%15 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @lseek(i32 %5, i32 2, i32 %16)
%18 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @lseek(i32 %5, i32 19, i32 %19)
%21 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2)
%22 = tail call i32 @close(i32 %5)
%23 = load i32, i32* @O_RDONLY
%24 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i32 @read(i32 %24, i8* %4, i32 10000)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %44
27: ; preds = %2
%28 = zext i32 %25 to i64
br label %29
29: ; preds = %27, %41
%30 = phi i64 [ 0, %27 ], [ %42, %41 ]
%31 = getelementptr inbounds [31 x i8], [31 x i8]* @.str, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 %30
%34 = load i8, i8* %33
%35 = icmp eq i8 %32, %34
br i1 %35, label %41, label %36
36: ; preds = %29
%37 = sext i8 %34 to i32
%38 = sext i8 %32 to i32
%39 = trunc i64 %30 to i32
%40 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %39, i32 %38, i32 %37)
br label %41
41: ; preds = %29, %36
%42 = add nuw nsw i64 %30, 1
%43 = icmp eq i64 %42, %28
br i1 %43, label %44, label %29
44: ; preds = %41, %2
%45 = tail call i32 @exit(i32 0)
unreachable
}