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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int htonl(int);
int /*<<< orphan*/ stderr;
bool is_beacon(char *csp, size_t csp_len) {
  if (csp_len < 4) {
    return false;
  }
  uint32_t hdr = htonl(*(uint32_t *)csp) & 0x3fffc000U;
  fprintf(stderr, " -- 0x%08x -- \n", hdr);
  return hdr == 0x02a2c000U || hdr == 0;
}


x86 assembly (clang, -O0):
<is_beacon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x4,-0x18(%rbp)
jae    1147 <is_beacon+0x27>
movl   $0x0,-0x4(%rbp)
jmp    1199 <is_beacon+0x79>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
and    $0x3fffc000,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe93(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%al
cmpl   $0x2a2c000,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
je     118e <is_beacon+0x6e>
cmpl   $0x0,-0x1c(%rbp)
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_beacon>:
xor    %eax,%eax
cmp    $0x4,%rsi
jb     1163 <is_beacon+0x43>
push   %rbx
mov    (%rdi),%edi
call   1030 <htonl@plt>
mov    %eax,%ebx
and    $0x3fffc000,%ebx
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
cmp    $0x2a2c000,%ebx
sete   %al
test   %ebx,%ebx
sete   %cl
or     %al,%cl
movzbl %cl,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c" -- 0x%08x -- \0A\00"
define i32 @is_beacon(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 i64, i64* %5
%8 = icmp ult i64 %7, 4
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %27
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
%14 = call i32 @htonl(i32 %13)
%15 = and i32 %14, 1073725440
store i32 %15, i32* %6
%16 = load i32, i32* @stderr
%17 = load i32, i32* %6
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 44220416
br i1 %20, label %24, label %21
21: ; preds = %10
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br label %24
24: ; preds = %21, %10
%25 = phi i1 [ true, %10 ], [ %23, %21 ]
%26 = zext i1 %25 to i32
store i32 %26, i32* %3
br label %27
27: ; preds = %24, %9
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c" -- 0x%08x -- \0A\00"
define i32 @is_beacon(i8* nocapture %0, i64 %1) {
%3 = icmp ult i64 %1, 4
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = bitcast i8* %0 to i32*
%6 = load i32, i32* %5
%7 = tail call i32 @htonl(i32 %6)
%8 = and i32 %7, 1073725440
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %8)
%11 = icmp eq i32 %8, 44220416
%12 = icmp eq i32 %8, 0
%13 = or i1 %11, %12
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %2, %4
%16 = phi i32 [ %14, %4 ], [ 0, %2 ]
ret i32 %16
}