#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 */

/* Variables and functions */
int ILibAlignOnFourByteBoundary(char *, int);
unsigned short htons(unsigned short);
int /*<<< orphan*/ memcpy(char *, void *, int);
int ILibSCTP_AddOptionalVariableParameter(char *insertionPoint,
                                          unsigned short parameterType,
                                          void *parameterData,
                                          int parameterDataLen) {
  int retValue;
  ((unsigned short *)insertionPoint)[0] = parameterType;
  ((unsigned short *)insertionPoint)[1] =
      htons((unsigned short)(4 + parameterDataLen));
  if (parameterDataLen > 0) {
    memcpy(insertionPoint + 4, parameterData, parameterDataLen);
  }
  parameterDataLen += 4;
  retValue = ILibAlignOnFourByteBoundary(insertionPoint, parameterDataLen);
  return (retValue);
}


x86 assembly (clang, -O0):
<ILibSCTP_AddOptionalVariableParameter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0xa(%rbp),%cx
mov    -0x8(%rbp),%rax
mov    %cx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
movzwl %ax,%edi
call   1030 <htons@plt>
mov    %ax,%cx
mov    -0x8(%rbp),%rax
mov    %cx,0x2(%rax)
cmpl   $0x0,-0x1c(%rbp)
jle    118c <ILibSCTP_AddOptionalVariableParameter+0x5c>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <ILibAlignOnFourByteBoundary@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ILibSCTP_AddOptionalVariableParameter>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rdi,%rbx
mov    %si,(%rdi)
lea    0x4(%r14),%ebp
movzwl %bp,%edi
call   1030 <htons@plt>
mov    %ax,0x2(%rbx)
test   %r14d,%r14d
jle    1167 <ILibSCTP_AddOptionalVariableParameter+0x37>
lea    0x4(%rbx),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <ILibAlignOnFourByteBoundary@plt>

LLVM IR (-O0):
define i32 @ILibSCTP_AddOptionalVariableParameter(i8* %0, i16 zeroext %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i16 %1, i16* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i16, i16* %6
%11 = load i8*, i8** %5
%12 = bitcast i8* %11 to i16*
%13 = getelementptr inbounds i16, i16* %12, i64 0
store i16 %10, i16* %13
%14 = load i32, i32* %8
%15 = add nsw i32 4, %14
%16 = trunc i32 %15 to i16
%17 = call zeroext i16 @htons(i16 zeroext %16)
%18 = load i8*, i8** %5
%19 = bitcast i8* %18 to i16*
%20 = getelementptr inbounds i16, i16* %19, i64 1
store i16 %17, i16* %20
%21 = load i32, i32* %8
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %4
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 4
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = call i32 @memcpy(i8* %25, i8* %26, i32 %27)
br label %29
29: ; preds = %23, %4
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 4
store i32 %31, i32* %8
%32 = load i8*, i8** %5
%33 = load i32, i32* %8
%34 = call i32 @ILibAlignOnFourByteBoundary(i8* %32, i32 %33)
store i32 %34, i32* %9
%35 = load i32, i32* %9
ret i32 %35
}

LLVM IR (-O2):
define i32 @ILibSCTP_AddOptionalVariableParameter(i8* %0, i16 zeroext %1, i8* %2, i32 %3) {
%5 = bitcast i8* %0 to i16*
store i16 %1, i16* %5
%6 = add nsw i32 %3, 4
%7 = trunc i32 %6 to i16
%8 = tail call zeroext i16 @htons(i16 zeroext %7)
%9 = getelementptr inbounds i8, i8* %0, i64 2
%10 = bitcast i8* %9 to i16*
store i16 %8, i16* %10
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = getelementptr inbounds i8, i8* %0, i64 4
%14 = tail call i32 @memcpy(i8* %13, i8* %2, i32 %3)
br label %15
15: ; preds = %12, %4
%16 = tail call i32 @ILibAlignOnFourByteBoundary(i8* %0, i32 %6)
ret i32 %16
}