#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*/ uint8_t;
struct in6_addr {
  int dummy;
};
struct icmp6_hdr {
  void *icmp6_seq;
  void *icmp6_id;
  int /*<<< orphan*/ icmp6_type;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ ICMP6_ECHO_REQUEST;
unsigned short getpid();
void *htons(unsigned short);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, struct in6_addr *);
int /*<<< orphan*/ memset(struct icmp6_hdr *, int /*<<< orphan*/, int);
int send_probe(int, int /*<<< orphan*/ *, struct in6_addr *, int, int);
int send_echo_query(int sock, uint8_t *buf) {
  static unsigned short seq = 1;
  int err;
  struct in6_addr addr;
  inet_pton(AF_INET6, "ff02::01", &addr);
  struct icmp6_hdr *req;
  req = (struct icmp6_hdr *)buf;
  memset(req, 0, sizeof(struct icmp6_hdr));
  req->icmp6_type = ICMP6_ECHO_REQUEST;
  req->icmp6_id = htons(getpid());
  req->icmp6_seq = htons(seq);
  if (seq == 65535)
    seq = 1;
  else
    seq++;
  uint8_t *p = (uint8_t *)buf + sizeof(struct icmp6_hdr);
  err = send_probe(sock, buf, &addr, p - buf, 255);
  return err;
}


x86 assembly (clang, -O0):
<send_echo_query>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <inet_pton@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    $0x0,%al
call   1030 <getpid@plt>
movzwl %ax,%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
movzwl 0x2e87(%rip),%edi
call   1040 <htons@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movzwl 0x2e71(%rip),%eax
cmp    $0xffff,%eax
jne    11f0 <send_echo_query+0xa0>
movw   $0x1,0x2e5d(%rip)
jmp    1202 <send_echo_query+0xb2>
mov    0x2e51(%rip),%ax
add    $0x1,%ax
mov    %ax,0x2e46(%rip)
mov    -0x10(%rbp),%rax
add    $0x60,%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,%ecx
lea    -0x18(%rbp),%rdx
mov    $0xff,%r8d
call   1070 <send_probe@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_echo_query>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
lea    0x8(%rsp),%r14
mov    %r14,%rdx
call   1060 <inet_pton@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbx)
xor    %eax,%eax
call   1030 <getpid@plt>
movzwl %ax,%edi
call   1040 <htons@plt>
mov    %rax,0x8(%rbx)
movzwl 0x2e99(%rip),%edi
call   1040 <htons@plt>
mov    %rax,(%rbx)
movzwl 0x2e8a(%rip),%eax
inc    %ax
mov    $0x1,%ecx
cmovne %eax,%ecx
mov    %cx,0x2e78(%rip)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    $0x18,%ecx
mov    $0xff,%r8d
call   1070 <send_probe@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
%struct.icmp6_hdr = type { i8*, i8*, i32 }
@send_echo_query.seq = internal global i16 1
@AF_INET6 = global i32 0
@.str = [9 x i8] c"ff02::01\00"
@ICMP6_ECHO_REQUEST = global i32 0
define i32 @send_echo_query(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.in6_addr
%7 = alloca %struct.icmp6_hdr*
%8 = alloca i32*
store i32 %0, i32* %3
store i32* %1, i32** %4
%9 = load i32, i32* @AF_INET6
%10 = call i32 @inet_pton(i32 %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.in6_addr* %6)
%11 = load i32*, i32** %4
%12 = bitcast i32* %11 to %struct.icmp6_hdr*
store %struct.icmp6_hdr* %12, %struct.icmp6_hdr** %7
%13 = load %struct.icmp6_hdr*, %struct.icmp6_hdr** %7
%14 = call i32 @memset(%struct.icmp6_hdr* %13, i32 0, i32 24)
%15 = load i32, i32* @ICMP6_ECHO_REQUEST
%16 = load %struct.icmp6_hdr*, %struct.icmp6_hdr** %7
%17 = getelementptr inbounds %struct.icmp6_hdr, %struct.icmp6_hdr* %16, i32 0, i32 2
store i32 %15, i32* %17
%18 = call zeroext i16 (...) @getpid()
%19 = call i8* @htons(i16 zeroext %18)
%20 = load %struct.icmp6_hdr*, %struct.icmp6_hdr** %7
%21 = getelementptr inbounds %struct.icmp6_hdr, %struct.icmp6_hdr* %20, i32 0, i32 1
store i8* %19, i8** %21
%22 = load i16, i16* @send_echo_query.seq
%23 = call i8* @htons(i16 zeroext %22)
%24 = load %struct.icmp6_hdr*, %struct.icmp6_hdr** %7
%25 = getelementptr inbounds %struct.icmp6_hdr, %struct.icmp6_hdr* %24, i32 0, i32 0
store i8* %23, i8** %25
%26 = load i16, i16* @send_echo_query.seq
%27 = zext i16 %26 to i32
%28 = icmp eq i32 %27, 65535
br i1 %28, label %29, label %30
29: ; preds = %2
store i16 1, i16* @send_echo_query.seq
br label %33
30: ; preds = %2
%31 = load i16, i16* @send_echo_query.seq
%32 = add i16 %31, 1
store i16 %32, i16* @send_echo_query.seq
br label %33
33: ; preds = %30, %29
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 24
store i32* %35, i32** %8
%36 = load i32, i32* %3
%37 = load i32*, i32** %4
%38 = load i32*, i32** %8
%39 = load i32*, i32** %4
%40 = ptrtoint i32* %38 to i64
%41 = ptrtoint i32* %39 to i64
%42 = sub i64 %40, %41
%43 = sdiv exact i64 %42, 4
%44 = trunc i64 %43 to i32
%45 = call i32 @send_probe(i32 %36, i32* %37, %struct.in6_addr* %6, i32 %44, i32 255)
store i32 %45, i32* %5
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
%struct.icmp6_hdr = type { i8*, i8*, i32 }
@send_echo_query.seq = internal unnamed_addr global i16 1
@AF_INET6 = global i32 0
@.str = [9 x i8] c"ff02::01\00"
@ICMP6_ECHO_REQUEST = global i32 0
define i32 @send_echo_query(i32 %0, i32* %1) {
%3 = alloca %struct.in6_addr
%4 = bitcast %struct.in6_addr* %3 to i8*
%5 = load i32, i32* @AF_INET6
%6 = call i32 @inet_pton(i32 %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.in6_addr* %3)
%7 = bitcast i32* %1 to %struct.icmp6_hdr*
%8 = call i32 @memset(%struct.icmp6_hdr* %7, i32 0, i32 24)
%9 = load i32, i32* @ICMP6_ECHO_REQUEST
%10 = getelementptr inbounds i32, i32* %1, i64 4
store i32 %9, i32* %10
%11 = call zeroext i16 (...) @getpid()
%12 = call i8* @htons(i16 zeroext %11)
%13 = getelementptr inbounds i32, i32* %1, i64 2
%14 = bitcast i32* %13 to i8**
store i8* %12, i8** %14
%15 = load i16, i16* @send_echo_query.seq
%16 = call i8* @htons(i16 zeroext %15)
%17 = bitcast i32* %1 to i8**
store i8* %16, i8** %17
%18 = load i16, i16* @send_echo_query.seq
%19 = icmp eq i16 %18, -1
%20 = add i16 %18, 1
%21 = select i1 %19, i16 1, i16 %20
store i16 %21, i16* @send_echo_query.seq
%22 = call i32 @send_probe(i32 %0, i32* %1, %struct.in6_addr* %3, i32 24, i32 255)
ret i32 %22
}