#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 trllc {
  int dummy;
};
struct trh_hdr {
  int *saddr;
  int /*<<< orphan*/ rcf;
};

/* Variables and functions */
int TR_MAXRIFLEN;
int TR_RCF_LEN_MASK;
int TR_RII;
int ntohs(int /*<<< orphan*/);
unsigned int get_tr_ip_offset(unsigned char *pkt) {
  struct trh_hdr *trh;
  unsigned int riflen = 0;
  trh = (struct trh_hdr *)pkt;
  if (trh->saddr[0] & TR_RII)
    riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
  return sizeof(struct trh_hdr) - TR_MAXRIFLEN + riflen + sizeof(struct trllc);
}


x86 assembly (clang, -O0):
<get_tr_ip_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    0x2e9d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1161 <get_tr_ip_offset+0x51>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1030 <ntohs@plt>
mov    0x2e8f(%rip),%rcx
and    (%rcx),%eax
sar    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    0x2e78(%rip),%rax
movslq (%rax),%rcx
mov    $0x10,%eax
sub    %rcx,%rax
mov    -0x14(%rbp),%ecx
add    %rcx,%rax
add    $0x4,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tr_ip_offset>:
push   %rax
mov    (%rdi),%rax
mov    0x2ebd(%rip),%rcx
mov    (%rcx),%ecx
test   %ecx,(%rax)
je     113a <get_tr_ip_offset+0x2a>
mov    0x8(%rdi),%edi
call   1030 <ntohs@plt>
mov    0x2eb8(%rip),%rcx
and    (%rcx),%eax
sar    $0x8,%eax
add    $0x14,%eax
jmp    113f <get_tr_ip_offset+0x2f>
mov    $0x14,%eax
mov    0x2e9a(%rip),%rcx
sub    (%rcx),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.trh_hdr = type { i32*, i32 }
@TR_RII = global i32 0
@TR_RCF_LEN_MASK = global i32 0
@TR_MAXRIFLEN = global i32 0
define i32 @get_tr_ip_offset(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.trh_hdr*
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to %struct.trh_hdr*
store %struct.trh_hdr* %6, %struct.trh_hdr** %3
%7 = load %struct.trh_hdr*, %struct.trh_hdr** %3
%8 = getelementptr inbounds %struct.trh_hdr, %struct.trh_hdr* %7, i32 0, i32 0
%9 = load i32*, i32** %8
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = load i32, i32* @TR_RII
%13 = and i32 %11, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %1
%16 = load %struct.trh_hdr*, %struct.trh_hdr** %3
%17 = getelementptr inbounds %struct.trh_hdr, %struct.trh_hdr* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 @ntohs(i32 %18)
%20 = load i32, i32* @TR_RCF_LEN_MASK
%21 = and i32 %19, %20
%22 = ashr i32 %21, 8
store i32 %22, i32* %4
br label %23
23: ; preds = %15, %1
%24 = load i32, i32* @TR_MAXRIFLEN
%25 = sext i32 %24 to i64
%26 = sub i64 16, %25
%27 = load i32, i32* %4
%28 = zext i32 %27 to i64
%29 = add i64 %26, %28
%30 = add i64 %29, 4
%31 = trunc i64 %30 to i32
ret i32 %31
}

LLVM IR (-O2):
@TR_RII = global i32 0
@TR_RCF_LEN_MASK = global i32 0
@TR_MAXRIFLEN = global i32 0
define i32 @get_tr_ip_offset(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32**
%3 = load i32*, i32** %2
%4 = load i32, i32* %3
%5 = load i32, i32* @TR_RII
%6 = and i32 %5, %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %1
%9 = getelementptr inbounds i8, i8* %0, i64 8
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
%12 = tail call i32 @ntohs(i32 %11)
%13 = load i32, i32* @TR_RCF_LEN_MASK
%14 = and i32 %13, %12
%15 = ashr i32 %14, 8
%16 = add nsw i32 %15, 20
br label %17
17: ; preds = %8, %1
%18 = phi i32 [ %16, %8 ], [ 20, %1 ]
%19 = load i32, i32* @TR_MAXRIFLEN
%20 = sub i32 %18, %19
ret i32 %20
}