#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 EOF;
int getc(int /*<<< orphan*/ *);
int DetectCodeType(FILE *in) {
  int p1, p2, p3, whatcode;
  whatcode = 0;
  while (((p1 = getc(in)) != EOF) && ((whatcode == 0) || (whatcode == 4))) {
    if (p1 == 27) {
      p2 = getc(in);
      if (p2 == '$') {
        p3 = getc(in);
        if (p3 == 'B')
          whatcode = 1;
        else if (p3 == '@')
          whatcode = 2;
      } else if (p2 == 'K')
        whatcode = 3;
    } else if ((p1 >= 129) && (p1 <= 254)) {
      p2 = getc(in);
      if (((p1 >= 129) && (p1 <= 159)) && ((p2 >= 64) && (p2 <= 160)))
        whatcode = 5;
      else if (((p1 >= 161) && (p1 <= 254)) && ((p2 >= 161) && (p2 <= 254)))
        whatcode = 4;
      else if (((p1 == 142)) && ((p2 >= 161) && (p2 <= 223)))
        whatcode = 4;
    }
  }
  return whatcode;
}


x86 assembly (clang, -O0):
<DetectCodeType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2eae(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     1164 <DetectCodeType+0x54>
mov    $0x1,%al
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x1a(%rbp)
je     115e <DetectCodeType+0x4e>
cmpl   $0x4,-0x18(%rbp)
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1174 <DetectCodeType+0x64>
jmp    12d6 <DetectCodeType+0x1c6>
cmpl   $0x1b,-0xc(%rbp)
jne    11ec <DetectCodeType+0xdc>
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x24,-0x10(%rbp)
jne    11d1 <DetectCodeType+0xc1>
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x42,-0x14(%rbp)
jne    11b6 <DetectCodeType+0xa6>
movl   $0x1,-0x18(%rbp)
jmp    11cc <DetectCodeType+0xbc>
cmpl   $0x40,-0x14(%rbp)
jne    11c7 <DetectCodeType+0xb7>
movl   $0x2,-0x18(%rbp)
jmp    11cc <DetectCodeType+0xbc>
jmp    11e7 <DetectCodeType+0xd7>
cmpl   $0x4b,-0x10(%rbp)
jne    11e2 <DetectCodeType+0xd2>
movl   $0x3,-0x18(%rbp)
jmp    11e7 <DetectCodeType+0xd7>
jmp    12d1 <DetectCodeType+0x1c1>
cmpl   $0x81,-0xc(%rbp)
jl     12cc <DetectCodeType+0x1bc>
cmpl   $0xfe,-0xc(%rbp)
jg     12cc <DetectCodeType+0x1bc>
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x81,-0xc(%rbp)
jl     124f <DetectCodeType+0x13f>
cmpl   $0x9f,-0xc(%rbp)
jg     124f <DetectCodeType+0x13f>
cmpl   $0x40,-0x10(%rbp)
jl     124f <DetectCodeType+0x13f>
cmpl   $0xa0,-0x10(%rbp)
jg     124f <DetectCodeType+0x13f>
movl   $0x5,-0x18(%rbp)
jmp    12c7 <DetectCodeType+0x1b7>
cmpl   $0xa1,-0xc(%rbp)
jl     128f <DetectCodeType+0x17f>
cmpl   $0xfe,-0xc(%rbp)
jg     128f <DetectCodeType+0x17f>
cmpl   $0xa1,-0x10(%rbp)
jl     128f <DetectCodeType+0x17f>
cmpl   $0xfe,-0x10(%rbp)
jg     128f <DetectCodeType+0x17f>
movl   $0x4,-0x18(%rbp)
jmp    12c2 <DetectCodeType+0x1b2>
cmpl   $0x8e,-0xc(%rbp)
jne    12bd <DetectCodeType+0x1ad>
cmpl   $0xa1,-0x10(%rbp)
jl     12bd <DetectCodeType+0x1ad>
cmpl   $0xdf,-0x10(%rbp)
jg     12bd <DetectCodeType+0x1ad>
movl   $0x4,-0x18(%rbp)
jmp    12c2 <DetectCodeType+0x1b2>
jmp    12c7 <DetectCodeType+0x1b7>
jmp    12cc <DetectCodeType+0x1bc>
jmp    12d1 <DetectCodeType+0x1c1>
jmp    1123 <DetectCodeType+0x13>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DetectCodeType>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <getc@plt>
mov    0x2ebe(%rip),%r15
xor    %ebp,%ebp
cmp    (%r15),%eax
je     121d <DetectCodeType+0x10d>
mov    %eax,%ebx
xor    %r13d,%r13d
mov    $0x4,%r12d
cmp    $0x1b,%ebx
jne    1180 <DetectCodeType+0x70>
mov    %r14,%rdi
call   1030 <getc@plt>
cmp    $0x4b,%eax
je     11e5 <DetectCodeType+0xd5>
cmp    $0x24,%eax
jne    11e0 <DetectCodeType+0xd0>
mov    %r14,%rdi
call   1030 <getc@plt>
cmp    $0x42,%eax
je     11ec <DetectCodeType+0xdc>
cmp    $0x40,%eax
jne    11e0 <DetectCodeType+0xd0>
mov    $0x2,%ebp
jmp    1200 <DetectCodeType+0xf0>
nop
lea    -0x81(%rbx),%eax
cmp    $0x7d,%eax
ja     11e0 <DetectCodeType+0xd0>
mov    %r14,%rdi
call   1030 <getc@plt>
cmp    $0x9f,%ebx
ja     11a8 <DetectCodeType+0x98>
lea    -0x40(%rax),%ecx
mov    $0x5,%ebp
cmp    $0x61,%ecx
jb     1200 <DetectCodeType+0xf0>
add    $0xffffff5f,%eax
cmp    $0xa1,%ebx
jb     11bf <DetectCodeType+0xaf>
mov    $0x4,%ebp
cmp    $0x5e,%eax
jb     1200 <DetectCodeType+0xf0>
cmp    $0x3f,%eax
mov    %r13d,%ebp
cmovb  %r12d,%ebp
cmp    $0x8e,%ebx
cmovne %r13d,%ebp
jmp    1200 <DetectCodeType+0xf0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13d,%ebp
jmp    1200 <DetectCodeType+0xf0>
mov    $0x3,%ebp
jmp    1200 <DetectCodeType+0xf0>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <getc@plt>
cmp    (%r15),%eax
je     121d <DetectCodeType+0x10d>
mov    %eax,%ebx
mov    %ebp,%eax
mov    %ebp,%r13d
and    $0xfffffffb,%eax
je     1140 <DetectCodeType+0x30>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @DetectCodeType(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %6
br label %7
7: ; preds = %96, %1
%8 = load i32*, i32** %2
%9 = call i32 @getc(i32* %8)
store i32 %9, i32* %3
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %7
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 4
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ true, %12 ], [ %17, %15 ]
br label %20
20: ; preds = %18, %7
%21 = phi i1 [ false, %7 ], [ %19, %18 ]
br i1 %21, label %22, label %97
22: ; preds = %20
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 27
br i1 %24, label %25, label %48
25: ; preds = %22
%26 = load i32*, i32** %2
%27 = call i32 @getc(i32* %26)
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 36
br i1 %29, label %30, label %42
30: ; preds = %25
%31 = load i32*, i32** %2
%32 = call i32 @getc(i32* %31)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 66
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 1, i32* %6
br label %41
36: ; preds = %30
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 64
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 2, i32* %6
br label %40
40: ; preds = %39, %36
br label %41
41: ; preds = %40, %35
br label %47
42: ; preds = %25
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 75
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 3, i32* %6
br label %46
46: ; preds = %45, %42
br label %47
47: ; preds = %46, %41
br label %96
48: ; preds = %22
%49 = load i32, i32* %3
%50 = icmp sge i32 %49, 129
br i1 %50, label %51, label %95
51: ; preds = %48
%52 = load i32, i32* %3
%53 = icmp sle i32 %52, 254
br i1 %53, label %54, label %95
54: ; preds = %51
%55 = load i32*, i32** %2
%56 = call i32 @getc(i32* %55)
store i32 %56, i32* %4
%57 = load i32, i32* %3
%58 = icmp sge i32 %57, 129
br i1 %58, label %59, label %69
59: ; preds = %54
%60 = load i32, i32* %3
%61 = icmp sle i32 %60, 159
br i1 %61, label %62, label %69
62: ; preds = %59
%63 = load i32, i32* %4
%64 = icmp sge i32 %63, 64
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i32, i32* %4
%67 = icmp sle i32 %66, 160
br i1 %67, label %68, label %69
68: ; preds = %65
store i32 5, i32* %6
br label %94
69: ; preds = %65, %62, %59, %54
%70 = load i32, i32* %3
%71 = icmp sge i32 %70, 161
br i1 %71, label %72, label %82
72: ; preds = %69
%73 = load i32, i32* %3
%74 = icmp sle i32 %73, 254
br i1 %74, label %75, label %82
75: ; preds = %72
%76 = load i32, i32* %4
%77 = icmp sge i32 %76, 161
br i1 %77, label %78, label %82
78: ; preds = %75
%79 = load i32, i32* %4
%80 = icmp sle i32 %79, 254
br i1 %80, label %81, label %82
81: ; preds = %78
store i32 4, i32* %6
br label %93
82: ; preds = %78, %75, %72, %69
%83 = load i32, i32* %3
%84 = icmp eq i32 %83, 142
br i1 %84, label %85, label %92
85: ; preds = %82
%86 = load i32, i32* %4
%87 = icmp sge i32 %86, 161
br i1 %87, label %88, label %92
88: ; preds = %85
%89 = load i32, i32* %4
%90 = icmp sle i32 %89, 223
br i1 %90, label %91, label %92
91: ; preds = %88
store i32 4, i32* %6
br label %92
92: ; preds = %91, %88, %85, %82
br label %93
93: ; preds = %92, %81
br label %94
94: ; preds = %93, %68
br label %95
95: ; preds = %94, %51, %48
br label %96
96: ; preds = %95, %47
br label %7
97: ; preds = %20
%98 = load i32, i32* %6
ret i32 %98
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @DetectCodeType(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %43, label %5
5: ; preds = %1, %35
%6 = phi i32 [ %37, %35 ], [ %2, %1 ]
%7 = phi i32 [ %36, %35 ], [ 0, %1 ]
%8 = icmp eq i32 %6, 27
br i1 %8, label %9, label %15
9: ; preds = %5
%10 = tail call i32 @getc(i32* %0)
switch i32 %10, label %35 [
i32 36, label %11
i32 75, label %14
]
11: ; preds = %9
%12 = tail call i32 @getc(i32* %0)
switch i32 %12, label %34 [
i32 66, label %35
i32 64, label %13
]
13: ; preds = %11
br label %35
14: ; preds = %9
br label %35
15: ; preds = %5
%16 = add i32 %6, -129
%17 = icmp ult i32 %16, 126
br i1 %17, label %18, label %35
18: ; preds = %15
%19 = tail call i32 @getc(i32* %0)
%20 = icmp ult i32 %6, 160
%21 = add i32 %19, -64
%22 = icmp ult i32 %21, 97
%23 = and i1 %20, %22
br i1 %23, label %35, label %24
24: ; preds = %18
%25 = icmp ugt i32 %6, 160
%26 = add i32 %19, -161
%27 = icmp ult i32 %26, 94
%28 = and i1 %25, %27
br i1 %28, label %35, label %29
29: ; preds = %24
%30 = icmp eq i32 %6, 142
%31 = icmp ult i32 %26, 63
%32 = and i1 %30, %31
%33 = select i1 %32, i32 4, i32 %7
br label %35
34: ; preds = %11
br label %35
35: ; preds = %29, %24, %18, %9, %11, %34, %15, %13, %14
%36 = phi i32 [ 2, %13 ], [ 3, %14 ], [ %7, %15 ], [ 1, %11 ], [ %7, %34 ], [ %7, %9 ], [ 5, %18 ], [ 4, %24 ], [ %33, %29 ]
%37 = tail call i32 @getc(i32* %0)
%38 = load i32, i32* @EOF
%39 = icmp ne i32 %37, %38
%40 = and i32 %36, -5
%41 = icmp eq i32 %40, 0
%42 = select i1 %39, i1 %41, i1 false
br i1 %42, label %5, label %43
43: ; preds = %35, %1
%44 = phi i32 [ 0, %1 ], [ %36, %35 ]
ret i32 %44
}