#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  scalar_t__ sin_family;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sendto(int, void const *, size_t, int /*<<< orphan*/,
                          struct sockaddr *, int);
ssize_t send_packet(int fd, const void *data, size_t len) {
  static struct sockaddr_in toaddr;
  if (toaddr.sin_family != AF_INET) {
    memset(&toaddr, 0, sizeof(struct sockaddr_in));
    toaddr.sin_family = AF_INET;
    toaddr.sin_port = htons(5353);
    toaddr.sin_addr.s_addr = inet_addr("224.0.0.251");
  }
  return sendto(fd, data, len, 0, (struct sockaddr *)&toaddr,
                sizeof(struct sockaddr_in));
}


x86 assembly (clang, -O0):
<send_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2eee(%rip),%rax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%rax
je     11b0 <send_packet+0x70>
lea    0x2ed7(%rip),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x2eba(%rip)
mov    $0x14e9,%edi
call   1030 <htons@plt>
mov    %eax,0x2eb6(%rip)
lea    0xe5b(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x2ea0(%rip)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
lea    0x2e84(%rip),%r8
mov    $0x10,%r9d
call   1050 <sendto@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_packet>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ef2(%rip),%rax
mov    0x2e8b(%rip),%r15
cmp    (%r15),%rax
je     11a1 <send_packet+0x61>
lea    0x2edf(%rip),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x2ec9(%rip)
mov    $0x14e9,%edi
call   1030 <htons@plt>
mov    %eax,0x2ec5(%rip)
lea    0xe6a(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x2eaf(%rip)
lea    0x2ea0(%rip),%r8
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    $0x10,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sendto@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i64, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@send_packet.toaddr = internal global %struct.sockaddr_in zeroinitializer
@AF_INET = global i64 0
@.str = [12 x i8] c"224.0.0.251\00"
define i32 @send_packet(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i64, i64* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @send_packet.toaddr, i32 0, i32 0)
%8 = load i64, i64* @AF_INET
%9 = icmp ne i64 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = call i32 @memset(%struct.sockaddr_in* @send_packet.toaddr, i32 0, i32 16)
%12 = load i64, i64* @AF_INET
store i64 %12, i64* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @send_packet.toaddr, i32 0, i32 0)
%13 = call i32 @htons(i32 5353)
store i32 %13, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @send_packet.toaddr, i32 0, i32 2)
%14 = call i32 @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @send_packet.toaddr, i32 0, i32 1, i32 0)
br label %15
15: ; preds = %10, %3
%16 = load i32, i32* %4
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = call i32 @sendto(i32 %16, i8* %17, i64 %18, i32 0, %struct.sockaddr* bitcast (%struct.sockaddr_in* @send_packet.toaddr to %struct.sockaddr*), i32 16)
ret i32 %19
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i64, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@send_packet.toaddr = internal global %struct.sockaddr_in zeroinitializer
@AF_INET = global i64 0
@.str = [12 x i8] c"224.0.0.251\00"
define i32 @send_packet(i32 %0, i8* %1, i64 %2) {
%4 = load i64, i64* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @send_packet.toaddr, i64 0, i32 0)
%5 = load i64, i64* @AF_INET
%6 = icmp eq i64 %4, %5
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = tail call i32 @memset(%struct.sockaddr_in* @send_packet.toaddr, i32 0, i32 16)
%9 = load i64, i64* @AF_INET
store i64 %9, i64* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @send_packet.toaddr, i64 0, i32 0)
%10 = tail call i32 @htons(i32 5353)
store i32 %10, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @send_packet.toaddr, i64 0, i32 2)
%11 = tail call i32 @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @send_packet.toaddr, i64 0, i32 1, i32 0)
br label %12
12: ; preds = %7, %3
%13 = tail call i32 @sendto(i32 %0, i8* %1, i64 %2, i32 0, %struct.sockaddr* bitcast (%struct.sockaddr_in* @send_packet.toaddr to %struct.sockaddr*), i32 16)
ret i32 %13
}