#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 uint8_t;
struct sockaddr_in6 {
  int sin6_addr;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
};
struct in6_addr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ aeron_set_err(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(int *, int *, size_t);
int aeron_ipv6_multicast_control_address(struct sockaddr_in6 *data_addr,
                                         struct sockaddr_in6 *control_addr) {
  uint8_t bytes[sizeof(struct in6_addr)];
  size_t addr_len = sizeof(struct in6_addr);
  size_t last_byte_index = addr_len - 1;
  memcpy(bytes, &(data_addr->sin6_addr), addr_len);
  if ((bytes[last_byte_index] & 0x1) == 0) {
    aeron_set_err(EINVAL, "%s", "Multicast data address must be odd");
    return -1;
  }
  bytes[last_byte_index]++;
  control_addr->sin6_family = data_addr->sin6_family;
  memcpy(&(control_addr->sin6_addr), bytes, addr_len);
  control_addr->sin6_port = data_addr->sin6_port;
  return 0;
}


x86 assembly (clang, -O0):
<aeron_ipv6_multicast_control_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x4,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1191 <aeron_ipv6_multicast_control_address+0x71>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
lea    0xe83(%rip),%rdx
call   1030 <aeron_set_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <aeron_ipv6_multicast_control_address+0xb4>
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aeron_ipv6_multicast_control_address>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x4,%edx
mov    %rbx,%rsi
call   1040 <memcpy@plt>
mov    0xc(%rsp),%eax
test   $0x1,%al
jne    1168 <aeron_ipv6_multicast_control_address+0x48>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
lea    0xea7(%rip),%rdx
call   1030 <aeron_set_err@plt>
mov    $0xffffffff,%eax
jmp    118f <aeron_ipv6_multicast_control_address+0x6f>
add    $0x1,%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rbx),%eax
mov    %eax,0x8(%r14)
mov    %rsp,%rsi
mov    $0x4,%edx
mov    %r14,%rdi
call   1040 <memcpy@plt>
mov    0x4(%rbx),%eax
mov    %eax,0x4(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32, i32 }
@EINVAL = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [35 x i8] c"Multicast data address must be odd\00"
define i32 @aeron_ipv6_multicast_control_address(%struct.sockaddr_in6* %0, %struct.sockaddr_in6* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in6*
%5 = alloca %struct.sockaddr_in6*
%6 = alloca [4 x i32]
%7 = alloca i64
%8 = alloca i64
store %struct.sockaddr_in6* %0, %struct.sockaddr_in6** %4
store %struct.sockaddr_in6* %1, %struct.sockaddr_in6** %5
store i64 4, i64* %7
%9 = load i64, i64* %7
%10 = sub i64 %9, 1
store i64 %10, i64* %8
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%12 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %4
%13 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %12, i32 0, i32 0
%14 = load i64, i64* %7
%15 = call i32 @memcpy(i32* %11, i32* %13, i64 %14)
%16 = load i64, i64* %8
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = and i32 %18, 1
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i32, i32* @EINVAL
%23 = call i32 @aeron_set_err(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %44
24: ; preds = %2
%25 = load i64, i64* %8
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
%29 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %4
%30 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %29, i32 0, i32 2
%31 = load i32, i32* %30
%32 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %5
%33 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %32, i32 0, i32 2
store i32 %31, i32* %33
%34 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %5
%35 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %34, i32 0, i32 0
%36 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
%37 = load i64, i64* %7
%38 = call i32 @memcpy(i32* %35, i32* %36, i64 %37)
%39 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %4
%40 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %39, i32 0, i32 1
%41 = load i32, i32* %40
%42 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %5
%43 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %42, i32 0, i32 1
store i32 %41, i32* %43
store i32 0, i32* %3
br label %44
44: ; preds = %24, %21
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32, i32 }
@EINVAL = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [35 x i8] c"Multicast data address must be odd\00"
define i32 @aeron_ipv6_multicast_control_address(%struct.sockaddr_in6* %0, %struct.sockaddr_in6* %1) {
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %3 to i8*
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%6 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %0, i64 0, i32 0
%7 = call i32 @memcpy(i32* %5, i32* %6, i64 4)
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%9 = load i32, i32* %8
%10 = and i32 %9, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @EINVAL
%14 = call i32 @aeron_set_err(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %25
15: ; preds = %2
%16 = add nsw i32 %9, 1
store i32 %16, i32* %8
%17 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %0, i64 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i64 0, i32 2
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i64 0, i32 0
%21 = call i32 @memcpy(i32* %20, i32* %5, i64 4)
%22 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %0, i64 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i64 0, i32 1
store i32 %23, i32* %24
br label %25
25: ; preds = %15, %12
%26 = phi i32 [ -1, %12 ], [ 0, %15 ]
ret i32 %26
}