#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 intel_pt_pkt {
  int dummy;
};

/* Variables and functions */
int intel_pt_get_mnt(unsigned char const *, size_t, struct intel_pt_pkt *);
int intel_pt_get_3byte(const unsigned char *buf, size_t len,
                       struct intel_pt_pkt *packet) {
  if (len < 3)
    return -1;
  switch (buf[2]) {
  case 0x88:
    return intel_pt_get_mnt(buf, len, packet);
  default:
    return -2;
  }
}


x86 assembly (clang, -O0):
<intel_pt_get_3byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x3,-0x18(%rbp)
jae    113b <intel_pt_get_3byte+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    116f <intel_pt_get_3byte+0x5f>
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%al
sub    $0x88,%al
jne    1168 <intel_pt_get_3byte+0x58>
jmp    114f <intel_pt_get_3byte+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <intel_pt_get_mnt@plt>
mov    %eax,-0x4(%rbp)
jmp    116f <intel_pt_get_3byte+0x5f>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intel_pt_get_3byte>:
mov    $0xffffffff,%eax
cmp    $0x3,%rsi
jb     112b <intel_pt_get_3byte+0x1b>
mov    $0xfffffffe,%eax
cmpb   $0x88,0x2(%rdi)
jne    112b <intel_pt_get_3byte+0x1b>
jmp    1030 <intel_pt_get_mnt@plt>
ret

LLVM IR (-O0):
%struct.intel_pt_pkt = type { i32 }
define i32 @intel_pt_get_3byte(i8* %0, i64 %1, %struct.intel_pt_pkt* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.intel_pt_pkt*
store i8* %0, i8** %5
store i64 %1, i64* %6
store %struct.intel_pt_pkt* %2, %struct.intel_pt_pkt** %7
%8 = load i64, i64* %6
%9 = icmp ult i64 %8, 3
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 -1, i32* %4
br label %22
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 2
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
switch i32 %15, label %21 [
i32 136, label %16
]
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = load %struct.intel_pt_pkt*, %struct.intel_pt_pkt** %7
%20 = call i32 @intel_pt_get_mnt(i8* %17, i64 %18, %struct.intel_pt_pkt* %19)
store i32 %20, i32* %4
br label %22
21: ; preds = %11
store i32 -2, i32* %4
br label %22
22: ; preds = %21, %16, %10
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.intel_pt_pkt = type { i32 }
define i32 @intel_pt_get_3byte(i8* %0, i64 %1, %struct.intel_pt_pkt* %2) {
%4 = icmp ult i64 %1, 3
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, -120
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @intel_pt_get_mnt(i8* %0, i64 %1, %struct.intel_pt_pkt* %2)
br label %11
11: ; preds = %5, %3, %9
%12 = phi i32 [ %10, %9 ], [ -1, %3 ], [ -2, %5 ]
ret i32 %12
}