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

/* Variables and functions */
int ntohs(int const);
uint16_t stun_get_method_str(const unsigned char *buf, size_t len) {
  if (!buf || len < 2)
    return (uint16_t)-1;
  uint16_t tt = ntohs(((const uint16_t *)buf)[0]);
  return (tt & 0x000F) | ((tt & 0x00E0) >> 1) | ((tt & 0x0E00) >> 2) |
         ((tt & 0x3000) >> 2);
}


x86 assembly (clang, -O0):
<stun_get_method_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1136 <stun_get_method_str+0x26>
cmpq   $0x2,-0x18(%rbp)
jae    1142 <stun_get_method_str+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    1183 <stun_get_method_str+0x73>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <ntohs@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
mov    -0x1c(%rbp),%ecx
and    $0xe0,%ecx
sar    $0x1,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0xe00,%ecx
sar    $0x2,%ecx
or     %ecx,%eax
mov    -0x1c(%rbp),%ecx
and    $0x3000,%ecx
sar    $0x2,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stun_get_method_str>:
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     114e <stun_get_method_str+0x3e>
cmp    $0x2,%rsi
jb     114e <stun_get_method_str+0x3e>
push   %rax
mov    (%rdi),%edi
call   1030 <ntohs@plt>
mov    %eax,%ecx
and    $0xf,%ecx
mov    %eax,%edx
shr    %edx
and    $0x70,%edx
or     %ecx,%edx
shr    $0x2,%eax
mov    %eax,%ecx
and    $0x380,%ecx
or     %edx,%ecx
and    $0xc00,%eax
or     %ecx,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
define i32 @stun_get_method_str(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i64, i64* %5
%11 = icmp ult i64 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i32 -1, i32* %3
br label %33
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = bitcast i8* %14 to i32*
%16 = getelementptr inbounds i32, i32* %15, i64 0
%17 = load i32, i32* %16
%18 = call i32 @ntohs(i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = and i32 %19, 15
%21 = load i32, i32* %6
%22 = and i32 %21, 224
%23 = ashr i32 %22, 1
%24 = or i32 %20, %23
%25 = load i32, i32* %6
%26 = and i32 %25, 3584
%27 = ashr i32 %26, 2
%28 = or i32 %24, %27
%29 = load i32, i32* %6
%30 = and i32 %29, 12288
%31 = ashr i32 %30, 2
%32 = or i32 %28, %31
store i32 %32, i32* %3
br label %33
33: ; preds = %13, %12
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @stun_get_method_str(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp ult i64 %1, 2
%5 = or i1 %3, %4
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = bitcast i8* %0 to i32*
%8 = load i32, i32* %7
%9 = tail call i32 @ntohs(i32 %8)
%10 = and i32 %9, 15
%11 = lshr i32 %9, 1
%12 = and i32 %11, 112
%13 = or i32 %12, %10
%14 = lshr i32 %9, 2
%15 = and i32 %14, 896
%16 = or i32 %13, %15
%17 = and i32 %14, 3072
%18 = or i32 %16, %17
br label %19
19: ; preds = %2, %6
%20 = phi i32 [ %18, %6 ], [ -1, %2 ]
ret i32 %20
}