#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*/ const u_int8_t;
typedef int /*<<< orphan*/ u_char;

/* Variables and functions */
int /*<<< orphan*/ const *pkt_get_offset(int /*<<< orphan*/ const *, int const);
int /*<<< orphan*/ printf(char *);
u_int8_t pkt_get_uint8(const u_char *packet_data, const int offset) {
  const u_int8_t *ptr;
  if (offset < 0 || NULL == packet_data) {
    printf("ERR: Invalid input packet_data\n");
    return 0;
  }
  ptr = pkt_get_offset(packet_data, offset);
  if (!ptr) {
    return 0;
  } else {
    return *ptr;
  }
}


x86 assembly (clang, -O0):
<pkt_get_uint8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1145 <pkt_get_uint8+0x25>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    115d <pkt_get_uint8+0x3d>
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    118d <pkt_get_uint8+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <pkt_get_offset@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1184 <pkt_get_uint8+0x64>
movl   $0x0,-0x4(%rbp)
jmp    118d <pkt_get_uint8+0x6d>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkt_get_uint8>:
push   %rax
test   %rdi,%rdi
je     1138 <pkt_get_uint8+0x18>
test   %esi,%esi
js     1138 <pkt_get_uint8+0x18>
call   1030 <pkt_get_offset@plt>
test   %rax,%rax
je     1144 <pkt_get_uint8+0x24>
mov    (%rax),%eax
pop    %rcx
ret
lea    0xec1(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"ERR: Invalid input packet_data\0A\00"
define i32 @pkt_get_uint8(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32*, i32** %4
%11 = icmp eq i32* null, %10
br i1 %11, label %12, label %14
12: ; preds = %9, %2
%13 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %24
14: ; preds = %9
%15 = load i32*, i32** %4
%16 = load i32, i32* %5
%17 = call i32* @pkt_get_offset(i32* %15, i32 %16)
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %14
store i32 0, i32* %3
br label %24
21: ; preds = %14
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
store i32 %23, i32* %3
br label %24
24: ; preds = %21, %20, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@str = [31 x i8] c"ERR: Invalid input packet_data\00"
define i32 @pkt_get_uint8(i32* %0, i32 %1) {
%3 = icmp slt i32 %1, 0
%4 = icmp eq i32* %0, null
%5 = or i1 %4, %3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %13
8: ; preds = %2
%9 = tail call i32* @pkt_get_offset(i32* %0, i32 %1)
%10 = icmp eq i32* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = load i32, i32* %9
br label %13
13: ; preds = %8, %11, %6
%14 = phi i32 [ 0, %6 ], [ %12, %11 ], [ 0, %8 ]
ret i32 %14
}