#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_byte(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;
  }
  result = px[offset];
  (*r_offset)++;
  return result;
}


x86 assembly (clang, -O0):
<get_byte>:
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_byte+0x38>
movl   $0x0,-0x4(%rbp)
jmp    118f <get_byte+0x7f>
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1170 <get_byte+0x60>
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1030 <FRAMERR@plt>
movl   $0x0,-0x4(%rbp)
jmp    118f <get_byte+0x7f>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%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_byte>:
push   %rbx
mov    (%rcx),%eax
xor    %ebx,%ebx
cmp    %edx,%eax
ja     1134 <get_byte+0x24>
cmp    %edx,%eax
jne    112b <get_byte+0x1b>
lea    0xedc(%rip),%rsi
call   1030 <FRAMERR@plt>
jmp    1134 <get_byte+0x24>
movzbl (%rsi,%rax,1),%ebx
add    $0x1,%eax
mov    %eax,(%rcx)
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.NetFrame = type { i32 }
@.str = [16 x i8] c"smb: truncated\0A\00"
define i32 @get_byte(%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 %36
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 %36
25: ; preds = %18
%26 = load i8*, i8** %7
%27 = load i32, i32* %11
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
store i32 %31, i32* %10
%32 = load i32*, i32** %9
%33 = load i32, i32* %32
%34 = add i32 %33, 1
store i32 %34, i32* %32
%35 = load i32, i32* %10
store i32 %35, i32* %5
br label %36
36: ; preds = %25, %22, %17
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
%struct.NetFrame = type { i32 }
@.str = [16 x i8] c"smb: truncated\0A\00"
define i32 @get_byte(%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 %17, 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 %17
11: ; preds = %7
%12 = zext i32 %5 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = add i32 %5, 1
store i32 %16, i32* %3
br label %17
17: ; preds = %4, %11, %9
%18 = phi i32 [ 0, %9 ], [ %15, %11 ], [ 0, %4 ]
ret i32 %18
}