#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 packet {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int const *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pdu_data(struct packet *, int *, int);
int pdu_icmpv6(struct packet *, int, int /*<<< orphan*/, int /*<<< orphan*/,
               int /*<<< orphan*/);
int pdu_icmpv6_neighbor_sol(struct packet *p, const uint8_t *target,
                            const uint8_t *mac_src) {
  uint8_t icmp_tag = pdu_icmpv6(p, 135, 0, 0, 0);
  if (icmp_tag == -1)
    return -1;
  uint8_t *icmp_data = malloc(16 + 8);
  memset(icmp_data, 0, 16 + 8);
  memcpy(icmp_data, target, 16);
  icmp_data[16] = 0x01;
  icmp_data[17] = 0x01;
  memcpy(&icmp_data[18], mac_src, 6);
  pdu_data(p, icmp_data, 16 + 8);
  free(icmp_data);
  return icmp_tag;
}


x86 assembly (clang, -O0):
<pdu_icmpv6_neighbor_sol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x87,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1040 <pdu_icmpv6@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11a4 <pdu_icmpv6_neighbor_sol+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    1221 <pdu_icmpv6_neighbor_sol+0xc1>
mov    $0x18,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%rax
movl   $0x1,0x40(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0x44(%rax)
mov    -0x30(%rbp),%rdi
add    $0x48,%rdi
mov    -0x20(%rbp),%rsi
mov    $0x6,%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x18,%edx
call   1080 <pdu_data@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdu_icmpv6_neighbor_sol>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x87,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <pdu_icmpv6@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11ec <pdu_icmpv6_neighbor_sol+0x8c>
mov    $0x18,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
movabs $0x100000001,%rax
mov    %rax,0x40(%rbx)
lea    0x48(%rbx),%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1060 <memcpy@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1080 <pdu_data@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.packet = type { i32 }
define i32 @pdu_icmpv6_neighbor_sol(%struct.packet* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.packet*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
store %struct.packet* %0, %struct.packet** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%10 = load %struct.packet*, %struct.packet** %5
%11 = call i32 @pdu_icmpv6(%struct.packet* %10, i32 135, i32 0, i32 0, i32 0)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %36
15: ; preds = %3
%16 = call i32* @malloc(i32 24)
store i32* %16, i32** %9
%17 = load i32*, i32** %9
%18 = call i32 @memset(i32* %17, i32 0, i32 24)
%19 = load i32*, i32** %9
%20 = load i32*, i32** %6
%21 = call i32 @memcpy(i32* %19, i32* %20, i32 16)
%22 = load i32*, i32** %9
%23 = getelementptr inbounds i32, i32* %22, i64 16
store i32 1, i32* %23
%24 = load i32*, i32** %9
%25 = getelementptr inbounds i32, i32* %24, i64 17
store i32 1, i32* %25
%26 = load i32*, i32** %9
%27 = getelementptr inbounds i32, i32* %26, i64 18
%28 = load i32*, i32** %7
%29 = call i32 @memcpy(i32* %27, i32* %28, i32 6)
%30 = load %struct.packet*, %struct.packet** %5
%31 = load i32*, i32** %9
%32 = call i32 @pdu_data(%struct.packet* %30, i32* %31, i32 24)
%33 = load i32*, i32** %9
%34 = call i32 @free(i32* %33)
%35 = load i32, i32* %8
store i32 %35, i32* %4
br label %36
36: ; preds = %15, %14
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
%struct.packet = type { i32 }
define i32 @pdu_icmpv6_neighbor_sol(%struct.packet* %0, i32* %1, i32* %2) {
%4 = tail call i32 @pdu_icmpv6(%struct.packet* %0, i32 135, i32 0, i32 0, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i32* @malloc(i32 24)
%8 = tail call i32 @memset(i32* %7, i32 0, i32 24)
%9 = tail call i32 @memcpy(i32* %7, i32* %1, i32 16)
%10 = getelementptr inbounds i32, i32* %7, i64 16
store i32 1, i32* %10
%11 = getelementptr inbounds i32, i32* %7, i64 17
store i32 1, i32* %11
%12 = getelementptr inbounds i32, i32* %7, i64 18
%13 = tail call i32 @memcpy(i32* %12, i32* %2, i32 6)
%14 = tail call i32 @pdu_data(%struct.packet* %0, i32* %7, i32 24)
%15 = tail call i32 @free(i32* %7)
br label %16
16: ; preds = %3, %6
ret i32 %4
}