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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fwrite(char const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
int main(void) {
  FILE *f;
  const char fname[] = "sk1test.dat";
  const char tsttxt1[] = "This is the first and only line of this file.\n";
  const char tsttxt2[] = "Now there is a second line.\n";
  char buf[sizeof(tsttxt1) + sizeof(tsttxt2) - 1] = "";
  f = fopen(fname, "w+");
  if (f == NULL || fwrite(tsttxt1, 1, strlen(tsttxt1), f) != strlen(tsttxt1) ||
      fclose(f) != 0) {
    printf("fail\n");
    exit(1);
  }
  f = fopen(fname, "a+");
  if (f == NULL || fwrite(tsttxt2, 1, strlen(tsttxt2), f) != strlen(tsttxt2) ||
      fclose(f) != 0) {
    printf("fail\n");
    exit(1);
  }
  f = fopen(fname, "r");
  if (f == NULL || fread(buf, 1, sizeof(buf), f) != sizeof(buf) - 1 ||
      strncmp(buf, tsttxt1, strlen(tsttxt1)) != 0 ||
      strncmp(buf + strlen(tsttxt1), tsttxt2, strlen(tsttxt2)) != 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    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe47(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xe45(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x2f,%edx
call   1090 <memcpy@plt>
mov    0xe6e(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0xe6b(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0xe68(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe66(%rip),%eax
mov    %eax,-0x58(%rbp)
mov    0xe61(%rip),%al
mov    %al,-0x54(%rbp)
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x4b,%edx
call   1080 <memset@plt>
lea    -0x1c(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12a3 <main+0x103>
lea    -0x50(%rbp),%rax
mov    %rax,-0xd0(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xd0(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    %rax,-0xc8(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xc8(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jne    12a3 <main+0x103>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     12b9 <main+0x119>
lea    0xd65(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x1c(%rbp),%rdi
lea    0xd51(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     133b <main+0x19b>
lea    -0x70(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    %rax,-0xd8(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xd8(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jne    133b <main+0x19b>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     1351 <main+0x1b1>
lea    0xccd(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x1c(%rbp),%rdi
lea    0xcbc(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     144a <main+0x2aa>
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4b,%edx
call   1040 <fread@plt>
cltq
cmp    $0x4a,%rax
jne    144a <main+0x2aa>
lea    -0xc0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xf0(%rbp),%rdi
mov    -0xe8(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    144a <main+0x2aa>
lea    -0xc0(%rbp),%rax
mov    %rax,-0x108(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x100(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0xf8(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x100(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    144a <main+0x2aa>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     1460 <main+0x2c0>
lea    0xbbe(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xbb3(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10b0 <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)
movups 0xe96(%rip),%xmm0
movups %xmm0,0x4f(%rsp)
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe5f(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movups 0xe90(%rip),%xmm0
movups %xmm0,0x1d(%rsp)
movaps 0xe77(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x9b(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
lea    0xe02(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1370 <main+0x1f0>
mov    %rax,%rbx
lea    0x30(%rsp),%r14
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <strlen@plt>
cltq
cmp    %rax,%r15
jne    1370 <main+0x1f0>
mov    %rbx,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
jne    1370 <main+0x1f0>
lea    0xda4(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1370 <main+0x1f0>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <strlen@plt>
cltq
cmp    %rax,%r15
jne    1370 <main+0x1f0>
mov    %rbx,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
jne    1370 <main+0x1f0>
lea    0xd46(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1370 <main+0x1f0>
mov    %rax,%rbx
lea    0x60(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4b,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
cmp    $0x4a,%eax
jne    1370 <main+0x1f0>
lea    0x30(%rsp),%r14
mov    %r14,%rdi
call   1070 <strlen@plt>
lea    0x60(%rsp),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1370 <main+0x1f0>
lea    0x30(%rsp),%rdi
call   1070 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%r14
add    $0x60,%r14
lea    0x10(%rsp),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1370 <main+0x1f0>
mov    %rbx,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
jne    1370 <main+0x1f0>
lea    0xcb0(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xca2(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.fname = [12 x i8] c"sk1test.dat\00"
@__const.main.tsttxt1 = [47 x i8] c"This is the first and only line of this file.\0A\00"
@__const.main.tsttxt2 = [29 x i8] c"Now there is a second line.\0A\00"
@.str = [3 x i8] c"w+\00"
@.str.1 = [6 x i8] c"fail\0A\00"
@.str.2 = [3 x i8] c"a+\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [6 x i8] c"pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [12 x i8]
%4 = alloca [47 x i8]
%5 = alloca [29 x i8]
%6 = alloca [75 x i8]
store i32 0, i32* %1
%7 = bitcast [12 x i8]* %3 to i8*
%8 = bitcast [47 x i8]* %4 to i8*
%9 = bitcast [29 x i8]* %5 to i8*
%10 = bitcast [75 x i8]* %6 to i8*
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %2
%13 = load i32*, i32** %2
%14 = icmp eq i32* %13, null
br i1 %14, label %29, label %15
15: ; preds = %0
%16 = getelementptr inbounds [47 x i8], [47 x i8]* %4, i64 0, i64 0
%17 = getelementptr inbounds [47 x i8], [47 x i8]* %4, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = load i32*, i32** %2
%20 = call i64 @fwrite(i8* %16, i32 1, i32 %18, i32* %19)
%21 = getelementptr inbounds [47 x i8], [47 x i8]* %4, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = icmp ne i64 %20, %23
br i1 %24, label %29, label %25
25: ; preds = %15
%26 = load i32*, i32** %2
%27 = call i64 @fclose(i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25, %15, %0
%30 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25
%33 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %2
%35 = load i32*, i32** %2
%36 = icmp eq i32* %35, null
br i1 %36, label %51, label %37
37: ; preds = %32
%38 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%39 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = load i32*, i32** %2
%42 = call i64 @fwrite(i8* %38, i32 1, i32 %40, i32* %41)
%43 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = sext i32 %44 to i64
%46 = icmp ne i64 %42, %45
br i1 %46, label %51, label %47
47: ; preds = %37
%48 = load i32*, i32** %2
%49 = call i64 @fclose(i32* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47, %37, %32
%52 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %47
%55 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%56 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %56, i32** %2
%57 = load i32*, i32** %2
%58 = icmp eq i32* %57, null
br i1 %58, label %87, label %59
59: ; preds = %54
%60 = getelementptr inbounds [75 x i8], [75 x i8]* %6, i64 0, i64 0
%61 = load i32*, i32** %2
%62 = call i32 @fread(i8* %60, i32 1, i32 75, i32* %61)
%63 = sext i32 %62 to i64
%64 = icmp ne i64 %63, 74
br i1 %64, label %87, label %65
65: ; preds = %59
%66 = getelementptr inbounds [75 x i8], [75 x i8]* %6, i64 0, i64 0
%67 = getelementptr inbounds [47 x i8], [47 x i8]* %4, i64 0, i64 0
%68 = getelementptr inbounds [47 x i8], [47 x i8]* %4, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
%70 = call i64 @strncmp(i8* %66, i8* %67, i32 %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %87, label %72
72: ; preds = %65
%73 = getelementptr inbounds [75 x i8], [75 x i8]* %6, i64 0, i64 0
%74 = getelementptr inbounds [47 x i8], [47 x i8]* %4, i64 0, i64 0
%75 = call i32 @strlen(i8* %74)
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %73, i64 %76
%78 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%79 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%80 = call i32 @strlen(i8* %79)
%81 = call i64 @strncmp(i8* %77, i8* %78, i32 %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %87, label %83
83: ; preds = %72
%84 = load i32*, i32** %2
%85 = call i64 @fclose(i32* %84)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %83, %72, %65, %59, %54
%88 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %83
%91 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%92 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.fname = [12 x i8] c"sk1test.dat\00"
@__const.main.tsttxt1 = [47 x i8] c"This is the first and only line of this file.\0A\00"
@__const.main.tsttxt2 = [29 x i8] c"Now there is a second line.\0A\00"
@.str = [3 x i8] c"w+\00"
@.str.2 = [3 x i8] c"a+\00"
@.str.3 = [2 x i8] c"r\00"
@str = [5 x i8] c"pass\00"
@str.7 = [5 x i8] c"fail\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [47 x i8]
%3 = alloca [29 x i8]
%4 = alloca [75 x i8]
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [47 x i8], [47 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [29 x i8], [29 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [75 x i8], [75 x i8]* %4, i64 0, i64 0
%9 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %20, label %11
11: ; preds = %0
%12 = call i32 @strlen(i8* %6)
%13 = call i64 @fwrite(i8* %6, i32 1, i32 %12, i32* %9)
%14 = call i32 @strlen(i8* %6)
%15 = sext i32 %14 to i64
%16 = icmp eq i64 %13, %15
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i64 @fclose(i32* %9)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17, %11, %0
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.7, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %35, label %26
26: ; preds = %23
%27 = call i32 @strlen(i8* %7)
%28 = call i64 @fwrite(i8* %7, i32 1, i32 %27, i32* %24)
%29 = call i32 @strlen(i8* %7)
%30 = sext i32 %29 to i64
%31 = icmp eq i64 %28, %30
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i64 @fclose(i32* %24)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32, %26, %23
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.7, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %32
%39 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i32* %39, null
br i1 %40, label %58, label %41
41: ; preds = %38
%42 = call i32 @fread(i8* %8, i32 1, i32 75, i32* %39)
%43 = icmp eq i32 %42, 74
br i1 %43, label %44, label %58
44: ; preds = %41
%45 = call i32 @strlen(i8* %6)
%46 = call i64 @strncmp(i8* %8, i8* %6, i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %58
48: ; preds = %44
%49 = call i32 @strlen(i8* %6)
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [75 x i8], [75 x i8]* %4, i64 0, i64 %50
%52 = call i32 @strlen(i8* %7)
%53 = call i64 @strncmp(i8* %51, i8* %7, i32 %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = call i64 @fclose(i32* %39)
%57 = icmp eq i64 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %55, %48, %44, %41, %38
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.7, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %55
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%63 = call i32 @exit(i32 0)
unreachable
}