#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*/ SEEK_END;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fread(char *, int, scalar_t__, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
scalar_t__ ftell(int /*<<< orphan*/ *);
scalar_t__ fwrite(char const *, int, scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
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] = "";
  f = fopen(fname, "w");
  if (f == NULL || fwrite(tsttxt, 1, strlen(tsttxt), f) != strlen(tsttxt) ||
      fclose(f) != 0) {
    printf("fail\n");
    exit(1);
  }
  f = fopen(fname, "rb");
  if (f == NULL || fseek(f, 0L, SEEK_END) != 0 || ftell(f) != strlen(tsttxt)) {
    printf("fail\n");
    exit(1);
  }
  rewind(f);
  if (fread(buf, 1, strlen(tsttxt), f) != strlen(tsttxt) ||
      strcmp(buf, tsttxt) != 0 || fclose(f) != 0) {
    printf("fail\n");
    exit(1);
  }
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe17(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xe15(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe1f(%rip),%rsi
mov    $0x43,%edx
call   10b0 <memcpy@plt>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x43,%edx
call   1080 <memset@plt>
lea    -0x1c(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     129f <main+0xcf>
lea    -0x60(%rbp),%rax
mov    %rax,-0xc0(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xc0(%rbp),%rdi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
mov    %rax,-0xb8(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0xb8(%rbp),%rax
cmp    %rcx,%rax
jne    129f <main+0xcf>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     12b5 <main+0xe5>
lea    0xd68(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x1c(%rbp),%rdi
lea    0xd54(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1320 <main+0x150>
mov    -0x10(%rbp),%rdi
mov    0x2d09(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
cmp    $0x0,%rax
jne    1320 <main+0x150>
mov    -0x10(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0xc8(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0xc8(%rbp),%rax
cmp    %rcx,%rax
je     1336 <main+0x166>
lea    0xce7(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1070 <rewind@plt>
lea    -0xb0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xd8(%rbp),%rdi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0xd0(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0xd0(%rbp),%rax
cmp    %rcx,%rax
jne    13be <main+0x1ee>
lea    -0xb0(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    13be <main+0x1ee>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     13d4 <main+0x204>
lea    0xc49(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xc3c(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xb0,%rsp
movabs $0x2e74736574316b73,%rax
73 74 2e
mov    %rax,(%rsp)
movl   $0x746164,0x8(%rsp)
movaps 0xe77(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe5b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe3f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe23(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0xa2e6b,0x4f(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movl   $0x0,0x9f(%rsp)
lea    0xdd3(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1342 <main+0x192>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %rbx,%rcx
call   10d0 <fwrite@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1060 <strlen@plt>
cmp    %rax,%r15
jne    1342 <main+0x192>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    1342 <main+0x192>
lea    0xd75(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1342 <main+0x192>
mov    %rax,%rbx
mov    0x2d34(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
test   %rax,%rax
jne    1342 <main+0x192>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
call   1060 <strlen@plt>
cmp    %rax,%r14
jne    1342 <main+0x192>
mov    %rbx,%rdi
call   1070 <rewind@plt>
lea    0x60(%rsp),%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
call   1060 <strlen@plt>
cmp    %rax,%r14
jne    1342 <main+0x192>
lea    0x60(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1342 <main+0x192>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    1342 <main+0x192>
lea    0xcdb(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xccd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <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"
@.str = [2 x i8] c"w\00"
@.str.1 = [6 x i8] c"fail\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.3 = [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]
store i32 0, i32* %1
%6 = bitcast [12 x i8]* %3 to i8*
%7 = bitcast [67 x i8]* %4 to i8*
%8 = bitcast [67 x i8]* %5 to i8*
%9 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %26, label %13
13: ; preds = %0
%14 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%15 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%16 = call i64 @strlen(i8* %15)
%17 = load i32*, i32** %2
%18 = call i64 @fwrite(i8* %14, i32 1, i64 %16, i32* %17)
%19 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%20 = call i64 @strlen(i8* %19)
%21 = icmp ne i64 %18, %20
br i1 %21, label %26, label %22
22: ; preds = %13
%23 = load i32*, i32** %2
%24 = call i64 @fclose(i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22, %13, %0
%27 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %22
%30 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %2
%32 = load i32*, i32** %2
%33 = icmp eq i32* %32, null
br i1 %33, label %45, label %34
34: ; preds = %29
%35 = load i32*, i32** %2
%36 = load i32, i32* @SEEK_END
%37 = call i64 @fseek(i32* %35, i64 0, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %34
%40 = load i32*, i32** %2
%41 = call i64 @ftell(i32* %40)
%42 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%43 = call i64 @strlen(i8* %42)
%44 = icmp ne i64 %41, %43
br i1 %44, label %45, label %48
45: ; preds = %39, %34, %29
%46 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %39
%49 = load i32*, i32** %2
%50 = call i32 @rewind(i32* %49)
%51 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 0
%52 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%53 = call i64 @strlen(i8* %52)
%54 = load i32*, i32** %2
%55 = call i64 @fread(i8* %51, i32 1, i64 %53, i32* %54)
%56 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%57 = call i64 @strlen(i8* %56)
%58 = icmp ne i64 %55, %57
br i1 %58, label %68, label %59
59: ; preds = %48
%60 = getelementptr inbounds [67 x i8], [67 x i8]* %5, i64 0, i64 0
%61 = getelementptr inbounds [67 x i8], [67 x i8]* %4, i64 0, i64 0
%62 = call i64 @strcmp(i8* %60, i8* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %68, label %64
64: ; preds = %59
%65 = load i32*, i32** %2
%66 = call i64 @fclose(i32* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %64, %59, %48
%69 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %64
%72 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%73 = 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 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@str = [5 x i8] c"pass\00"
@str.6 = [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 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [67 x i8], [67 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [67 x i8], [67 x i8]* %3, i64 0, i64 0
%7 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %17, label %9
9: ; preds = %0
%10 = call i64 @strlen(i8* %5)
%11 = call i64 @fwrite(i8* %5, i32 1, i64 %10, i32* %7)
%12 = call i64 @strlen(i8* %5)
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i64 @fclose(i32* %7)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14, %9, %0
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.6, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %14
%21 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %31, label %23
23: ; preds = %20
%24 = load i32, i32* @SEEK_END
%25 = tail call i64 @fseek(i32* %21, i64 0, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = tail call i64 @ftell(i32* %21)
%29 = call i64 @strlen(i8* %5)
%30 = icmp eq i64 %28, %29
br i1 %30, label %34, label %31
31: ; preds = %27, %23, %20
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.6, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = tail call i32 @rewind(i32* %21)
%36 = call i64 @fread(i8* %6, i32 1, i64 %28, i32* %21)
%37 = call i64 @strlen(i8* %5)
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %45
39: ; preds = %34
%40 = call i64 @strcmp(i8* %6, i8* %5)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = call i64 @fclose(i32* %21)
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %42, %39, %34
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.6, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %42
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
}