#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 scalar_t__ pframe;

/* Variables and functions */
unsigned short le16_to_cpu(int);
unsigned char *get_sa(unsigned char *pframe) {
  unsigned char *sa;
  unsigned int to_fr_ds =
      ((((*(unsigned short *)(pframe)) & le16_to_cpu((1 << (8)))) != 0) << 1) |
      (((*(unsigned short *)(pframe)) & le16_to_cpu((1 << (9)))) != 0);
  switch (to_fr_ds) {
  case 0x00:
    sa = ((unsigned char *)((unsigned long)(pframe) + 10));
    break;
  case 0x01:
    sa = ((unsigned char *)((unsigned long)(pframe) + 16));
    break;
  case 0x02:
    sa = ((unsigned char *)((unsigned long)(pframe) + 10));
    break;
  default:
    sa = ((unsigned char *)((unsigned long)(pframe) + 24));
    break;
  }
  return sa;
}


x86 assembly (clang, -O0):
<get_sa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ax
mov    %ax,-0x20(%rbp)
mov    $0x100,%edi
call   1030 <le16_to_cpu@plt>
mov    %ax,%cx
mov    -0x20(%rbp),%ax
and    %cx,%ax
test   %ax,%ax
setne  %al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ax
mov    %ax,-0x1e(%rbp)
mov    $0x200,%edi
call   1030 <le16_to_cpu@plt>
mov    -0x1e(%rbp),%cx
mov    %ax,%dx
mov    -0x1c(%rbp),%eax
and    %dx,%cx
test   %cx,%cx
setne  %cl
movzbl %cl,%edx
mov    %eax,%ecx
mov    %edx,%eax
lea    (%rax,%rcx,2),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     11b1 <get_sa+0xa1>
jmp    118f <get_sa+0x7f>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     11c2 <get_sa+0xb2>
jmp    11a0 <get_sa+0x90>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     11d3 <get_sa+0xc3>
jmp    11e4 <get_sa+0xd4>
mov    -0x8(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    11f0 <get_sa+0xe0>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
jmp    11f0 <get_sa+0xe0>
mov    -0x8(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    11f0 <get_sa+0xe0>
mov    -0x8(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sa>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
movzwl (%rdi),%ebp
mov    $0x100,%edi
call   1030 <le16_to_cpu@plt>
xor    %ebx,%ebx
test   %bp,%ax
setne  %bl
movzwl (%r14),%ebp
mov    $0x200,%edi
call   1030 <le16_to_cpu@plt>
xor    %ecx,%ecx
test   %bp,%ax
setne  %cl
lea    (%rcx,%rbx,2),%ecx
mov    $0x18,%eax
cmp    $0x3,%ecx
je     115c <get_sa+0x4c>
mov    %ecx,%eax
lea    0xea8(%rip),%rcx
mov    (%rcx,%rax,8),%rax
add    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @get_sa(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i16*
%7 = load i16, i16* %6
%8 = zext i16 %7 to i32
%9 = call zeroext i16 @le16_to_cpu(i32 256)
%10 = zext i16 %9 to i32
%11 = and i32 %8, %10
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i32
%14 = shl i32 %13, 1
%15 = load i8*, i8** %2
%16 = bitcast i8* %15 to i16*
%17 = load i16, i16* %16
%18 = zext i16 %17 to i32
%19 = call zeroext i16 @le16_to_cpu(i32 512)
%20 = zext i16 %19 to i32
%21 = and i32 %18, %20
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i32
%24 = or i32 %14, %23
store i32 %24, i32* %4
%25 = load i32, i32* %4
switch i32 %25, label %41 [
i32 0, label %26
i32 1, label %31
i32 2, label %36
]
26: ; preds = %1
%27 = load i8*, i8** %2
%28 = ptrtoint i8* %27 to i64
%29 = add i64 %28, 10
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %3
br label %46
31: ; preds = %1
%32 = load i8*, i8** %2
%33 = ptrtoint i8* %32 to i64
%34 = add i64 %33, 16
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %3
br label %46
36: ; preds = %1
%37 = load i8*, i8** %2
%38 = ptrtoint i8* %37 to i64
%39 = add i64 %38, 10
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %3
br label %46
41: ; preds = %1
%42 = load i8*, i8** %2
%43 = ptrtoint i8* %42 to i64
%44 = add i64 %43, 24
%45 = inttoptr i64 %44 to i8*
store i8* %45, i8** %3
br label %46
46: ; preds = %41, %36, %31, %26
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
@switch.table.get_sa = [3 x i64] [i64 10, i64 16, i64 10]
define i8* @get_sa(i8* %0) {
%2 = bitcast i8* %0 to i16*
%3 = load i16, i16* %2
%4 = tail call zeroext i16 @le16_to_cpu(i32 256)
%5 = and i16 %4, %3
%6 = icmp eq i16 %5, 0
%7 = select i1 %6, i32 0, i32 2
%8 = load i16, i16* %2
%9 = tail call zeroext i16 @le16_to_cpu(i32 512)
%10 = and i16 %9, %8
%11 = icmp ne i16 %10, 0
%12 = zext i1 %11 to i32
%13 = or i32 %7, %12
%14 = icmp eq i32 %13, 3
br i1 %14, label %19, label %15
15: ; preds = %1
%16 = zext i32 %13 to i64
%17 = getelementptr inbounds [3 x i64], [3 x i64]* @switch.table.get_sa, i64 0, i64 %16
%18 = load i64, i64* %17
br label %19
19: ; preds = %1, %15
%20 = phi i64 [ %18, %15 ], [ 24, %1 ]
%21 = ptrtoint i8* %0 to i64
%22 = add i64 %20, %21
%23 = inttoptr i64 %22 to i8*
ret i8* %23
}