#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;
};

/* Variables and functions */
int /*<<< orphan*/ FRAMERR(struct NetFrame *, char *);
unsigned get_word(struct NetFrame *frame, const unsigned char *px,
                  unsigned length, unsigned *r_offset) {
  unsigned result;
  unsigned offset = *r_offset;
  if (offset > length)
    return 0;
  if (offset == length) {
    FRAMERR(frame, "smb: truncated\n");
    return 0;
  }
  if (offset + 1 == length) {
    FRAMERR(frame, "smb: truncated\n");
    return 0;
  }
  result = (*((unsigned char *)(px + offset) + 0) << 0 |
            *((unsigned char *)(px + offset) + 1) << 8);
  (*r_offset) += 2;
  return result;
}


x86 assembly (clang, -O0):
<get_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jbe    1148 <get_word+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11ce <get_word+0xbe>
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1170 <get_word+0x60>
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1030 <FRAMERR@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ce <get_word+0xbe>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jne    119b <get_word+0x8b>
mov    -0x10(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1030 <FRAMERR@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ce <get_word+0xbe>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
shl    $0x0,%eax
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%edx
movzbl 0x1(%rcx,%rdx,1),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x2,%ecx
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word>:
push   %rbp
push   %rbx
push   %rax
mov    (%rcx),%eax
xor    %ebp,%ebp
cmp    %edx,%eax
ja     113d <get_word+0x2d>
cmp    %edx,%eax
je     1126 <get_word+0x16>
lea    0x1(%rax),%ebx
cmp    %edx,%ebx
jne    1134 <get_word+0x24>
lea    0xed3(%rip),%rsi
call   1030 <FRAMERR@plt>
jmp    113d <get_word+0x2d>
movzwl (%rsi,%rax,1),%ebp
add    $0x2,%eax
mov    %eax,(%rcx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.NetFrame = type { i32 }
@.str = [16 x i8] c"smb: truncated\0A\00"
define i32 @get_word(%struct.NetFrame* %0, i8* nocapture %1, i32 %2, i32* nocapture %3) {
%5 = load i32, i32* %3
%6 = icmp ugt i32 %5, %2
br i1 %6, label %27, label %7
7: ; preds = %4
%8 = icmp eq i32 %5, %2
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @FRAMERR(%struct.NetFrame* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %27
11: ; preds = %7
%12 = add i32 %5, 1
%13 = icmp eq i32 %12, %2
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @FRAMERR(%struct.NetFrame* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %27
16: ; preds = %11
%17 = zext i32 %5 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = shl nuw nsw i32 %23, 8
%25 = or i32 %24, %20
%26 = add i32 %5, 2
store i32 %26, i32* %3
br label %27
27: ; preds = %4, %16, %14, %9
%28 = phi i32 [ 0, %9 ], [ 0, %14 ], [ %25, %16 ], [ 0, %4 ]
ret i32 %28
}