#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*/ u_int16_t;
typedef int u_char;

/* Variables and functions */
int /*<<< orphan*/ dst_s_get_int16(int const *);
int /*<<< orphan*/ dst_s_id_calc(int const *, int const);
u_int16_t dst_s_dns_key_id(const u_char *dns_key_rdata, const int rdata_len) {
  if (!dns_key_rdata)
    return 0;
  if (dns_key_rdata[3] == 1)
    return dst_s_get_int16((const u_char *)&dns_key_rdata[rdata_len - 3]);
  else if (dns_key_rdata[3] == 157)
    return 0;
  else
    return dst_s_id_calc(dns_key_rdata, rdata_len);
}


x86 assembly (clang, -O0):
<dst_s_dns_key_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <dst_s_dns_key_id+0x26>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <dst_s_dns_key_id+0x80>
mov    -0x10(%rbp),%rax
cmpl   $0x1,0xc(%rax)
jne    1174 <dst_s_dns_key_id+0x54>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1040 <dst_s_get_int16@plt>
mov    %eax,-0x4(%rbp)
jmp    11a0 <dst_s_dns_key_id+0x80>
mov    -0x10(%rbp),%rax
cmpl   $0x9d,0xc(%rax)
jne    1191 <dst_s_dns_key_id+0x71>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <dst_s_dns_key_id+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <dst_s_id_calc@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dst_s_dns_key_id>:
test   %rdi,%rdi
je     1144 <dst_s_dns_key_id+0x24>
mov    0xc(%rdi),%eax
cmp    $0x9d,%eax
je     1144 <dst_s_dns_key_id+0x24>
cmp    $0x1,%eax
jne    1147 <dst_s_dns_key_id+0x27>
movslq %esi,%rax
lea    (%rdi,%rax,4),%rdi
add    $0xfffffffffffffff4,%rdi
jmp    1040 <dst_s_get_int16@plt>
xor    %eax,%eax
ret
jmp    1030 <dst_s_id_calc@plt>

LLVM IR (-O0):
define i32 @dst_s_dns_key_id(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32*, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
store i32 0, i32* %3
br label %31
9: ; preds = %2
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 3
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i32*, i32** %4
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %15, i64 %18
%20 = call i32 @dst_s_get_int16(i32* %19)
store i32 %20, i32* %3
br label %31
21: ; preds = %9
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 3
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 157
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 0, i32* %3
br label %31
27: ; preds = %21
%28 = load i32*, i32** %4
%29 = load i32, i32* %5
%30 = call i32 @dst_s_id_calc(i32* %28, i32 %29)
store i32 %30, i32* %3
br label %31
31: ; preds = %27, %26, %14, %8
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @dst_s_dns_key_id(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = getelementptr inbounds i32, i32* %0, i64 3
%6 = load i32, i32* %5
switch i32 %6, label %12 [
i32 1, label %7
i32 157, label %14
]
7: ; preds = %4
%8 = add nsw i32 %1, -3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = tail call i32 @dst_s_get_int16(i32* %10)
br label %14
12: ; preds = %4
%13 = tail call i32 @dst_s_id_calc(i32* %0, i32 %1)
br label %14
14: ; preds = %4, %2, %12, %7
%15 = phi i32 [ %11, %7 ], [ %13, %12 ], [ 0, %2 ], [ 0, %4 ]
ret i32 %15
}