#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__ memcmp(unsigned char *, char *, int);
int tek_getnum_s7s(unsigned char **);
int tek_getsize(unsigned char *p) {
  static char header[15] = {0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x4f,
                            0x53, 0x41, 0x53, 0x4b, 0x43, 0x4d, 0x50};
  int size = -1;
  if (memcmp(p + 1, header, 15) == 0 &&
      (*p == 0x83 || *p == 0x85 || *p == 0x89)) {
    p += 16;
    size = tek_getnum_s7s(&p);
  }
  return size;
}


x86 assembly (clang, -O0):
<tek_getsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0x2eee(%rip),%rsi
mov    $0xf,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11a4 <tek_getsize+0x84>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x83,%eax
je     118c <tek_getsize+0x6c>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x85,%eax
je     118c <tek_getsize+0x6c>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x89,%eax
jne    11a4 <tek_getsize+0x84>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <tek_getnum_s7s@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tek_getsize>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
add    $0x1,%rdi
lea    0x2efd(%rip),%rsi
mov    $0xf,%edx
call   1040 <memcmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1174 <tek_getsize+0x54>
mov    (%rbx),%cl
add    $0x7d,%cl
cmp    $0x6,%cl
ja     1174 <tek_getsize+0x54>
movzbl %cl,%ecx
mov    $0x45,%edx
bt     %ecx,%edx
jae    1174 <tek_getsize+0x54>
add    $0x10,%rbx
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <tek_getnum_s7s@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@tek_getsize.header = internal global [15 x i8] c"\FF\FF\FF\01\00\00\00OSASKCMP"
define i32 @tek_getsize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = call i64 @memcmp(i8* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @tek_getsize.header, i64 0, i64 0), i32 15)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = icmp eq i32 %11, 131
br i1 %12, label %23, label %13
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 133
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = icmp eq i32 %21, 137
br i1 %22, label %23, label %27
23: ; preds = %18, %13, %8
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 16
store i8* %25, i8** %2
%26 = call i32 @tek_getnum_s7s(i8** %2)
store i32 %26, i32* %3
br label %27
27: ; preds = %23, %18, %1
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@tek_getsize.header = internal global [15 x i8] c"\FF\FF\FF\01\00\00\00OSASKCMP"
define i32 @tek_getsize(i8* %0) {
%2 = alloca i8*
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = tail call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @tek_getsize.header, i64 0, i64 0), i32 15)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i8, i8* %0
switch i8 %7, label %11 [
i8 -125, label %8
i8 -123, label %8
i8 -119, label %8
]
8: ; preds = %6, %6, %6
%9 = getelementptr inbounds i8, i8* %0, i64 16
store i8* %9, i8** %2
%10 = call i32 @tek_getnum_s7s(i8** %2)
br label %11
11: ; preds = %6, %8, %1
%12 = phi i32 [ %10, %8 ], [ -1, %1 ], [ -1, %6 ]
ret i32 %12
}