#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 */
struct NetFrame {
  int dummy;
};
struct Ferret {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ FRAMERR(struct NetFrame *, char *, char *, ...);
int /*<<< orphan*/ memcmp(unsigned char const *, char *, int);
int /*<<< orphan*/ process_smb_dgm(struct Ferret *, struct NetFrame *,
                                   unsigned char const *, unsigned int);
void parse_novell_netbios_dgram(struct Ferret *ferret, struct NetFrame *frame,
                                const unsigned char *px, unsigned length) {
  unsigned opcode;
  unsigned offset = 0;
  offset += 16 * 2;
  if (offset + 2 >= length) {
    FRAMERR(frame, "%s: truncated\n", "IPXNB");
    return;
  }
  opcode = px[offset + 0];
  switch (opcode) {
  case 0xfc:
    offset += 4;
    offset += 32;
    if (offset + 4 < length && memcmp(px + offset,
                                      "\xFF"
                                      "SMB",
                                      4) == 0)
      process_smb_dgm(ferret, frame, px + offset, length - offset);
    break;
  default:
    FRAMERR(frame, "%s: unknown type: 0x%x\n", "IPXNB", opcode);
  }
}


x86 assembly (clang, -O0):
<parse_novell_netbios_dgram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
cmp    -0x1c(%rbp),%eax
jb     1184 <parse_novell_netbios_dgram+0x54>
mov    -0x10(%rbp),%rdi
lea    0xe8f(%rip),%rsi
lea    0xe97(%rip),%rdx
mov    $0x0,%al
call   1040 <FRAMERR@plt>
jmp    1228 <parse_novell_netbios_dgram+0xf8>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
sub    $0xfc,%eax
jne    120c <parse_novell_netbios_dgram+0xdc>
jmp    11a5 <parse_novell_netbios_dgram+0x75>
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x20,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x4,%eax
cmp    -0x1c(%rbp),%eax
jae    1207 <parse_novell_netbios_dgram+0xd7>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    %rax,%rdi
lea    0xe3e(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    1207 <parse_novell_netbios_dgram+0xd7>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%eax
add    %rax,%rdx
mov    -0x1c(%rbp),%ecx
sub    -0x24(%rbp),%ecx
call   1050 <process_smb_dgm@plt>
jmp    1228 <parse_novell_netbios_dgram+0xf8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%ecx
lea    0xe00(%rip),%rsi
lea    0xdee(%rip),%rdx
mov    $0x0,%al
call   1040 <FRAMERR@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_novell_netbios_dgram>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x22,%ecx
ja     1161 <parse_novell_netbios_dgram+0x31>
lea    0xeba(%rip),%rsi
lea    0xec2(%rip),%rdx
mov    %r14,%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <FRAMERR@plt>
mov    %ecx,%ebp
mov    %rdx,%rbx
movzbl 0x20(%rdx),%ecx
cmp    $0xfc,%ecx
jne    11a1 <parse_novell_netbios_dgram+0x71>
cmp    $0x49,%ebp
jb     1196 <parse_novell_netbios_dgram+0x66>
mov    %rdi,%r15
add    $0x44,%rbx
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     11c3 <parse_novell_netbios_dgram+0x93>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe72(%rip),%rsi
lea    0xe60(%rip),%rdx
mov    %r14,%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <FRAMERR@plt>
add    $0xffffffbc,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <process_smb_dgm@plt>

LLVM IR (-O0):
%struct.Ferret = type { i32 }
%struct.NetFrame = type { i32 }
@.str = [15 x i8] c"%s: truncated\0A\00"
@.str.1 = [6 x i8] c"IPXNB\00"
@.str.2 = [5 x i8] c"\FFSMB\00"
@.str.3 = [24 x i8] c"%s: unknown type: 0x%x\0A\00"
define void @parse_novell_netbios_dgram(%struct.Ferret* %0, %struct.NetFrame* %1, i8* %2, i32 %3) {
%5 = alloca %struct.Ferret*
%6 = alloca %struct.NetFrame*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.Ferret* %0, %struct.Ferret** %5
store %struct.NetFrame* %1, %struct.NetFrame** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %10
%11 = load i32, i32* %10
%12 = add i32 %11, 32
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = add i32 %13, 2
%15 = load i32, i32* %8
%16 = icmp uge i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = load %struct.NetFrame*, %struct.NetFrame** %6
%19 = call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %61
20: ; preds = %4
%21 = load i8*, i8** %7
%22 = load i32, i32* %10
%23 = add i32 %22, 0
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
store i32 %27, i32* %9
%28 = load i32, i32* %9
switch i32 %28, label %57 [
i32 252, label %29
]
29: ; preds = %20
%30 = load i32, i32* %10
%31 = add i32 %30, 4
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = add i32 %32, 32
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = add i32 %34, 4
%36 = load i32, i32* %8
%37 = icmp ult i32 %35, %36
br i1 %37, label %38, label %56
38: ; preds = %29
%39 = load i8*, i8** %7
%40 = load i32, i32* %10
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = call i32 @memcmp(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %56
45: ; preds = %38
%46 = load %struct.Ferret*, %struct.Ferret** %5
%47 = load %struct.NetFrame*, %struct.NetFrame** %6
%48 = load i8*, i8** %7
%49 = load i32, i32* %10
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i32, i32* %8
%53 = load i32, i32* %10
%54 = sub i32 %52, %53
%55 = call i32 @process_smb_dgm(%struct.Ferret* %46, %struct.NetFrame* %47, i8* %51, i32 %54)
br label %56
56: ; preds = %45, %38, %29
br label %61
57: ; preds = %20
%58 = load %struct.NetFrame*, %struct.NetFrame** %6
%59 = load i32, i32* %9
%60 = call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %58, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %17, %57, %56
ret void
}

LLVM IR (-O2):
%struct.Ferret = type { i32 }
%struct.NetFrame = type { i32 }
@.str = [15 x i8] c"%s: truncated\0A\00"
@.str.1 = [6 x i8] c"IPXNB\00"
@.str.2 = [5 x i8] c"\FFSMB\00"
@.str.3 = [24 x i8] c"%s: unknown type: 0x%x\0A\00"
define void @parse_novell_netbios_dgram(%struct.Ferret* %0, %struct.NetFrame* %1, i8* %2, i32 %3) {
%5 = icmp ult i32 %3, 35
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %24
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %2, i64 32
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, -4
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = icmp ugt i32 %3, 72
br i1 %13, label %14, label %24
14: ; preds = %12
%15 = getelementptr inbounds i8, i8* %2, i64 68
%16 = tail call i32 @memcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = add i32 %3, -68
%20 = tail call i32 @process_smb_dgm(%struct.Ferret* %0, %struct.NetFrame* %1, i8* %15, i32 %19)
br label %24
21: ; preds = %8
%22 = zext i8 %10 to i32
%23 = tail call i32 (%struct.NetFrame*, i8*, i8*, ...) @FRAMERR(%struct.NetFrame* %1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %18, %14, %12, %6
ret void
}