#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 */
scalar_t__ open_test();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ stress_test1();
scalar_t__ stress_test2();
scalar_t__ test_rw_exist(char *);
scalar_t__ test_rw_long_exist(char *);
scalar_t__ test_rw_long_trunc(char *);
scalar_t__ test_rw_short_exist(char *);
scalar_t__ test_rw_short_trunc(char *);
scalar_t__ test_rw_trunc(char *);
scalar_t__ test_wr_exist(char *);
scalar_t__ test_wr_long_exist(char *);
scalar_t__ test_wr_long_trunc(char *);
scalar_t__ test_wr_short_exist(char *);
scalar_t__ test_wr_short_trunc(char *);
scalar_t__ test_wr_trunc(char *);
int test_file(void) {
  int i;
  char buffer[32];
  if (open_test() < 0) {
    printf("Open test failed\n");
    return -1;
  }
  if (stress_test1() < 0) {
    printf("stress test 1 failed\n");
    return -1;
  }
  if (stress_test2() < 0) {
    printf("stress test 2 failed\n");
    return -1;
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "file%d.txt", i);
    if (test_rw_trunc(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "file_long%d.txt", i);
    if (test_rw_long_trunc(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "file_short%d.txt", i);
    if (test_rw_short_trunc(buffer) < 0) {
      return -1;
    }
  }
  return 0;
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "file%d.txt", i);
    if (test_rw_exist(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "file_long%d.txt", i);
    if (test_rw_long_exist(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "file_short%d.txt", i);
    if (test_rw_short_exist(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "wfile%d.txt", i);
    if (test_wr_trunc(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "wfile_long%d.txt", i);
    if (test_wr_long_trunc(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "wfile_short%d.txt", i);
    if (test_wr_short_trunc(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "wfile%d.txt", i);
    if (test_wr_exist(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "wfile_long%d.txt", i);
    if (test_wr_long_exist(buffer) < 0) {
      return -1;
    }
  }
  for (i = 0; i < 26; i++) {
    sprintf(buffer, "wfile_short%d.txt", i);
    if (test_wr_short_exist(buffer) < 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1050 <open_test@plt>
cmp    $0x0,%rax
jge    11b1 <test_file+0x31>
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <test_file+0x18c>
mov    $0x0,%al
call   1080 <stress_test1@plt>
cmp    $0x0,%rax
jge    11da <test_file+0x5a>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <test_file+0x18c>
mov    $0x0,%al
call   1030 <stress_test2@plt>
cmp    $0x0,%rax
jge    1203 <test_file+0x83>
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <test_file+0x18c>
movl   $0x0,-0x8(%rbp)
cmpl   $0x1a,-0x8(%rbp)
jge    1259 <test_file+0xd9>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe1c(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1070 <test_rw_trunc@plt>
cmp    $0x0,%rax
jge    1246 <test_file+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <test_file+0x18c>
jmp    124b <test_file+0xcb>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    120a <test_file+0x8a>
movl   $0x0,-0x8(%rbp)
cmpl   $0x1a,-0x8(%rbp)
jge    12af <test_file+0x12f>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xdd1(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   10a0 <test_rw_long_trunc@plt>
cmp    $0x0,%rax
jge    129c <test_file+0x11c>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <test_file+0x18c>
jmp    12a1 <test_file+0x121>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1260 <test_file+0xe0>
movl   $0x0,-0x8(%rbp)
cmpl   $0x1a,-0x8(%rbp)
jge    1305 <test_file+0x185>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xd8b(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1060 <test_rw_short_trunc@plt>
cmp    $0x0,%rax
jge    12f2 <test_file+0x172>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <test_file+0x18c>
jmp    12f7 <test_file+0x177>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12b6 <test_file+0x136>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1050 <open_test@plt>
test   %rax,%rax
js     1266 <test_file+0xe6>
xor    %eax,%eax
call   1080 <stress_test1@plt>
test   %rax,%rax
js     126f <test_file+0xef>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <stress_test2@plt>
test   %rax,%rax
js     1278 <test_file+0xf8>
lea    0xe3e(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1090 <sprintf@plt>
mov    %r15,%rdi
call   1070 <test_rw_trunc@plt>
test   %rax,%rax
js     1284 <test_file+0x104>
add    $0x1,%ebx
cmp    $0x1a,%ebx
jne    11d0 <test_file+0x50>
xor    %ebx,%ebx
lea    0xe0c(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1090 <sprintf@plt>
mov    %r15,%rdi
call   10a0 <test_rw_long_trunc@plt>
test   %rax,%rax
js     1284 <test_file+0x104>
add    $0x1,%ebx
cmp    $0x1a,%ebx
jne    1210 <test_file+0x90>
xor    %ebx,%ebx
lea    0xde0(%rip),%r14
mov    %rsp,%r15
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1090 <sprintf@plt>
mov    %r15,%rdi
call   1060 <test_rw_short_trunc@plt>
test   %rax,%rax
js     1284 <test_file+0x104>
add    $0x1,%ebx
xor    %eax,%eax
cmp    $0x1a,%ebx
jne    1240 <test_file+0xc0>
jmp    1289 <test_file+0x109>
lea    0xde9(%rip),%rdi
jmp    127f <test_file+0xff>
lea    0xdcb(%rip),%rdi
jmp    127f <test_file+0xff>
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Open test failed\0A\00"
@.str.1 = [22 x i8] c"stress test 1 failed\0A\00"
@.str.2 = [22 x i8] c"stress test 2 failed\0A\00"
@.str.3 = [11 x i8] c"file%d.txt\00"
@.str.4 = [16 x i8] c"file_long%d.txt\00"
@.str.5 = [17 x i8] c"file_short%d.txt\00"
define i32 @test_file() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = call i64 (...) @open_test()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %67
8: ; preds = %0
%9 = call i64 (...) @stress_test1()
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %67
13: ; preds = %8
%14 = call i64 (...) @stress_test2()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %67
18: ; preds = %13
store i32 0, i32* %2
br label %19
19: ; preds = %31, %18
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 26
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%24 = load i32, i32* %2
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%27 = call i64 @test_rw_trunc(i8* %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 -1, i32* %1
br label %67
30: ; preds = %22
br label %31
31: ; preds = %30
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %19
34: ; preds = %19
store i32 0, i32* %2
br label %35
35: ; preds = %47, %34
%36 = load i32, i32* %2
%37 = icmp slt i32 %36, 26
br i1 %37, label %38, label %50
38: ; preds = %35
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%40 = load i32, i32* %2
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%43 = call i64 @test_rw_long_trunc(i8* %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %38
store i32 -1, i32* %1
br label %67
46: ; preds = %38
br label %47
47: ; preds = %46
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %35
50: ; preds = %35
store i32 0, i32* %2
br label %51
51: ; preds = %63, %50
%52 = load i32, i32* %2
%53 = icmp slt i32 %52, 26
br i1 %53, label %54, label %66
54: ; preds = %51
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%56 = load i32, i32* %2
%57 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%59 = call i64 @test_rw_short_trunc(i8* %58)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %54
store i32 -1, i32* %1
br label %67
62: ; preds = %54
br label %63
63: ; preds = %62
%64 = load i32, i32* %2
%65 = add nsw i32 %64, 1
store i32 %65, i32* %2
br label %51
66: ; preds = %51
store i32 0, i32* %1
br label %67
67: ; preds = %66, %61, %45, %29, %16, %11, %6
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
@.str.3 = [11 x i8] c"file%d.txt\00"
@.str.4 = [16 x i8] c"file_long%d.txt\00"
@.str.5 = [17 x i8] c"file_short%d.txt\00"
@str = [21 x i8] c"stress test 2 failed\00"
@str.6 = [21 x i8] c"stress test 1 failed\00"
@str.7 = [17 x i8] c"Open test failed\00"
define i32 @test_file() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = tail call i64 (...) @open_test()
%4 = icmp slt i64 %3, 0
br i1 %4, label %35, label %5
5: ; preds = %0
%6 = tail call i64 (...) @stress_test1()
%7 = icmp slt i64 %6, 0
br i1 %7, label %35, label %8
8: ; preds = %5
%9 = tail call i64 (...) @stress_test2()
%10 = icmp slt i64 %9, 0
br i1 %10, label %35, label %14
11: ; preds = %14
%12 = add nuw nsw i32 %15, 1
%13 = icmp eq i32 %12, 26
br i1 %13, label %22, label %14
14: ; preds = %8, %11
%15 = phi i32 [ %12, %11 ], [ 0, %8 ]
%16 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = call i64 @test_rw_trunc(i8* %2)
%18 = icmp slt i64 %17, 0
br i1 %18, label %38, label %11
19: ; preds = %22
%20 = add nuw nsw i32 %23, 1
%21 = icmp eq i32 %20, 26
br i1 %21, label %30, label %22
22: ; preds = %11, %19
%23 = phi i32 [ %20, %19 ], [ 0, %11 ]
%24 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = call i64 @test_rw_long_trunc(i8* %2)
%26 = icmp slt i64 %25, 0
br i1 %26, label %38, label %19
27: ; preds = %30
%28 = add nuw nsw i32 %31, 1
%29 = icmp eq i32 %28, 26
br i1 %29, label %38, label %30
30: ; preds = %19, %27
%31 = phi i32 [ %28, %27 ], [ 0, %19 ]
%32 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %31)
%33 = call i64 @test_rw_short_trunc(i8* %2)
%34 = icmp slt i64 %33, 0
br i1 %34, label %38, label %27
35: ; preds = %8, %5, %0
%36 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0), %0 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0), %5 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0), %8 ]
%37 = tail call i32 @puts(i8* dereferenceable(1) %36)
br label %38
38: ; preds = %14, %22, %27, %30, %35
%39 = phi i32 [ -1, %35 ], [ 0, %27 ], [ -1, %30 ], [ -1, %22 ], [ -1, %14 ]
ret i32 %39
}