#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 */
struct ip6_rthdr0 {
  int dummy;
};
struct cmsghdr {
  int cmsg_len;
  int /*<<< orphan*/ cmsg_type;
  int /*<<< orphan*/ cmsg_level;
};

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_RTHDR;
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
extern struct cmsghdr *inet6_srcrt_init(void *bp, int type) {
  struct cmsghdr *cmsg;
  if (type)
    return NULL;
  memset(bp, 0, sizeof(struct cmsghdr) + sizeof(struct ip6_rthdr0));
  cmsg = (struct cmsghdr *)bp;
  cmsg->cmsg_len = sizeof(struct cmsghdr) + sizeof(struct ip6_rthdr0);
  cmsg->cmsg_level = IPPROTO_IPV6;
  cmsg->cmsg_type = IPV6_RTHDR;
  return cmsg;
}


x86 assembly (clang, -O0):
<inet6_srcrt_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1136 <inet6_srcrt_init+0x26>
movq   $0x0,-0x8(%rbp)
jmp    1180 <inet6_srcrt_init+0x70>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x10,(%rax)
mov    0x2e79(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2e79(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_srcrt_init>:
push   %rbx
test   %esi,%esi
je     1119 <inet6_srcrt_init+0x9>
xor    %ebx,%ebx
jmp    1146 <inet6_srcrt_init+0x36>
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
movl   $0x10,(%rbx)
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    0x2ea7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.cmsghdr = type { i32, i32, i32 }
@IPPROTO_IPV6 = global i32 0
@IPV6_RTHDR = global i32 0
define %struct.cmsghdr* @inet6_srcrt_init(i8* %0, i32 %1) {
%3 = alloca %struct.cmsghdr*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.cmsghdr*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store %struct.cmsghdr* null, %struct.cmsghdr** %3
br label %24
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @memset(i8* %11, i32 0, i32 16)
%13 = load i8*, i8** %4
%14 = bitcast i8* %13 to %struct.cmsghdr*
store %struct.cmsghdr* %14, %struct.cmsghdr** %6
%15 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%16 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %15, i32 0, i32 0
store i32 16, i32* %16
%17 = load i32, i32* @IPPROTO_IPV6
%18 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%19 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %18, i32 0, i32 2
store i32 %17, i32* %19
%20 = load i32, i32* @IPV6_RTHDR
%21 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%22 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %21, i32 0, i32 1
store i32 %20, i32* %22
%23 = load %struct.cmsghdr*, %struct.cmsghdr** %6
store %struct.cmsghdr* %23, %struct.cmsghdr** %3
br label %24
24: ; preds = %10, %9
%25 = load %struct.cmsghdr*, %struct.cmsghdr** %3
ret %struct.cmsghdr* %25
}

LLVM IR (-O2):
%struct.cmsghdr = type { i32, i32, i32 }
@IPPROTO_IPV6 = global i32 0
@IPV6_RTHDR = global i32 0
define %struct.cmsghdr* @inet6_srcrt_init(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = tail call i32 @memset(i8* %0, i32 0, i32 16)
%6 = bitcast i8* %0 to %struct.cmsghdr*
%7 = bitcast i8* %0 to i32*
store i32 16, i32* %7
%8 = load i32, i32* @IPPROTO_IPV6
%9 = getelementptr inbounds i8, i8* %0, i64 8
%10 = bitcast i8* %9 to i32*
store i32 %8, i32* %10
%11 = load i32, i32* @IPV6_RTHDR
%12 = getelementptr inbounds i8, i8* %0, i64 4
%13 = bitcast i8* %12 to i32*
store i32 %11, i32* %13
br label %14
14: ; preds = %2, %4
%15 = phi %struct.cmsghdr* [ %6, %4 ], [ null, %2 ]
ret %struct.cmsghdr* %15
}