#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*/ target;
struct in6_addr {
  int dummy;
};
struct sockaddr_in6 {
  int sin6_scope_id;
  scalar_t__ nd_rs_reserved;
  scalar_t__ nd_rs_cksum;
  scalar_t__ nd_rs_code;
  int /*<<< orphan*/ nd_rs_type;
  int /*<<< orphan*/ sin6_family;
  struct in6_addr sin6_addr;
};
struct sockaddr {
  int dummy;
};
struct nd_router_solicit {
  int sin6_scope_id;
  scalar_t__ nd_rs_reserved;
  scalar_t__ nd_rs_cksum;
  scalar_t__ nd_rs_code;
  int /*<<< orphan*/ nd_rs_type;
  int /*<<< orphan*/ sin6_family;
  struct in6_addr sin6_addr;
};
typedef int /*<<< orphan*/ rs;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ ND_ROUTER_SOLICIT;
int /*<<< orphan*/ memset(struct sockaddr_in6 *, int /*<<< orphan*/, int);
int sendto(int, struct sockaddr_in6 *, int, int /*<<< orphan*/,
           struct sockaddr const *, int);
int send_rdisc(int fd, int ifindex, struct in6_addr *addr) {
  struct sockaddr_in6 target;
  struct nd_router_solicit rs;
  if (ifindex == 0)
    return -1;
  memset(&target, 0, sizeof(target));
  memset(&rs, 0, sizeof(rs));
  target.sin6_addr = *addr;
  target.sin6_family = AF_INET6;
  target.sin6_scope_id = ifindex;
  rs.nd_rs_type = ND_ROUTER_SOLICIT;
  rs.nd_rs_code = 0;
  rs.nd_rs_cksum = 0;
  rs.nd_rs_reserved = 0;
  if (sendto(fd, &rs, sizeof(rs), 0, (const struct sockaddr *)&target,
             sizeof(target)) != sizeof(rs)) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<send_rdisc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    114b <send_rdisc+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <send_rdisc+0xc4>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
lea    -0x78(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x78(%rbp),%rsi
lea    -0x48(%rbp),%r8
mov    $0x30,%r9d
xor    %ecx,%ecx
mov    %r9d,%edx
call   1040 <sendto@plt>
cltq
cmp    $0x30,%rax
je     11dd <send_rdisc+0xbd>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <send_rdisc+0xc4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_rdisc>:
test   %esi,%esi
je     11cb <send_rdisc+0xab>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r15d
lea    0x30(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x58(%rsp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x54(%rsp)
mov    %ebp,0x30(%rsp)
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x30,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x30,%r9d
call   1040 <sendto@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
setne  %al
neg    %eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
%struct.sockaddr_in6 = type { i32, i64, i64, i64, i32, i32, %struct.in6_addr }
%struct.nd_router_solicit = type { i32, i64, i64, i64, i32, i32, %struct.in6_addr }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@ND_ROUTER_SOLICIT = global i32 0
define i32 @send_rdisc(i32 %0, i32 %1, %struct.in6_addr* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.in6_addr*
%8 = alloca %struct.sockaddr_in6
%9 = alloca %struct.nd_router_solicit
store i32 %0, i32* %5
store i32 %1, i32* %6
store %struct.in6_addr* %2, %struct.in6_addr** %7
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %38
13: ; preds = %3
%14 = call i32 @memset(%struct.sockaddr_in6* %8, i32 0, i32 48)
%15 = bitcast %struct.nd_router_solicit* %9 to %struct.sockaddr_in6*
%16 = call i32 @memset(%struct.sockaddr_in6* %15, i32 0, i32 48)
%17 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 6
%18 = load %struct.in6_addr*, %struct.in6_addr** %7
%19 = bitcast %struct.in6_addr* %17 to i8*
%20 = bitcast %struct.in6_addr* %18 to i8*
%21 = load i32, i32* @AF_INET6
%22 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 5
store i32 %21, i32* %22
%23 = load i32, i32* %6
%24 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %8, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @ND_ROUTER_SOLICIT
%26 = getelementptr inbounds %struct.nd_router_solicit, %struct.nd_router_solicit* %9, i32 0, i32 4
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.nd_router_solicit, %struct.nd_router_solicit* %9, i32 0, i32 3
store i64 0, i64* %27
%28 = getelementptr inbounds %struct.nd_router_solicit, %struct.nd_router_solicit* %9, i32 0, i32 2
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.nd_router_solicit, %struct.nd_router_solicit* %9, i32 0, i32 1
store i64 0, i64* %29
%30 = load i32, i32* %5
%31 = bitcast %struct.nd_router_solicit* %9 to %struct.sockaddr_in6*
%32 = bitcast %struct.sockaddr_in6* %8 to %struct.sockaddr*
%33 = call i32 @sendto(i32 %30, %struct.sockaddr_in6* %31, i32 48, i32 0, %struct.sockaddr* %32, i32 48)
%34 = sext i32 %33 to i64
%35 = icmp ne i64 %34, 48
br i1 %35, label %36, label %37
36: ; preds = %13
store i32 -1, i32* %4
br label %38
37: ; preds = %13
store i32 0, i32* %4
br label %38
38: ; preds = %37, %36, %12
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
%struct.sockaddr_in6 = type { i32, i64, i64, i64, i32, i32, %struct.in6_addr }
%struct.nd_router_solicit = type { i32, i64, i64, i64, i32, i32, %struct.in6_addr }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@ND_ROUTER_SOLICIT = global i32 0
define i32 @send_rdisc(i32 %0, i32 %1, %struct.in6_addr* nocapture %2) {
%4 = alloca %struct.sockaddr_in6
%5 = alloca %struct.nd_router_solicit
%6 = bitcast %struct.sockaddr_in6* %4 to i8*
%7 = bitcast %struct.nd_router_solicit* %5 to i8*
%8 = icmp eq i32 %1, 0
br i1 %8, label %27, label %9
9: ; preds = %3
%10 = call i32 @memset(%struct.sockaddr_in6* %4, i32 0, i32 48)
%11 = bitcast %struct.nd_router_solicit* %5 to %struct.sockaddr_in6*
%12 = call i32 @memset(%struct.sockaddr_in6* %11, i32 0, i32 48)
%13 = getelementptr %struct.in6_addr, %struct.in6_addr* %2, i64 0, i32 0
%14 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 6, i32 0
%15 = load i32, i32* %13
store i32 %15, i32* %14
%16 = load i32, i32* @AF_INET6
%17 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 5
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i64 0, i32 0
store i32 %1, i32* %18
%19 = load i32, i32* @ND_ROUTER_SOLICIT
%20 = getelementptr inbounds %struct.nd_router_solicit, %struct.nd_router_solicit* %5, i64 0, i32 4
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.nd_router_solicit, %struct.nd_router_solicit* %5, i64 0, i32 1
%22 = bitcast %struct.sockaddr_in6* %4 to %struct.sockaddr*
%23 = bitcast i64* %21 to i8*
%24 = call i32 @sendto(i32 %0, %struct.sockaddr_in6* %11, i32 48, i32 0, %struct.sockaddr* %22, i32 48)
%25 = icmp ne i32 %24, 48
%26 = sext i1 %25 to i32
br label %27
27: ; preds = %9, %3
%28 = phi i32 [ -1, %3 ], [ %26, %9 ]
ret i32 %28
}