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

/* Variables and functions */
scalar_t__ CMSG_DATA(struct cmsghdr *);
int /*<<< orphan*/ CMSG_LEN(int);
int /*<<< orphan*/ IPPROTO_IPV6;
int /*<<< orphan*/ IPV6_RTHDR;
#define IPV6_RTHDR_TYPE_0 128
int /*<<< orphan*/ bzero(struct ip6_rthdr *, int);
struct cmsghdr *inet6_rthdr_init(void *bp, int type) {
  struct cmsghdr *ch = (struct cmsghdr *)bp;
  struct ip6_rthdr *rthdr;
  rthdr = (struct ip6_rthdr *)CMSG_DATA(ch);
  ch->cmsg_level = IPPROTO_IPV6;
  ch->cmsg_type = IPV6_RTHDR;
  switch (type) {
  case IPV6_RTHDR_TYPE_0:
    ch->cmsg_len = CMSG_LEN(sizeof(struct ip6_rthdr0));
    bzero(rthdr, sizeof(struct ip6_rthdr0));
    rthdr->ip6r_type = IPV6_RTHDR_TYPE_0;
    return (ch);
  default:
    return (NULL);
  }
}


x86 assembly (clang, -O0):
<inet6_rthdr_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <CMSG_DATA@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2e7d(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%eax
sub    $0x80,%eax
jne    11be <inet6_rthdr_init+0x8e>
jmp    1187 <inet6_rthdr_init+0x57>
mov    $0x4,%edi
call   1040 <CMSG_LEN@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x4,%esi
call   1050 <bzero@plt>
mov    -0x28(%rbp),%rax
movl   $0x80,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c6 <inet6_rthdr_init+0x96>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_rthdr_init>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <CMSG_DATA@plt>
mov    %rax,%r14
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
cmp    $0x80,%ebp
jne    1183 <inet6_rthdr_init+0x53>
mov    $0x4,%edi
call   1040 <CMSG_LEN@plt>
mov    %eax,(%rbx)
mov    %r14,%rdi
mov    $0x4,%esi
call   1050 <bzero@plt>
movl   $0x80,(%r14)
jmp    1185 <inet6_rthdr_init+0x55>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.cmsghdr = type { i32, i32, i32 }
%struct.ip6_rthdr = type { i32 }
@IPPROTO_IPV6 = global i32 0
@IPV6_RTHDR = global i32 0
define %struct.cmsghdr* @inet6_rthdr_init(i8* %0, i32 %1) {
%3 = alloca %struct.cmsghdr*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.cmsghdr*
%7 = alloca %struct.ip6_rthdr*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = bitcast i8* %8 to %struct.cmsghdr*
store %struct.cmsghdr* %9, %struct.cmsghdr** %6
%10 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%11 = call i64 @CMSG_DATA(%struct.cmsghdr* %10)
%12 = inttoptr i64 %11 to %struct.ip6_rthdr*
store %struct.ip6_rthdr* %12, %struct.ip6_rthdr** %7
%13 = load i32, i32* @IPPROTO_IPV6
%14 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%15 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %14, i32 0, i32 2
store i32 %13, i32* %15
%16 = load i32, i32* @IPV6_RTHDR
%17 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%18 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %17, i32 0, i32 1
store i32 %16, i32* %18
%19 = load i32, i32* %5
switch i32 %19, label %29 [
i32 128, label %20
]
20: ; preds = %2
%21 = call i32 @CMSG_LEN(i32 4)
%22 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%23 = getelementptr inbounds %struct.cmsghdr, %struct.cmsghdr* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load %struct.ip6_rthdr*, %struct.ip6_rthdr** %7
%25 = call i32 @bzero(%struct.ip6_rthdr* %24, i32 4)
%26 = load %struct.ip6_rthdr*, %struct.ip6_rthdr** %7
%27 = getelementptr inbounds %struct.ip6_rthdr, %struct.ip6_rthdr* %26, i32 0, i32 0
store i32 128, i32* %27
%28 = load %struct.cmsghdr*, %struct.cmsghdr** %6
store %struct.cmsghdr* %28, %struct.cmsghdr** %3
br label %30
29: ; preds = %2
store %struct.cmsghdr* null, %struct.cmsghdr** %3
br label %30
30: ; preds = %29, %20
%31 = load %struct.cmsghdr*, %struct.cmsghdr** %3
ret %struct.cmsghdr* %31
}

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