#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 int socklen_t;
typedef int /*<<< orphan*/ pkt;

/* Variables and functions */
int /*<<< orphan*/ lssdp_process_packet(int, struct sockaddr *, char *, size_t);
int /*<<< orphan*/ memset(char *, char, int);
size_t recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int bee_ssdp_handler(int sock) {
  struct sockaddr_in sender;
  socklen_t sender_len;
  char pkt[1024];
  size_t pkt_len;
  memset(pkt, '\0', sizeof(pkt));
  sender_len = sizeof(struct sockaddr_in);
  pkt_len = recvfrom(sock, pkt, sizeof(pkt), 0, (struct sockaddr *)&sender,
                     &sender_len);
  if (pkt_len > 0) {
    lssdp_process_packet(sock, (struct sockaddr *)&sender, pkt, pkt_len);
  }
  return 0;
}


x86 assembly (clang, -O0):
<bee_ssdp_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
movl   $0x4,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
lea    -0x8(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0xc(%rbp),%r9
call   1050 <recvfrom@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jbe    11a5 <bee_ssdp_handler+0x75>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0x410(%rbp),%rdx
mov    -0x418(%rbp),%rcx
call   1030 <lssdp_process_packet@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bee_ssdp_handler>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %edi,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
movl   $0x4,0xc(%rsp)
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1050 <recvfrom@plt>
test   %rax,%rax
je     118c <bee_ssdp_handler+0x5c>
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1030 <lssdp_process_packet@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @bee_ssdp_handler(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i64
store i32 %0, i32* %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i8 signext 0, i32 1024)
store i32 4, i32* %4
%9 = load i32, i32* %2
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%12 = call i64 @recvfrom(i32 %9, i8* %10, i32 1024, i32 0, %struct.sockaddr* %11, i32* %4)
store i64 %12, i64* %6
%13 = load i64, i64* %6
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %1
%16 = load i32, i32* %2
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = load i64, i64* %6
%20 = call i32 @lssdp_process_packet(i32 %16, %struct.sockaddr* %17, i8* %18, i64 %19)
br label %21
21: ; preds = %15, %1
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @bee_ssdp_handler(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i8 signext 0, i32 1024)
store i32 4, i32* %3
%9 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%10 = call i64 @recvfrom(i32 %0, i8* %7, i32 1024, i32 0, %struct.sockaddr* %9, i32* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = call i32 @lssdp_process_packet(i32 %0, %struct.sockaddr* %9, i8* %7, i64 %10)
br label %14
14: ; preds = %12, %1
ret i32 0
}