#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 sockaddr_in6 {
  int iov_len;
  int msg_namelen;
  int msg_iovlen;
  scalar_t__ msg_controllen;
  int /*<<< orphan*/ *msg_control;
  struct sockaddr_in6 *msg_iov;
  struct sockaddr_in6 *msg_name;
  int /*<<< orphan*/ *iov_base;
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
};
struct msghdr {
  int iov_len;
  int msg_namelen;
  int msg_iovlen;
  scalar_t__ msg_controllen;
  int /*<<< orphan*/ *msg_control;
  struct msghdr *msg_iov;
  struct msghdr *msg_name;
  int /*<<< orphan*/ *iov_base;
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
};
struct iovec {
  int iov_len;
  int msg_namelen;
  int msg_iovlen;
  scalar_t__ msg_controllen;
  int /*<<< orphan*/ *msg_control;
  struct iovec *msg_iov;
  struct iovec *msg_name;
  int /*<<< orphan*/ *iov_base;
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
};
struct in6_addr {
  int dummy;
};
typedef int /*<<< orphan*/ str;
typedef int socklen_t;
typedef int /*<<< orphan*/ mhdr;
typedef int /*<<< orphan*/ iov;
typedef int /*<<< orphan*/ hoplimit;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ IPPROTO_ICMPV6;
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_MULTICAST_HOPS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, struct in6_addr *, char *,
                             int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, struct in6_addr *, int);
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int sendmsg(int, struct sockaddr_in6 *, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int send_probe(int sock, uint8_t *buf, struct in6_addr *addr, int len,
               int set_hop) {
  struct sockaddr_in6 whereto;
  memset(&whereto, 0, sizeof(struct sockaddr_in6));
  whereto.sin6_family = AF_INET6;
  whereto.sin6_port = htons(IPPROTO_ICMPV6);
  memcpy(&whereto.sin6_addr, addr, sizeof(struct in6_addr));
  if (set_hop) {
    int hoplimit;
    socklen_t hlen = sizeof(hoplimit);
    hoplimit = set_hop;
    setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hoplimit, hlen);
  }
  int cc;
  struct msghdr mhdr;
  struct iovec iov;
  memset(&iov, 0, sizeof(iov));
  memset(&mhdr, 0, sizeof(mhdr));
  iov.iov_len = len;
  iov.iov_base = buf;
  mhdr.msg_name = &whereto;
  mhdr.msg_namelen = sizeof(struct sockaddr_in6);
  mhdr.msg_iov = &iov;
  mhdr.msg_iovlen = 1;
  mhdr.msg_control = NULL;
  mhdr.msg_controllen = 0;
  cc = sendmsg(sock, &mhdr, 0);
  if (cc < 0) {
    static char str[128];
    inet_ntop(AF_INET6, addr, str, sizeof(str));
    fprintf(stderr, "sendmsg to %s: %s\n", str, strerror(errno));
  }
  return (cc == len ? 0 : cc);
}


x86 assembly (clang, -O0):
<send_probe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
lea    -0x68(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1070 <memset@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x68(%rbp),%rdi
add    $0x38,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
cmpl   $0x0,-0x20(%rbp)
je     1219 <send_probe+0x99>
movl   $0x4,-0x70(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
mov    -0x70(%rbp),%r8d
lea    -0x6c(%rbp),%rcx
call   1050 <setsockopt@plt>
lea    -0x108(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1070 <memset@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1070 <memset@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x108(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x68(%rbp),%rax
mov    %rax,-0x98(%rbp)
movl   $0x48,-0xbc(%rbp)
lea    -0x108(%rbp),%rax
mov    %rax,-0xa0(%rbp)
movl   $0x1,-0xb8(%rbp)
movq   $0x0,-0xa8(%rbp)
movq   $0x0,-0xb0(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xc0(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jge    130b <send_probe+0x18b>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    0x2db8(%rip),%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10c(%rbp)
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x10c(%rbp),%edi
mov    %rax,%rcx
lea    0xd01(%rip),%rsi
lea    0x2d7a(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x74(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1324 <send_probe+0x1a4>
xor    %eax,%eax
mov    %eax,-0x110(%rbp)
jmp    132d <send_probe+0x1ad>
mov    -0x74(%rbp),%eax
mov    %eax,-0x110(%rbp)
mov    -0x110(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_probe>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %r8d,%ebx
mov    %ecx,0xc(%rsp)
mov    %rdx,%rbp
mov    %rsi,0x18(%rsp)
mov    %edi,%r15d
lea    0x68(%rsp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1070 <memset@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xa8(%rsp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1060 <htons@plt>
mov    %eax,0xa4(%rsp)
lea    0xa0(%rsp),%rdi
mov    %rbp,0x10(%rsp)
mov    %rbp,%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
test   %ebx,%ebx
je     1220 <send_probe+0xa0>
mov    %ebx,0x20(%rsp)
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
mov    0x2db5(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
lea    0xb0(%rsp),%r12
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1070 <memset@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1070 <memset@plt>
mov    0xc(%rsp),%r13d
mov    %r13d,0xb0(%rsp)
mov    0x18(%rsp),%rax
mov    %rax,0xe0(%rsp)
lea    0x68(%rsp),%rax
mov    %rax,0x48(%rsp)
movabs $0x100000048,%rax
mov    %rax,0x24(%rsp)
mov    %r12,0x40(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x30(%rsp)
mov    %r15d,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12ef <send_probe+0x16f>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0x2dd0(%rip),%r14
mov    0x10(%rsp),%rsi
mov    %r14,%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%r12d
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd1f(%rip),%rsi
mov    %r12d,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1080 <fprintf@plt>
cmp    %r13d,%ebp
cmovne %ebp,%ebx
mov    %ebx,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
%struct.sockaddr_in6 = type { i32, i32, i32, i64, i32*, %struct.sockaddr_in6*, %struct.sockaddr_in6*, i32*, i32, i32, i32 }
%struct.msghdr = type { i32, i32, i32, i64, i32*, %struct.msghdr*, %struct.msghdr*, i32*, i32, i32, i32 }
%struct.iovec = type { i32, i32, i32, i64, i32*, %struct.iovec*, %struct.iovec*, i32*, i32, i32, i32 }
@AF_INET6 = global i32 0
@IPPROTO_ICMPV6 = global i32 0
@IPPROTO_IPV6 = global i32 0
@IPV6_MULTICAST_HOPS = global i32 0
@send_probe.str = internal global [128 x i8] zeroinitializer
@stderr = global i32 0
@.str = [19 x i8] c"sendmsg to %s: %s\0A\00"
@errno = global i32 0
define i32 @send_probe(i32 %0, i32* %1, %struct.in6_addr* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.in6_addr*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in6
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.msghdr
%16 = alloca %struct.iovec
store i32 %0, i32* %6
store i32* %1, i32** %7
store %struct.in6_addr* %2, %struct.in6_addr** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%17 = call i32 @memset(%struct.sockaddr_in6* %11, i32 0, i32 72)
%18 = load i32, i32* @AF_INET6
%19 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 10
store i32 %18, i32* %19
%20 = load i32, i32* @IPPROTO_ICMPV6
%21 = call i32 @htons(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 9
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %11, i32 0, i32 8
%24 = load %struct.in6_addr*, %struct.in6_addr** %8
%25 = call i32 @memcpy(i32* %23, %struct.in6_addr* %24, i32 4)
%26 = load i32, i32* %10
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %5
store i32 4, i32* %13
%29 = load i32, i32* %10
store i32 %29, i32* %12
%30 = load i32, i32* %6
%31 = load i32, i32* @IPPROTO_IPV6
%32 = load i32, i32* @IPV6_MULTICAST_HOPS
%33 = load i32, i32* %13
%34 = call i32 @setsockopt(i32 %30, i32 %31, i32 %32, i32* %12, i32 %33)
br label %35
35: ; preds = %28, %5
%36 = bitcast %struct.iovec* %16 to %struct.sockaddr_in6*
%37 = call i32 @memset(%struct.sockaddr_in6* %36, i32 0, i32 72)
%38 = bitcast %struct.msghdr* %15 to %struct.sockaddr_in6*
%39 = call i32 @memset(%struct.sockaddr_in6* %38, i32 0, i32 72)
%40 = load i32, i32* %9
%41 = getelementptr inbounds %struct.iovec, %struct.iovec* %16, i32 0, i32 0
store i32 %40, i32* %41
%42 = load i32*, i32** %7
%43 = getelementptr inbounds %struct.iovec, %struct.iovec* %16, i32 0, i32 7
store i32* %42, i32** %43
%44 = bitcast %struct.sockaddr_in6* %11 to %struct.msghdr*
%45 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 6
store %struct.msghdr* %44, %struct.msghdr** %45
%46 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 1
store i32 72, i32* %46
%47 = bitcast %struct.iovec* %16 to %struct.msghdr*
%48 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 5
store %struct.msghdr* %47, %struct.msghdr** %48
%49 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 2
store i32 1, i32* %49
%50 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 4
store i32* null, i32** %50
%51 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %15, i32 0, i32 3
store i64 0, i64* %51
%52 = load i32, i32* %6
%53 = bitcast %struct.msghdr* %15 to %struct.sockaddr_in6*
%54 = call i32 @sendmsg(i32 %52, %struct.sockaddr_in6* %53, i32 0)
store i32 %54, i32* %14
%55 = load i32, i32* %14
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %35
%58 = load i32, i32* @AF_INET6
%59 = load %struct.in6_addr*, %struct.in6_addr** %8
%60 = call i32 @inet_ntop(i32 %58, %struct.in6_addr* %59, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @send_probe.str, i64 0, i64 0), i32 128)
%61 = load i32, i32* @stderr
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([128 x i8], [128 x i8]* @send_probe.str, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %57, %35
%66 = load i32, i32* %14
%67 = load i32, i32* %9
%68 = icmp eq i32 %66, %67
br i1 %68, label %69, label %70
69: ; preds = %65
br label %72
70: ; preds = %65
%71 = load i32, i32* %14
br label %72
72: ; preds = %70, %69
%73 = phi i32 [ 0, %69 ], [ %71, %70 ]
ret i32 %73
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
%struct.sockaddr_in6 = type { i32, i32, i32, i64, i32*, %struct.sockaddr_in6*, %struct.sockaddr_in6*, i32*, i32, i32, i32 }
%struct.msghdr = type { i32, i32, i32, i64, i32*, %struct.msghdr*, %struct.msghdr*, i32*, i32, i32, i32 }
%struct.iovec = type { i32, i32, i32, i64, i32*, %struct.iovec*, %struct.iovec*, i32*, i32, i32, i32 }
@AF_INET6 = global i32 0
@IPPROTO_ICMPV6 = global i32 0
@IPPROTO_IPV6 = global i32 0
@IPV6_MULTICAST_HOPS = global i32 0
@send_probe.str = internal global [128 x i8] zeroinitializer
@stderr = global i32 0
@.str = [19 x i8] c"sendmsg to %s: %s\0A\00"
@errno = global i32 0
define i32 @send_probe(i32 %0, i32* %1, %struct.in6_addr* %2, i32 %3, i32 %4) {
%6 = alloca %struct.sockaddr_in6
%7 = alloca i32
%8 = alloca %struct.msghdr
%9 = alloca %struct.iovec
%10 = bitcast %struct.sockaddr_in6* %6 to i8*
%11 = call i32 @memset(%struct.sockaddr_in6* %6, i32 0, i32 72)
%12 = load i32, i32* @AF_INET6
%13 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %6, i64 0, i32 10
store i32 %12, i32* %13
%14 = load i32, i32* @IPPROTO_ICMPV6
%15 = call i32 @htons(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %6, i64 0, i32 9
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %6, i64 0, i32 8
%18 = call i32 @memcpy(i32* %17, %struct.in6_addr* %2, i32 4)
%19 = icmp eq i32 %4, 0
br i1 %19, label %25, label %20
20: ; preds = %5
%21 = bitcast i32* %7 to i8*
store i32 %4, i32* %7
%22 = load i32, i32* @IPPROTO_IPV6
%23 = load i32, i32* @IPV6_MULTICAST_HOPS
%24 = call i32 @setsockopt(i32 %0, i32 %22, i32 %23, i32* %7, i32 4)
br label %25
25: ; preds = %20, %5
%26 = bitcast %struct.msghdr* %8 to i8*
%27 = bitcast %struct.iovec* %9 to i8*
%28 = bitcast %struct.iovec* %9 to %struct.sockaddr_in6*
%29 = call i32 @memset(%struct.sockaddr_in6* %28, i32 0, i32 72)
%30 = bitcast %struct.msghdr* %8 to %struct.sockaddr_in6*
%31 = call i32 @memset(%struct.sockaddr_in6* %30, i32 0, i32 72)
%32 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i64 0, i32 0
store i32 %3, i32* %32
%33 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i64 0, i32 7
store i32* %1, i32** %33
%34 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i64 0, i32 6
%35 = bitcast %struct.msghdr** %34 to %struct.sockaddr_in6**
store %struct.sockaddr_in6* %6, %struct.sockaddr_in6** %35
%36 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i64 0, i32 1
store i32 72, i32* %36
%37 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i64 0, i32 5
%38 = bitcast %struct.msghdr** %37 to %struct.iovec**
store %struct.iovec* %9, %struct.iovec** %38
%39 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i64 0, i32 2
store i32 1, i32* %39
%40 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i64 0, i32 3
%41 = bitcast i64* %40 to i8*
%42 = call i32 @sendmsg(i32 %0, %struct.sockaddr_in6* %30, i32 0)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %25
%45 = load i32, i32* @AF_INET6
%46 = call i32 @inet_ntop(i32 %45, %struct.in6_addr* %2, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @send_probe.str, i64 0, i64 0), i32 128)
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([128 x i8], [128 x i8]* @send_probe.str, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %44, %25
%52 = icmp eq i32 %42, %3
%53 = select i1 %52, i32 0, i32 %42
ret i32 %53
}