#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 */
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/);
int fseek(int /*<<< orphan*/, int, int /*<<< orphan*/);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(void) {
  char *header = "Allaire Cold Fusion Template\012Header Size: ";
  char buffer[54];
  int debug = 0;
  int headsize, outlen, seek_pos;
  if ((fread(buffer, 1, 54, stdin) < 54) || (memcmp(buffer, header, 42))) {
    if (debug)
      fprintf(stderr, "File is not an encrypted template\n");
    return 1;
  }
  if (!memcmp(&buffer[42], "New Version", 11)) {
    if (debug)
      fprintf(stderr, "\nEncrypted with 'New Version'\n");
    headsize = 69;
  } else {
    if (debug)
      fprintf(stderr, "\nEncrypted with 'Old Version'\n");
    headsize = atoi(&buffer[42]);
  }
  seek_pos = fseek(stdin, headsize, SEEK_SET);
  if ((headsize < 54) || seek_pos < 0) {
    if (debug) {
      fprintf(stderr, "Error in file format.\n Head size: %i\n", headsize);
      if (headsize < 54) {
        fprintf(stderr, "Error: Head Size < 54");
      }
      if (seek_pos < 0) {
        fprintf(stderr, "Couldn't set seek position: %i", seek_pos);
      }
      fprintf(stderr, "\n");
    }
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x36,%edx
call   1030 <fread@plt>
cmp    $0x36,%eax
jl     11b2 <main+0x62>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2a,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11df <main+0x8f>
cmpl   $0x0,-0x54(%rbp)
je     11d3 <main+0x83>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1324 <main+0x1d4>
lea    -0x50(%rbp),%rdi
add    $0x2a,%rdi
lea    0xe60(%rip),%rsi
mov    $0xb,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    122f <main+0xdf>
cmpl   $0x0,-0x54(%rbp)
je     1223 <main+0xd3>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x45,-0x58(%rbp)
jmp    1260 <main+0x110>
cmpl   $0x0,-0x54(%rbp)
je     1250 <main+0x100>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x50(%rbp),%rdi
add    $0x2a,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x58(%rbp)
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%esi
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x36,-0x58(%rbp)
jl     1291 <main+0x141>
cmpl   $0x0,-0x60(%rbp)
jge    131d <main+0x1cd>
cmpl   $0x0,-0x54(%rbp)
je     1311 <main+0x1c1>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%edx
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x36,-0x58(%rbp)
jge    12d6 <main+0x186>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x60(%rbp)
jge    12fa <main+0x1aa>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
mov    -0x60(%rbp),%edx
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1324 <main+0x1d4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    0x2e9a(%rip),%r14
mov    (%r14),%ecx
mov    %rsp,%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
mov    $0x36,%edx
call   1030 <fread@plt>
cmp    $0x36,%eax
jl     11d8 <main+0x98>
lea    0xe8c(%rip),%rsi
mov    %rsp,%rdi
mov    $0x2a,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    11d8 <main+0x98>
lea    0x2a(%rsp),%rbx
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
mov    $0xb,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     11b0 <main+0x70>
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
jmp    11b5 <main+0x75>
mov    $0x45,%ebx
mov    (%r14),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%esi
call   1050 <fseek@plt>
cmp    $0x36,%ebx
setl   %cl
test   %eax,%eax
sets   %al
or     %cl,%al
movzbl %al,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Allaire Cold Fusion Template\0AHeader Size: \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [35 x i8] c"File is not an encrypted template\0A\00"
@.str.2 = [12 x i8] c"New Version\00"
@.str.3 = [31 x i8] c"\0AEncrypted with 'New Version'\0A\00"
@.str.4 = [31 x i8] c"\0AEncrypted with 'Old Version'\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [38 x i8] c"Error in file format.\0A Head size: %i\0A\00"
@.str.6 = [22 x i8] c"Error: Head Size < 54\00"
@.str.7 = [31 x i8] c"Couldn't set seek position: %i\00"
@.str.8 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [54 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8** %2
store i32 0, i32* %4
%8 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fread(i8* %8, i32 1, i32 54, i32 %9)
%11 = icmp slt i32 %10, 54
br i1 %11, label %17, label %12
12: ; preds = %0
%13 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 0
%14 = load i8*, i8** %2
%15 = call i64 @memcmp(i8* %13, i8* %14, i32 42)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %12, %0
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %20, %17
store i32 1, i32* %1
br label %78
24: ; preds = %12
%25 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 42
%26 = call i64 @memcmp(i8* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%27 = icmp ne i64 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %24
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %31, %28
store i32 69, i32* %5
br label %44
35: ; preds = %24
%36 = load i32, i32* %4
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %38, %35
%42 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 42
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %5
br label %44
44: ; preds = %41, %34
%45 = load i32, i32* @stdin
%46 = load i32, i32* %5
%47 = load i32, i32* @SEEK_SET
%48 = call i32 @fseek(i32 %45, i32 %46, i32 %47)
store i32 %48, i32* %7
%49 = load i32, i32* %5
%50 = icmp slt i32 %49, 54
br i1 %50, label %54, label %51
51: ; preds = %44
%52 = load i32, i32* %7
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %77
54: ; preds = %51, %44
%55 = load i32, i32* %4
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %76
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = load i32, i32* %5
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %5
%62 = icmp slt i32 %61, 54
br i1 %62, label %63, label %66
63: ; preds = %57
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %63, %57
%67 = load i32, i32* %7
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = load i32, i32* @stderr
%71 = load i32, i32* %7
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %69, %66
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %76
76: ; preds = %73, %54
store i32 1, i32* %1
br label %78
77: ; preds = %51
store i32 0, i32* %1
br label %78
78: ; preds = %77, %76, %23
%79 = load i32, i32* %1
ret i32 %79
}

LLVM IR (-O2):
@.str = [43 x i8] c"Allaire Cold Fusion Template\0AHeader Size: \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.2 = [12 x i8] c"New Version\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca [54 x i8]
%2 = getelementptr inbounds [54 x i8], [54 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fread(i8* %2, i32 1, i32 54, i32 %3)
%5 = icmp slt i32 %4, 54
br i1 %5, label %24, label %6
6: ; preds = %0
%7 = call i64 @memcmp(i8* %2, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 42)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = getelementptr inbounds [54 x i8], [54 x i8]* %1, i64 0, i64 42
%11 = call i64 @memcmp(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 11)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 @atoi(i8* %10)
br label %15
15: ; preds = %9, %13
%16 = phi i32 [ %14, %13 ], [ 69, %9 ]
%17 = load i32, i32* @stdin
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32 %17, i32 %16, i32 %18)
%20 = icmp slt i32 %16, 54
%21 = icmp slt i32 %19, 0
%22 = select i1 %20, i1 true, i1 %21
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %15, %6, %0
%25 = phi i32 [ 1, %0 ], [ 1, %6 ], [ %23, %15 ]
ret i32 %25
}