#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fwrite(char const *, int, scalar_t__, int /*<<< orphan*/ *);
int lseek(int, long, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ read(int, char *, scalar_t__);
scalar_t__ strcmp(char *, char const *);
scalar_t__ strlen(char const *);
int main(void) {
  FILE *f;
  const char fname[] = "sk1test.dat";
  const char tsttxt[] =
      "A random line of text, used to test correct read, write and seek.\n";
  char buf[sizeof tsttxt] = "";
  const char correct[] = "correct";
  char buf2[sizeof correct] = {0};
  int fd;
  f = fopen(fname, "wb");
  if (f == NULL || fwrite(tsttxt, 1, strlen(tsttxt), f) != strlen(tsttxt) ||
      fclose(f) != 0) {
    printf("fail\n");
    exit(1);
  }
  fd = open(fname, O_RDONLY);
  if (fd < 0 || read(fd, buf, strlen(tsttxt)) != strlen(tsttxt) ||
      strcmp(buf, tsttxt) != 0 || lseek(fd, -30L, SEEK_CUR) != 36 ||
      read(fd, buf2, strlen(correct)) != strlen(correct) ||
      strcmp(buf2, correct) != 0) {
    printf("fail\n");
    exit(1);
  }
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe27(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xe25(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x43,%edx
call   10a0 <memcpy@plt>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x43,%edx
call   1070 <memset@plt>
mov    0xdf7(%rip),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
lea    -0x1c(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12b0 <main+0xf0>
lea    -0x60(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xd8(%rbp),%rdi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    %rax,-0xd0(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xd0(%rbp),%rax
cmp    %rcx,%rax
jne    12b0 <main+0xf0>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     12c6 <main+0x106>
lea    0xd60(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x1c(%rbp),%rdi
mov    0x2d0f(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0xc4(%rbp)
cmpl   $0x0,-0xc4(%rbp)
jl     1402 <main+0x242>
mov    -0xc4(%rbp),%eax
mov    %eax,-0xec(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xec(%rbp),%edi
mov    -0xe8(%rbp),%rsi
mov    %rax,%rdx
call   1080 <read@plt>
mov    %rax,-0xe0(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xe0(%rbp),%rax
cmp    %rcx,%rax
jne    1402 <main+0x242>
lea    -0xb0(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1402 <main+0x242>
mov    -0xc4(%rbp),%edi
mov    0x2c7b(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffffffffffe2,%rsi
call   1060 <lseek@plt>
cmp    $0x24,%eax
jne    1402 <main+0x242>
mov    -0xc4(%rbp),%eax
mov    %eax,-0x104(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0x100(%rbp)
lea    -0xb8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x104(%rbp),%edi
mov    -0x100(%rbp),%rsi
mov    %rax,%rdx
call   1080 <read@plt>
mov    %rax,-0xf8(%rbp)
lea    -0xb8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xf8(%rbp),%rax
cmp    %rcx,%rax
jne    1402 <main+0x242>
lea    -0xc0(%rbp),%rdi
lea    -0xb8(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1418 <main+0x258>
lea    0xc0e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xbfe(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xb8,%rsp
movabs $0x2e74736574316b73,%rax
73 74 2e
mov    %rax,0x10(%rsp)
movl   $0x746164,0x18(%rsp)
movaps 0xe85(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe69(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe4d(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe31(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0xa2e6b,0x5f(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movl   $0x0,0xaf(%rsp)
movabs $0x74636572726f63,%rax
mov    %rax,0x8(%rsp)
movq   $0x0,(%rsp)
lea    0xdc7(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1368 <main+0x1c8>
mov    %rax,%rbx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %rbx,%rcx
call   10c0 <fwrite@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %rax,%r15
jne    1368 <main+0x1c8>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    1368 <main+0x1c8>
mov    0x2d39(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1368 <main+0x1c8>
mov    %eax,%ebp
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x70(%rsp),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1070 <read@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %rax,%rbx
jne    1368 <main+0x1c8>
lea    0x70(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1368 <main+0x1c8>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0xffffffffffffffe2,%rsi
call   1060 <lseek@plt>
cmp    $0x24,%eax
jne    1368 <main+0x1c8>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1070 <read@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    %rax,%rbp
jne    1368 <main+0x1c8>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1368 <main+0x1c8>
lea    0xcb3(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xca5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@__const.main.fname = [12 x i8] c"sk1test.dat\00"
@__const.main.tsttxt = [67 x i8] c"A random line of text, used to test correct read, write and seek.\0A\00"
@__const.main.correct = [8 x i8] c"correct\00"
@.str = [3 x i8] c"wb\00"
@.str.1 = [6 x i8] c"fail\0A\00"
@O_RDONLY = global i32 0
@SEEK_CUR = global i32 0
@.str.2 = [6 x i8] c"pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [12 x i8]
%4 = alloca [67 x i8]
%5 = alloca [67 x i8]
%6 = alloca [8 x i8]
%7 = alloca [8 x i8]
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [12 x i8]* %3 to i8*
%10 = bitcast [67 x i8]* %4 to i8*
%11 = bitcast [67 x i8]* %5 to i8*
%12 = bitcast [8 x i8]* %6 to i8*
%13 = bitcast [8 x i8]* %7 to i8*
%14 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %2
%16 = load i32*, i32** %2
%17 = icmp eq i32* %16, null
br i1 %17, label %31, label %18
18: ; preds = %0
%19 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
%22 = load i32*, i32** %2
%23 = call i64 @fwrite(i8* %19, i32 1, i64 %21, i32* %22)
%24 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%25 = call i64 @strlen(i8* %24)
%26 = icmp ne i64 %23, %25
br i1 %26, label %31, label %27
27: ; preds = %18
%28 = load i32*, i32** %2
%29 = call i64 @fclose(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27, %18, %0
%32 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp slt i32 %38, 0
br i1 %39, label %73, label %40
40: ; preds = %34
%41 = load i32, i32* %8
%42 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 0
%43 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%44 = call i64 @strlen(i8* %43)
%45 = call i64 @read(i32 %41, i8* %42, i64 %44)
%46 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%47 = call i64 @strlen(i8* %46)
%48 = icmp ne i64 %45, %47
br i1 %48, label %73, label %49
49: ; preds = %40
%50 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 0
%51 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%52 = call i64 @strcmp(i8* %50, i8* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %73, label %54
54: ; preds = %49
%55 = load i32, i32* %8
%56 = load i32, i32* @SEEK_CUR
%57 = call i32 @lseek(i32 %55, i64 -30, i32 %56)
%58 = icmp ne i32 %57, 36
br i1 %58, label %73, label %59
59: ; preds = %54
%60 = load i32, i32* %8
%61 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%62 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%63 = call i64 @strlen(i8* %62)
%64 = call i64 @read(i32 %60, i8* %61, i64 %63)
%65 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%66 = call i64 @strlen(i8* %65)
%67 = icmp ne i64 %64, %66
br i1 %67, label %73, label %68
68: ; preds = %59
%69 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%70 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%71 = call i64 @strcmp(i8* %69, i8* %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %68, %59, %54, %49, %40, %34
%74 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %68
%77 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%78 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.fname = [12 x i8] c"sk1test.dat\00"
@__const.main.tsttxt = [67 x i8] c"A random line of text, used to test correct read, write and seek.\0A\00"
@.str = [3 x i8] c"wb\00"
@O_RDONLY = global i32 0
@SEEK_CUR = global i32 0
@str = [5 x i8] c"pass\00"
@str.4 = [5 x i8] c"fail\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [67 x i8]
%3 = alloca [67 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [67 x i8], [67 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [67 x i8], [67 x i8]* %3, i64 0, i64 0
%9 = bitcast i64* %4 to i8*
store i64 32760384661385059, i64* %4
%10 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%11 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %21, label %13
13: ; preds = %0
%14 = call i64 @strlen(i8* %7)
%15 = call i64 @fwrite(i8* %7, i32 1, i64 %14, i32* %11)
%16 = call i64 @strlen(i8* %7)
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i64 @fclose(i32* %11)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18, %13, %0
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %18
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %6, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %48, label %28
28: ; preds = %24
%29 = call i64 @strlen(i8* %7)
%30 = call i64 @read(i32 %26, i8* %8, i64 %29)
%31 = call i64 @strlen(i8* %7)
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %48
33: ; preds = %28
%34 = call i64 @strcmp(i8* %8, i8* %7)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %48
36: ; preds = %33
%37 = load i32, i32* @SEEK_CUR
%38 = call i32 @lseek(i32 %26, i64 -30, i32 %37)
%39 = icmp eq i32 %38, 36
br i1 %39, label %40, label %48
40: ; preds = %36
%41 = call i64 @strlen(i8* %9)
%42 = call i64 @read(i32 %26, i8* %10, i64 %41)
%43 = call i64 @strlen(i8* %9)
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = call i64 @strcmp(i8* %10, i8* %9)
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %45, %40, %36, %33, %28, %24
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %45
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
}