#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 sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ source;
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ receive_beacon(struct sockaddr_in *);
scalar_t__ recvfrom(int, unsigned char *, int, int /*<<< orphan*/,
                    struct sockaddr *, int *);
scalar_t__ strncmp(char *, char *, int);
void receive_beacons(int fd) {
  struct sockaddr_in source;
  socklen_t source_len;
  unsigned char data[32];
  ssize_t data_len;
  source_len = sizeof(source);
  data_len = recvfrom(fd, data, 32, 0, (struct sockaddr *)&source, &source_len);
  if (data_len > 0) {
    if (strncmp((char *)data, "UDPLOGGER BEACON", 32) == 0) {
      receive_beacon(&source);
    }
  }
}


x86 assembly (clang, -O0):
<receive_beacons>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x8(%rbp),%r8
mov    $0x20,%edx
xor    %ecx,%ecx
lea    -0xc(%rbp),%r9
call   1050 <recvfrom@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jle    1199 <receive_beacons+0x69>
lea    -0x30(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x20,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1194 <receive_beacons+0x64>
lea    -0x8(%rbp),%rdi
call   1040 <receive_beacon@plt>
jmp    1199 <receive_beacons+0x69>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_beacons>:
sub    $0x38,%rsp
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
mov    $0x20,%edx
xor    %ecx,%ecx
call   1050 <recvfrom@plt>
test   %rax,%rax
jle    1177 <receive_beacons+0x47>
lea    0xe9d(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x20,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     117c <receive_beacons+0x4c>
add    $0x38,%rsp
ret
lea    0x8(%rsp),%rdi
call   1040 <receive_beacon@plt>
add    $0x38,%rsp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"UDPLOGGER BEACON\00"
define void @receive_beacons(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = alloca i64
store i32 %0, i32* %2
store i32 4, i32* %4
%7 = load i32, i32* %2
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%10 = call i64 @recvfrom(i32 %7, i8* %8, i32 32, i32 0, %struct.sockaddr* %9, i32* %4)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %1
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 32)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @receive_beacon(%struct.sockaddr_in* %3)
br label %19
19: ; preds = %17, %13
br label %20
20: ; preds = %19, %1
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"UDPLOGGER BEACON\00"
define void @receive_beacons(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
store i32 4, i32* %3
%8 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%9 = call i64 @recvfrom(i32 %0, i8* %7, i32 32, i32 0, %struct.sockaddr* %8, i32* %3)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 32)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @receive_beacon(%struct.sockaddr_in* %2)
br label %16
16: ; preds = %11, %14, %1
ret void
}