#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 */
unsigned short htons(unsigned short);
int ILibStun_AddSctpChunkHeader(char *buffer, int ptr, unsigned char chunktype,
                                unsigned char chunkflags,
                                unsigned short chunklength) {
  buffer[ptr] = chunktype;
  buffer[ptr + 1] = chunkflags;
  ((unsigned short *)(buffer + ptr))[1] = htons(chunklength);
  return ptr + 4;
}


x86 assembly (clang, -O0):
<ILibStun_AddSctpChunkHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %r8w,%ax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %dl,-0xd(%rbp)
mov    %cl,-0xe(%rbp)
mov    %ax,-0x10(%rbp)
mov    -0xd(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xe(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movzwl -0x10(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,%dx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dx,0x2(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x4,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ILibStun_AddSctpChunkHeader>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movslq %esi,%rbx
mov    %dl,(%rdi,%rbx,1)
mov    %cl,0x1(%rdi,%rbx,1)
mov    %r8d,%edi
call   1030 <htons@plt>
mov    %ax,0x2(%r14,%rbx,1)
add    $0x4,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @ILibStun_AddSctpChunkHeader(i8* %0, i32 %1, i8 zeroext %2, i8 zeroext %3, i16 zeroext %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
%10 = alloca i16
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8 %2, i8* %8
store i8 %3, i8* %9
store i16 %4, i16* %10
%11 = load i8, i8* %8
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 %11, i8* %15
%16 = load i8, i8* %9
%17 = load i8*, i8** %6
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 %16, i8* %21
%22 = load i16, i16* %10
%23 = call zeroext i16 @htons(i16 zeroext %22)
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = bitcast i8* %27 to i16*
%29 = getelementptr inbounds i16, i16* %28, i64 1
store i16 %23, i16* %29
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 4
ret i32 %31
}

LLVM IR (-O2):
define i32 @ILibStun_AddSctpChunkHeader(i8* nocapture writeonly %0, i32 %1, i8 zeroext %2, i8 zeroext %3, i16 zeroext %4) {
%6 = sext i32 %1 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %2, i8* %7
%8 = add nsw i32 %1, 1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %3, i8* %10
%11 = tail call zeroext i16 @htons(i16 zeroext %4)
%12 = getelementptr inbounds i8, i8* %7, i64 2
%13 = bitcast i8* %12 to i16*
store i16 %11, i16* %13
%14 = add nsw i32 %1, 4
ret i32 %14
}