#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_CUR;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ doaw(int /*<<< orphan*/ *, int const);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int const, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ memcmp(unsigned char *, char *, int);
int const read32(unsigned char *);
int /*<<< orphan*/ stderr;
int doWSYS(FILE *infile, const int offset) {
  unsigned char buf[4];
  int WINFoffset;
  int aw_count;
  int old_offset;
  int i;
  old_offset = ftell(infile);
  if (old_offset < 0)
    return 1;
  if (fseek(infile, offset, SEEK_SET) < 0)
    return 1;
  if (fread(buf, 1, 4, infile) != 4)
    return 1;
  if (memcmp(buf, "WSYS", 4)) {
    fprintf(stderr, "WSYS file expected at 0x%x\n", offset);
    return 1;
  }
  if (fseek(infile, 12, SEEK_CUR) < 0)
    return 1;
  if (fread(buf, 1, 4, infile) != 4)
    return 1;
  WINFoffset = read32(buf) + offset;
  if (fseek(infile, WINFoffset, SEEK_SET) < 0)
    return 1;
  if (fread(buf, 1, 4, infile) != 4)
    return 1;
  if (memcmp(buf, "WINF", 4)) {
    fprintf(stderr, "expected WINF tag at 0x%x\n", WINFoffset);
    return 1;
  }
  if (fread(buf, 1, 4, infile) != 4)
    return 1;
  aw_count = read32(buf);
  for (i = 0; i < aw_count; i++) {
    if (doaw(infile, offset)) {
      fprintf(stderr, "error parsing .aw file\n");
      return 1;
    }
  }
  if (fseek(infile, old_offset, SEEK_SET) < 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<doWSYS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a1 <doWSYS+0x31>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
cmp    $0x0,%rax
jge    11cc <doWSYS+0x5c>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x4,%eax
je     11f8 <doWSYS+0x88>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
lea    -0x18(%rbp),%rdi
lea    0xdfd(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     123d <doWSYS+0xcd>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
mov    -0x10(%rbp),%rdi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
jge    126a <doWSYS+0xfa>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x4,%eax
je     1296 <doWSYS+0x126>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
lea    -0x18(%rbp),%rdi
call   1090 <read32@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2d1d(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
cmp    $0x0,%rax
jge    12d0 <doWSYS+0x160>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x4,%eax
je     12fc <doWSYS+0x18c>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
lea    -0x18(%rbp),%rdi
lea    0xd1a(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1341 <doWSYS+0x1d1>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xcf8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x4,%eax
je     136d <doWSYS+0x1fd>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
lea    -0x18(%rbp),%rdi
call   1090 <read32@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    13d8 <doWSYS+0x268>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <doaw@plt>
cmp    $0x0,%rax
je     13c5 <doWSYS+0x255>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
lea    0xc8f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
jmp    13ca <doWSYS+0x25a>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1380 <doWSYS+0x210>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x2bea(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
cmp    $0x0,%rax
jge    1403 <doWSYS+0x293>
movl   $0x1,-0x4(%rbp)
jmp    140a <doWSYS+0x29a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doWSYS>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
call   1070 <ftell@plt>
mov    $0x1,%r15d
test   %eax,%eax
js     1204 <doWSYS+0x94>
mov    %eax,%ebx
mov    0x2e37(%rip),%r13
mov    0x0(%r13),%edx
mov    %rbp,%rdi
mov    %r14d,%esi
call   1080 <fseek@plt>
test   %rax,%rax
js     1204 <doWSYS+0x94>
lea    0x4(%rsp),%rdi
mov    $0x1,%r15d
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
cmp    $0x4,%eax
jne    1204 <doWSYS+0x94>
lea    0xe2a(%rip),%rsi
lea    0x4(%rsp),%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     1216 <doWSYS+0xa6>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dcb(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0xc,%esi
call   1080 <fseek@plt>
test   %rax,%rax
js     1204 <doWSYS+0x94>
lea    0x4(%rsp),%rdi
mov    $0x1,%r15d
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
cmp    $0x4,%eax
jne    1204 <doWSYS+0x94>
lea    0x4(%rsp),%rdi
call   1090 <read32@plt>
mov    %eax,%r12d
add    %r14d,%r12d
mov    0x0(%r13),%edx
mov    %rbp,%rdi
mov    %r12d,%esi
call   1080 <fseek@plt>
test   %rax,%rax
js     1204 <doWSYS+0x94>
lea    0x4(%rsp),%rdi
mov    $0x1,%r15d
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
cmp    $0x4,%eax
jne    1204 <doWSYS+0x94>
lea    0xd7d(%rip),%rsi
lea    0x4(%rsp),%rdi
mov    $0x4,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     12d0 <doWSYS+0x160>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
mov    %r12d,%edx
jmp    11fd <doWSYS+0x8d>
lea    0x4(%rsp),%rdi
mov    $0x1,%r15d
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
cmp    $0x4,%eax
jne    1204 <doWSYS+0x94>
lea    0x4(%rsp),%rdi
call   1090 <read32@plt>
test   %eax,%eax
jle    131d <doWSYS+0x1ad>
mov    %eax,%r12d
mov    %rbp,%rdi
mov    %r14d,%esi
call   1040 <doaw@plt>
test   %rax,%rax
jne    1337 <doWSYS+0x1c7>
add    $0xffffffff,%r12d
jne    1307 <doWSYS+0x197>
mov    0x0(%r13),%edx
mov    %rbp,%rdi
mov    %ebx,%esi
call   1080 <fseek@plt>
mov    %rax,%r15
shr    $0x3f,%r15
jmp    1204 <doWSYS+0x94>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    0xcfa(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1204 <doWSYS+0x94>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [5 x i8] c"WSYS\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"WSYS file expected at 0x%x\0A\00"
@SEEK_CUR = global i32 0
@.str.2 = [5 x i8] c"WINF\00"
@.str.3 = [27 x i8] c"expected WINF tag at 0x%x\0A\00"
@.str.4 = [24 x i8] c"error parsing .aw file\0A\00"
define i32 @doWSYS(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [4 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%11 = load i32*, i32** %4
%12 = call i32 @ftell(i32* %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 1, i32* %3
br label %107
16: ; preds = %2
%17 = load i32*, i32** %4
%18 = load i32, i32* %5
%19 = load i32, i32* @SEEK_SET
%20 = call i64 @fseek(i32* %17, i32 %18, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 1, i32* %3
br label %107
23: ; preds = %16
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%25 = load i32*, i32** %4
%26 = call i32 @fread(i8* %24, i32 1, i32 4, i32* %25)
%27 = icmp ne i32 %26, 4
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 1, i32* %3
br label %107
29: ; preds = %23
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%31 = call i64 @memcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = load i32, i32* %5
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %35)
store i32 1, i32* %3
br label %107
37: ; preds = %29
%38 = load i32*, i32** %4
%39 = load i32, i32* @SEEK_CUR
%40 = call i64 @fseek(i32* %38, i32 12, i32 %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %37
store i32 1, i32* %3
br label %107
43: ; preds = %37
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%45 = load i32*, i32** %4
%46 = call i32 @fread(i8* %44, i32 1, i32 4, i32* %45)
%47 = icmp ne i32 %46, 4
br i1 %47, label %48, label %49
48: ; preds = %43
store i32 1, i32* %3
br label %107
49: ; preds = %43
%50 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%51 = call i32 @read32(i8* %50)
%52 = load i32, i32* %5
%53 = add nsw i32 %51, %52
store i32 %53, i32* %7
%54 = load i32*, i32** %4
%55 = load i32, i32* %7
%56 = load i32, i32* @SEEK_SET
%57 = call i64 @fseek(i32* %54, i32 %55, i32 %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %49
store i32 1, i32* %3
br label %107
60: ; preds = %49
%61 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%62 = load i32*, i32** %4
%63 = call i32 @fread(i8* %61, i32 1, i32 4, i32* %62)
%64 = icmp ne i32 %63, 4
br i1 %64, label %65, label %66
65: ; preds = %60
store i32 1, i32* %3
br label %107
66: ; preds = %60
%67 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%68 = call i64 @memcmp(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %66
%71 = load i32, i32* @stderr
%72 = load i32, i32* %7
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %72)
store i32 1, i32* %3
br label %107
74: ; preds = %66
%75 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%76 = load i32*, i32** %4
%77 = call i32 @fread(i8* %75, i32 1, i32 4, i32* %76)
%78 = icmp ne i32 %77, 4
br i1 %78, label %79, label %80
79: ; preds = %74
store i32 1, i32* %3
br label %107
80: ; preds = %74
%81 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%82 = call i32 @read32(i8* %81)
store i32 %82, i32* %8
store i32 0, i32* %10
br label %83
83: ; preds = %96, %80
%84 = load i32, i32* %10
%85 = load i32, i32* %8
%86 = icmp slt i32 %84, %85
br i1 %86, label %87, label %99
87: ; preds = %83
%88 = load i32*, i32** %4
%89 = load i32, i32* %5
%90 = call i64 @doaw(i32* %88, i32 %89)
%91 = icmp ne i64 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %87
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %107
95: ; preds = %87
br label %96
96: ; preds = %95
%97 = load i32, i32* %10
%98 = add nsw i32 %97, 1
store i32 %98, i32* %10
br label %83
99: ; preds = %83
%100 = load i32*, i32** %4
%101 = load i32, i32* %9
%102 = load i32, i32* @SEEK_SET
%103 = call i64 @fseek(i32* %100, i32 %101, i32 %102)
%104 = icmp slt i64 %103, 0
br i1 %104, label %105, label %106
105: ; preds = %99
store i32 1, i32* %3
br label %107
106: ; preds = %99
store i32 0, i32* %3
br label %107
107: ; preds = %106, %105, %92, %79, %70, %65, %59, %48, %42, %33, %28, %22, %15
%108 = load i32, i32* %3
ret i32 %108
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [5 x i8] c"WSYS\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"WSYS file expected at 0x%x\0A\00"
@SEEK_CUR = global i32 0
@.str.2 = [5 x i8] c"WINF\00"
@.str.3 = [27 x i8] c"expected WINF tag at 0x%x\0A\00"
@.str.4 = [24 x i8] c"error parsing .aw file\0A\00"
define i32 @doWSYS(i32* %0, i32 %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @ftell(i32* %0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %63, label %7
7: ; preds = %2
%8 = load i32, i32* @SEEK_SET
%9 = tail call i64 @fseek(i32* %0, i32 %1, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %63, label %11
11: ; preds = %7
%12 = call i32 @fread(i8* %4, i32 1, i32 4, i32* %0)
%13 = icmp eq i32 %12, 4
br i1 %13, label %14, label %63
14: ; preds = %11
%15 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %63
20: ; preds = %14
%21 = load i32, i32* @SEEK_CUR
%22 = call i64 @fseek(i32* %0, i32 12, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %63, label %24
24: ; preds = %20
%25 = call i32 @fread(i8* %4, i32 1, i32 4, i32* %0)
%26 = icmp eq i32 %25, 4
br i1 %26, label %27, label %63
27: ; preds = %24
%28 = call i32 @read32(i8* %4)
%29 = add nsw i32 %28, %1
%30 = load i32, i32* @SEEK_SET
%31 = call i64 @fseek(i32* %0, i32 %29, i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %63, label %33
33: ; preds = %27
%34 = call i32 @fread(i8* %4, i32 1, i32 4, i32* %0)
%35 = icmp eq i32 %34, 4
br i1 %35, label %36, label %63
36: ; preds = %33
%37 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %29)
br label %63
42: ; preds = %36
%43 = call i32 @fread(i8* %4, i32 1, i32 4, i32* %0)
%44 = icmp eq i32 %43, 4
br i1 %44, label %45, label %63
45: ; preds = %42
%46 = call i32 @read32(i8* %4)
%47 = icmp sgt i32 %46, 0
br i1 %47, label %50, label %58
48: ; preds = %50
%49 = icmp eq i32 %54, %46
br i1 %49, label %58, label %50
50: ; preds = %45, %48
%51 = phi i32 [ %54, %48 ], [ 0, %45 ]
%52 = call i64 @doaw(i32* %0, i32 %1)
%53 = icmp eq i64 %52, 0
%54 = add nuw nsw i32 %51, 1
br i1 %53, label %48, label %55
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %63
58: ; preds = %48, %45
%59 = load i32, i32* @SEEK_SET
%60 = call i64 @fseek(i32* %0, i32 %5, i32 %59)
%61 = lshr i64 %60, 63
%62 = trunc i64 %61 to i32
br label %63
63: ; preds = %58, %42, %33, %27, %24, %20, %11, %7, %2, %55, %39, %17
%64 = phi i32 [ 1, %17 ], [ 1, %39 ], [ 1, %55 ], [ 1, %2 ], [ 1, %7 ], [ 1, %11 ], [ 1, %20 ], [ 1, %24 ], [ 1, %27 ], [ 1, %33 ], [ 1, %42 ], [ %62, %58 ]
ret i32 %64
}