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

/* Variables and functions */
int const IP6OPT_PAD1;
int /*<<< orphan*/ memcpy(int *, int const *, int);
int *option_alloc(struct cmsghdr *, int, int, int);
int inet6_option_append(struct cmsghdr *cmsg, const uint8_t *typep, int multx,
                        int plusy) {
  int len = typep[0] == IP6OPT_PAD1 ? 1 : typep[1] + 2;
  uint8_t *ptr = option_alloc(cmsg, len, multx, plusy);
  if (ptr == NULL)
    return -1;
  memcpy(ptr, typep, len);
  return 0;
}


x86 assembly (clang, -O0):
<inet6_option_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2ea5(%rip),%rcx
cmp    (%rcx),%eax
jne    1158 <inet6_option_append+0x38>
mov    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1165 <inet6_option_append+0x45>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1040 <option_alloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1198 <inet6_option_append+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <inet6_option_append+0x8f>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet6_option_append>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmpl   $0x0,(%rsi)
je     1133 <inet6_option_append+0x13>
mov    0x4(%rbx),%ebp
add    $0x2,%ebp
jmp    1138 <inet6_option_append+0x18>
mov    $0x1,%ebp
mov    %ebp,%esi
call   1040 <option_alloc@plt>
test   %rax,%rax
je     1155 <inet6_option_append+0x35>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
jmp    115a <inet6_option_append+0x3a>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.cmsghdr = type { i32 }
@IP6OPT_PAD1 = constant i32 0
define i32 @inet6_option_append(%struct.cmsghdr* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.cmsghdr*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store %struct.cmsghdr* %0, %struct.cmsghdr** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i32*, i32** %7
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = load i32, i32* @IP6OPT_PAD1
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %4
br label %23
18: ; preds = %4
%19 = load i32*, i32** %7
%20 = getelementptr inbounds i32, i32* %19, i64 1
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 2
br label %23
23: ; preds = %18, %17
%24 = phi i32 [ 1, %17 ], [ %22, %18 ]
store i32 %24, i32* %10
%25 = load %struct.cmsghdr*, %struct.cmsghdr** %6
%26 = load i32, i32* %10
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = call i32* @option_alloc(%struct.cmsghdr* %25, i32 %26, i32 %27, i32 %28)
store i32* %29, i32** %11
%30 = load i32*, i32** %11
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %33
32: ; preds = %23
store i32 -1, i32* %5
br label %38
33: ; preds = %23
%34 = load i32*, i32** %11
%35 = load i32*, i32** %7
%36 = load i32, i32* %10
%37 = call i32 @memcpy(i32* %34, i32* %35, i32 %36)
store i32 0, i32* %5
br label %38
38: ; preds = %33, %32
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
%struct.cmsghdr = type { i32 }
@IP6OPT_PAD1 = constant i32 0
define i32 @inet6_option_append(%struct.cmsghdr* %0, i32* %1, i32 %2, i32 %3) {
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = getelementptr inbounds i32, i32* %1, i64 1
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 2
br label %11
11: ; preds = %4, %7
%12 = phi i32 [ %10, %7 ], [ 1, %4 ]
%13 = tail call i32* @option_alloc(%struct.cmsghdr* %0, i32 %12, i32 %2, i32 %3)
%14 = icmp eq i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @memcpy(i32* %13, i32* %1, i32 %12)
br label %17
17: ; preds = %11, %15
%18 = phi i32 [ 0, %15 ], [ -1, %11 ]
ret i32 %18
}