#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ memcmp(unsigned char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
scalar_t__ strncasecmp(char const *, char *, int);
scalar_t__ strncmp(char *, char *, int);
char *strrchr(char *, char);
int determine_file_format(char *name) {
  FILE *f;
  unsigned char head[200];
  int n;
  f = fopen(name, "r");
  if (!f) {
    printf("ERROR: Could not fine or open file %s\n", name);
    return 0;
  }
  n = fread(head, 1, 200, f);
  fclose(f);
  if (n < 8) {
    return 0;
  }
  {
    char *p = strrchr(name, '/');
    if (p) {
      p++;
    } else {
      p = name;
    }
    if (strlen(p) == 8 && strncmp(p, "GR3D", 4) == 0) {
      return 1;
    }
  }
  {
    char *p = strrchr(name, '/');
    if (p) {
      p++;
    } else {
      p = name;
    }
    if (strlen(p) == 8 && strncmp(p, "GRID", 4) == 0) {
      return 6;
    }
  }
  if ((n > 25) && ((memcmp(head + 16, "MMOUT   ", 8) == 0) ||
                   (memcmp(head + 16, "ZIGGY   ", 8) == 0))) {
    return 2;
  }
  if ((n > 161) && ((memcmp(head + 144, "AX    69NSPEC   ", 16) == 0) ||
                    (memcmp(head + 144, "AX    35NSPEC   ", 16) == 0) ||
                    (memcmp(head + 144, "15IMAX    35NSPE", 16) == 0) ||
                    (memcmp(head + 144, " 6IMAX    35NSPE", 16) == 0))) {
    return 2;
  }
  if (memcmp(head, "V5D\n", 4) == 0) {
    return 3;
  }
  if (head[0] == 0x80 && head[1] == 0x80 && head[2] == 0x80) {
    return 3;
  }
  if (strncasecmp((const char *)head, "DSET", 4) == 0) {
    return 4;
  }
  {
    int pos, n;
    for (pos = 0; head[pos] == ' '; pos++)
      ;
    n = 0;
    while (head[pos] >= '0' && head[pos] <= '9') {
      n = n * 10 + head[pos] - '0';
      pos++;
    }
    if (n > 0 && n < 100) {
      return 5;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<determine_file_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11da <determine_file_format+0x4a>
mov    -0x10(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
lea    -0xe0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc8,%edx
call   1040 <fread@plt>
mov    %eax,-0xe4(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x8,-0xe4(%rbp)
jge    121c <determine_file_format+0x8c>
movl   $0x0,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0xf0(%rbp)
cmpq   $0x0,-0xf0(%rbp)
je     1256 <determine_file_format+0xc6>
mov    -0xf0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf0(%rbp)
jmp    1261 <determine_file_format+0xd1>
mov    -0x10(%rbp),%rax
mov    %rax,-0xf0(%rbp)
mov    -0xf0(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x8,%eax
jne    12a4 <determine_file_format+0x114>
mov    -0xf0(%rbp),%rdi
lea    0xda5(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12a4 <determine_file_format+0x114>
movl   $0x1,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0xf8(%rbp)
cmpq   $0x0,-0xf8(%rbp)
je     12de <determine_file_format+0x14e>
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
jmp    12e9 <determine_file_format+0x159>
mov    -0x10(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x8,%eax
jne    132c <determine_file_format+0x19c>
mov    -0xf8(%rbp),%rdi
lea    0xd22(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    132c <determine_file_format+0x19c>
movl   $0x6,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
cmpl   $0x19,-0xe4(%rbp)
jle    1391 <determine_file_format+0x201>
lea    -0xe0(%rbp),%rdi
add    $0x10,%rdi
lea    0xce8(%rip),%rsi
mov    $0x8,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
je     1385 <determine_file_format+0x1f5>
lea    -0xe0(%rbp),%rdi
add    $0x10,%rdi
lea    0xccb(%rip),%rsi
mov    $0x8,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
jne    1391 <determine_file_format+0x201>
movl   $0x2,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
cmpl   $0xa1,-0xe4(%rbp)
jle    1451 <determine_file_format+0x2c1>
lea    -0xe0(%rbp),%rdi
add    $0x90,%rdi
lea    0xc8f(%rip),%rsi
mov    $0x10,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
je     1445 <determine_file_format+0x2b5>
lea    -0xe0(%rbp),%rdi
add    $0x90,%rdi
lea    0xc77(%rip),%rsi
mov    $0x10,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
je     1445 <determine_file_format+0x2b5>
lea    -0xe0(%rbp),%rdi
add    $0x90,%rdi
lea    0xc5f(%rip),%rsi
mov    $0x10,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
je     1445 <determine_file_format+0x2b5>
lea    -0xe0(%rbp),%rdi
add    $0x90,%rdi
lea    0xc47(%rip),%rsi
mov    $0x10,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
jne    1451 <determine_file_format+0x2c1>
movl   $0x2,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
lea    -0xe0(%rbp),%rdi
lea    0xc2a(%rip),%rsi
mov    $0x4,%edx
call   1090 <memcmp@plt>
cmp    $0x0,%rax
jne    147f <determine_file_format+0x2ef>
movl   $0x3,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
movzbl -0xe0(%rbp),%eax
cmp    $0x80,%eax
jne    14c1 <determine_file_format+0x331>
movzbl -0xdf(%rbp),%eax
cmp    $0x80,%eax
jne    14c1 <determine_file_format+0x331>
movzbl -0xde(%rbp),%eax
cmp    $0x80,%eax
jne    14c1 <determine_file_format+0x331>
movl   $0x3,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
lea    -0xe0(%rbp),%rdi
lea    0xbbf(%rip),%rsi
mov    $0x4,%edx
call   10a0 <strncasecmp@plt>
cmp    $0x0,%rax
jne    14ef <determine_file_format+0x35f>
movl   $0x4,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
movl   $0x0,-0xfc(%rbp)
movslq -0xfc(%rbp),%rax
movzbl -0xe0(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    152a <determine_file_format+0x39a>
jmp    1516 <determine_file_format+0x386>
mov    -0xfc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc(%rbp)
jmp    14f9 <determine_file_format+0x369>
movl   $0x0,-0x100(%rbp)
movslq -0xfc(%rbp),%rax
movzbl -0xe0(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x101(%rbp)
jl     156f <determine_file_format+0x3df>
movslq -0xfc(%rbp),%rax
movzbl -0xe0(%rbp,%rax,1),%eax
ff
cmp    $0x39,%eax
setle  %al
mov    %al,-0x101(%rbp)
mov    -0x101(%rbp),%al
test   $0x1,%al
jne    1582 <determine_file_format+0x3f2>
jmp    15b7 <determine_file_format+0x427>
imul   $0xa,-0x100(%rbp),%eax
movslq -0xfc(%rbp),%rcx
movzbl -0xe0(%rbp,%rcx,1),%ecx
ff
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x100(%rbp)
mov    -0xfc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc(%rbp)
jmp    1534 <determine_file_format+0x3a4>
cmpl   $0x0,-0x100(%rbp)
jle    15dd <determine_file_format+0x44d>
cmpl   $0x64,-0x100(%rbp)
jge    15dd <determine_file_format+0x44d>
movl   $0x5,-0x4(%rbp)
jmp    15e4 <determine_file_format+0x454>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<determine_file_format>:
push   %rbp
push   %r14
push   %rbx
sub    $0xd0,%rsp
mov    %rdi,%rbp
lea    0xe5b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     13b0 <determine_file_format+0x220>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xc8,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %ebx,%ebx
cmp    $0x8,%r14d
jl     13c1 <determine_file_format+0x231>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %rbp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x8,%eax
jne    1224 <determine_file_format+0x94>
lea    0xe1b(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     13cf <determine_file_format+0x23f>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %rbp,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x8,%eax
jne    1266 <determine_file_format+0xd6>
lea    0xdde(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     13d6 <determine_file_format+0x246>
cmp    $0x1a,%r14d
jb     1339 <determine_file_format+0x1a9>
lea    0x10(%rsp),%rbp
lea    0xdb7(%rip),%rsi
mov    %rbp,%rdi
mov    $0x8,%edx
call   1090 <memcmp@plt>
mov    $0x2,%ebx
test   %rax,%rax
je     13c1 <determine_file_format+0x231>
lea    0xd9e(%rip),%rsi
mov    %rbp,%rdi
mov    $0x8,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     13c1 <determine_file_format+0x231>
cmp    $0xa2,%r14d
jb     1339 <determine_file_format+0x1a9>
lea    0x90(%rsp),%rbp
lea    0xd79(%rip),%rsi
mov    %rbp,%rdi
mov    $0x10,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     13c1 <determine_file_format+0x231>
lea    0xd6d(%rip),%rsi
mov    %rbp,%rdi
mov    $0x10,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     13c1 <determine_file_format+0x231>
lea    0xd61(%rip),%rsi
mov    %rbp,%rdi
mov    $0x10,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     13c1 <determine_file_format+0x231>
lea    0xd55(%rip),%rsi
mov    %rbp,%rdi
mov    $0x10,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     13c1 <determine_file_format+0x231>
lea    0xd49(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1090 <memcmp@plt>
mov    $0x3,%ebx
test   %rax,%rax
je     13c1 <determine_file_format+0x231>
mov    (%rsp),%r14b
cmp    $0x80,%r14b
jne    136f <determine_file_format+0x1df>
cmpb   $0x80,0x1(%rsp)
jne    136f <determine_file_format+0x1df>
cmpb   $0x80,0x2(%rsp)
je     13c1 <determine_file_format+0x231>
lea    0xd18(%rip),%rsi
mov    %rsp,%rbp
mov    $0x4,%ebx
mov    %rbp,%rdi
mov    $0x4,%edx
call   10a0 <strncasecmp@plt>
test   %rax,%rax
je     13c1 <determine_file_format+0x231>
xor    %ebx,%ebx
cmp    $0x20,%r14b
jne    13dd <determine_file_format+0x24d>
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rax
cmpb   $0x20,0x1(%rsp,%rcx,1)
mov    %rax,%rcx
je     13a0 <determine_file_format+0x210>
jmp    13df <determine_file_format+0x24f>
lea    0xc4b(%rip),%rdi
mov    %rbp,%rsi
call   1070 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%ebx
jmp    13c1 <determine_file_format+0x231>
mov    $0x6,%ebx
jmp    13c1 <determine_file_format+0x231>
xor    %eax,%eax
mov    %eax,%ecx
mov    (%rsp,%rcx,1),%al
lea    -0x30(%rax),%edx
cmp    $0x9,%dl
ja     13c1 <determine_file_format+0x231>
lea    (%rcx,%rbp,1),%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
movzbl %al,%eax
lea    (%rcx,%rcx,4),%ecx
lea    (%rax,%rcx,2),%ecx
add    $0xffffffd0,%ecx
movzbl (%rdx),%eax
lea    -0x30(%rax),%esi
add    $0x1,%rdx
cmp    $0xa,%sil
jb     1400 <determine_file_format+0x270>
add    $0xffffffff,%ecx
xor    %eax,%eax
cmp    $0x63,%ecx
setb   %al
lea    (%rax,%rax,4),%ebx
jmp    13c1 <determine_file_format+0x231>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [39 x i8] c"ERROR: Could not fine or open file %s\0A\00"
@.str.2 = [5 x i8] c"GR3D\00"
@.str.3 = [5 x i8] c"GRID\00"
@.str.4 = [9 x i8] c"MMOUT \00"
@.str.5 = [9 x i8] c"ZIGGY \00"
@.str.6 = [17 x i8] c"AX 69NSPEC \00"
@.str.7 = [17 x i8] c"AX 35NSPEC \00"
@.str.8 = [17 x i8] c"15IMAX 35NSPE\00"
@.str.9 = [17 x i8] c" 6IMAX 35NSPE\00"
@.str.10 = [5 x i8] c"V5D\0A\00"
@.str.11 = [5 x i8] c"DSET\00"
define i32 @determine_file_format(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [200 x i8]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp ne i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 0, i32* %2
br label %178
18: ; preds = %1
%19 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32 @fread(i8* %19, i32 1, i32 200, i32* %20)
store i32 %21, i32* %6
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 8
br i1 %25, label %26, label %27
26: ; preds = %18
store i32 0, i32* %2
br label %178
27: ; preds = %18
%28 = load i8*, i8** %3
%29 = call i8* @strrchr(i8* %28, i8 signext 47)
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %7
br label %37
35: ; preds = %27
%36 = load i8*, i8** %3
store i8* %36, i8** %7
br label %37
37: ; preds = %35, %32
%38 = load i8*, i8** %7
%39 = call i32 @strlen(i8* %38)
%40 = icmp eq i32 %39, 8
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i8*, i8** %7
%43 = call i64 @strncmp(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41
store i32 1, i32* %2
br label %178
46: ; preds = %41, %37
%47 = load i8*, i8** %3
%48 = call i8* @strrchr(i8* %47, i8 signext 47)
store i8* %48, i8** %8
%49 = load i8*, i8** %8
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i8*, i8** %8
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %8
br label %56
54: ; preds = %46
%55 = load i8*, i8** %3
store i8* %55, i8** %8
br label %56
56: ; preds = %54, %51
%57 = load i8*, i8** %8
%58 = call i32 @strlen(i8* %57)
%59 = icmp eq i32 %58, 8
br i1 %59, label %60, label %65
60: ; preds = %56
%61 = load i8*, i8** %8
%62 = call i64 @strncmp(i8* %61, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %60
store i32 6, i32* %2
br label %178
65: ; preds = %60, %56
%66 = load i32, i32* %6
%67 = icmp sgt i32 %66, 25
br i1 %67, label %68, label %79
68: ; preds = %65
%69 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%70 = getelementptr inbounds i8, i8* %69, i64 16
%71 = call i64 @memcmp(i8* %70, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%72 = icmp eq i64 %71, 0
br i1 %72, label %78, label %73
73: ; preds = %68
%74 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%75 = getelementptr inbounds i8, i8* %74, i64 16
%76 = call i64 @memcmp(i8* %75, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 8)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %73, %68
store i32 2, i32* %2
br label %178
79: ; preds = %73, %65
%80 = load i32, i32* %6
%81 = icmp sgt i32 %80, 161
br i1 %81, label %82, label %103
82: ; preds = %79
%83 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%84 = getelementptr inbounds i8, i8* %83, i64 144
%85 = call i64 @memcmp(i8* %84, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 16)
%86 = icmp eq i64 %85, 0
br i1 %86, label %102, label %87
87: ; preds = %82
%88 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%89 = getelementptr inbounds i8, i8* %88, i64 144
%90 = call i64 @memcmp(i8* %89, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 16)
%91 = icmp eq i64 %90, 0
br i1 %91, label %102, label %92
92: ; preds = %87
%93 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%94 = getelementptr inbounds i8, i8* %93, i64 144
%95 = call i64 @memcmp(i8* %94, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 16)
%96 = icmp eq i64 %95, 0
br i1 %96, label %102, label %97
97: ; preds = %92
%98 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%99 = getelementptr inbounds i8, i8* %98, i64 144
%100 = call i64 @memcmp(i8* %99, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 16)
%101 = icmp eq i64 %100, 0
br i1 %101, label %102, label %103
102: ; preds = %97, %92, %87, %82
store i32 2, i32* %2
br label %178
103: ; preds = %97, %79
%104 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%105 = call i64 @memcmp(i8* %104, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4)
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %103
store i32 3, i32* %2
br label %178
108: ; preds = %103
%109 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%110 = load i8, i8* %109
%111 = zext i8 %110 to i32
%112 = icmp eq i32 %111, 128
br i1 %112, label %113, label %124
113: ; preds = %108
%114 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 1
%115 = load i8, i8* %114
%116 = zext i8 %115 to i32
%117 = icmp eq i32 %116, 128
br i1 %117, label %118, label %124
118: ; preds = %113
%119 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 2
%120 = load i8, i8* %119
%121 = zext i8 %120 to i32
%122 = icmp eq i32 %121, 128
br i1 %122, label %123, label %124
123: ; preds = %118
store i32 3, i32* %2
br label %178
124: ; preds = %118, %113, %108
%125 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%126 = call i64 @strncasecmp(i8* %125, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%127 = icmp eq i64 %126, 0
br i1 %127, label %128, label %129
128: ; preds = %124
store i32 4, i32* %2
br label %178
129: ; preds = %124
store i32 0, i32* %9
br label %130
130: ; preds = %138, %129
%131 = load i32, i32* %9
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %132
%134 = load i8, i8* %133
%135 = zext i8 %134 to i32
%136 = icmp eq i32 %135, 32
br i1 %136, label %137, label %141
137: ; preds = %130
br label %138
138: ; preds = %137
%139 = load i32, i32* %9
%140 = add nsw i32 %139, 1
store i32 %140, i32* %9
br label %130
141: ; preds = %130
store i32 0, i32* %10
br label %142
142: ; preds = %158, %141
%143 = load i32, i32* %9
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %144
%146 = load i8, i8* %145
%147 = zext i8 %146 to i32
%148 = icmp sge i32 %147, 48
br i1 %148, label %149, label %156
149: ; preds = %142
%150 = load i32, i32* %9
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %151
%153 = load i8, i8* %152
%154 = zext i8 %153 to i32
%155 = icmp sle i32 %154, 57
br label %156
156: ; preds = %149, %142
%157 = phi i1 [ false, %142 ], [ %155, %149 ]
br i1 %157, label %158, label %170
158: ; preds = %156
%159 = load i32, i32* %10
%160 = mul nsw i32 %159, 10
%161 = load i32, i32* %9
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %162
%164 = load i8, i8* %163
%165 = zext i8 %164 to i32
%166 = add nsw i32 %160, %165
%167 = sub nsw i32 %166, 48
store i32 %167, i32* %10
%168 = load i32, i32* %9
%169 = add nsw i32 %168, 1
store i32 %169, i32* %9
br label %142
170: ; preds = %156
%171 = load i32, i32* %10
%172 = icmp sgt i32 %171, 0
br i1 %172, label %173, label %177
173: ; preds = %170
%174 = load i32, i32* %10
%175 = icmp slt i32 %174, 100
br i1 %175, label %176, label %177
176: ; preds = %173
store i32 5, i32* %2
br label %178
177: ; preds = %173, %170
store i32 0, i32* %2
br label %178
178: ; preds = %177, %176, %128, %123, %107, %102, %78, %64, %45, %26, %15
%179 = load i32, i32* %2
ret i32 %179
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [39 x i8] c"ERROR: Could not fine or open file %s\0A\00"
@.str.2 = [5 x i8] c"GR3D\00"
@.str.3 = [5 x i8] c"GRID\00"
@.str.4 = [9 x i8] c"MMOUT \00"
@.str.5 = [9 x i8] c"ZIGGY \00"
@.str.6 = [17 x i8] c"AX 69NSPEC \00"
@.str.7 = [17 x i8] c"AX 35NSPEC \00"
@.str.8 = [17 x i8] c"15IMAX 35NSPE\00"
@.str.9 = [17 x i8] c" 6IMAX 35NSPE\00"
@.str.10 = [5 x i8] c"V5D\0A\00"
@.str.11 = [5 x i8] c"DSET\00"
define i32 @determine_file_format(i8* %0) {
%2 = alloca [200 x i8]
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %105
8: ; preds = %1
%9 = call i32 @fread(i8* %3, i32 1, i32 200, i32* %4)
%10 = tail call i32 @fclose(i32* %4)
%11 = icmp slt i32 %9, 8
br i1 %11, label %105, label %12
12: ; preds = %8
%13 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%14 = icmp eq i8* %13, null
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = select i1 %14, i8* %0, i8* %15
%17 = tail call i32 @strlen(i8* %16)
%18 = icmp eq i32 %17, 8
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = tail call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %105, label %22
22: ; preds = %12, %19
%23 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%24 = icmp eq i8* %23, null
%25 = getelementptr inbounds i8, i8* %23, i64 1
%26 = select i1 %24, i8* %0, i8* %25
%27 = tail call i32 @strlen(i8* %26)
%28 = icmp eq i32 %27, 8
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = tail call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %105, label %32
32: ; preds = %22, %29
%33 = icmp ugt i32 %9, 25
br i1 %33, label %34, label %56
34: ; preds = %32
%35 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 16
%36 = call i64 @memcmp(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%37 = icmp eq i64 %36, 0
br i1 %37, label %105, label %38
38: ; preds = %34
%39 = call i64 @memcmp(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 8)
%40 = icmp eq i64 %39, 0
br i1 %40, label %105, label %41
41: ; preds = %38
%42 = icmp ugt i32 %9, 161
br i1 %42, label %43, label %56
43: ; preds = %41
%44 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 144
%45 = call i64 @memcmp(i8* %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 16)
%46 = icmp eq i64 %45, 0
br i1 %46, label %105, label %47
47: ; preds = %43
%48 = call i64 @memcmp(i8* %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 16)
%49 = icmp eq i64 %48, 0
br i1 %49, label %105, label %50
50: ; preds = %47
%51 = call i64 @memcmp(i8* %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 16)
%52 = icmp eq i64 %51, 0
br i1 %52, label %105, label %53
53: ; preds = %50
%54 = call i64 @memcmp(i8* %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 16)
%55 = icmp eq i64 %54, 0
br i1 %55, label %105, label %56
56: ; preds = %32, %53, %41
%57 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4)
%58 = icmp eq i64 %57, 0
br i1 %58, label %105, label %59
59: ; preds = %56
%60 = load i8, i8* %3
%61 = icmp eq i8 %60, -128
%62 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 1
%63 = load i8, i8* %62
%64 = icmp eq i8 %63, -128
%65 = select i1 %61, i1 %64, i1 false
%66 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 2
%67 = load i8, i8* %66
%68 = icmp eq i8 %67, -128
%69 = select i1 %65, i1 %68, i1 false
br i1 %69, label %105, label %70
70: ; preds = %59
%71 = call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%72 = icmp eq i64 %71, 0
br i1 %72, label %105, label %73
73: ; preds = %70
%74 = icmp eq i8 %60, 32
br i1 %74, label %75, label %81
75: ; preds = %73, %75
%76 = phi i64 [ %80, %75 ], [ 1, %73 ]
%77 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = icmp eq i8 %78, 32
%80 = add nuw i64 %76, 1
br i1 %79, label %75, label %81
81: ; preds = %75, %73
%82 = phi i64 [ 0, %73 ], [ %76, %75 ]
%83 = and i64 %82, 4294967295
%84 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %83
%85 = load i8, i8* %84
%86 = add i8 %85, -48
%87 = icmp ult i8 %86, 10
br i1 %87, label %88, label %105
88: ; preds = %81, %88
%89 = phi i64 [ %96, %88 ], [ %83, %81 ]
%90 = phi i8 [ %98, %88 ], [ %85, %81 ]
%91 = phi i32 [ %95, %88 ], [ 0, %81 ]
%92 = zext i8 %90 to i32
%93 = mul nsw i32 %91, 10
%94 = add i32 %93, -48
%95 = add i32 %94, %92
%96 = add nuw i64 %89, 1
%97 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %96
%98 = load i8, i8* %97
%99 = add i8 %98, -48
%100 = icmp ult i8 %99, 10
br i1 %100, label %88, label %101
101: ; preds = %88
%102 = add i32 %95, -1
%103 = icmp ult i32 %102, 99
%104 = select i1 %103, i32 5, i32 0
br label %105
105: ; preds = %81, %101, %29, %70, %59, %56, %43, %47, %50, %53, %34, %38, %19, %8, %6
%106 = phi i32 [ 0, %6 ], [ 0, %8 ], [ 1, %19 ], [ 2, %38 ], [ 2, %34 ], [ 2, %53 ], [ 2, %50 ], [ 2, %47 ], [ 2, %43 ], [ 3, %56 ], [ 3, %59 ], [ 4, %70 ], [ 6, %29 ], [ 0, %81 ], [ %104, %101 ]
ret i32 %106
}