void writedatachunkhead(unsigned char *hdr, int wchannel, int wbits,
                        int nsamples) {
  int size = wchannel * (wbits / 8) * nsamples;
  *(hdr) = 'd';
  *(hdr + 1) = 'a';
  *(hdr + 2) = 't';
  *(hdr + 3) = 'a';
  *(hdr + 4) = (unsigned char)(size & 0xff);
  *(hdr + 5) = (unsigned char)((size & 0xff00) >> 8);
  *(hdr + 6) = (unsigned char)((size & 0xff0000) >> 16);
  *(hdr + 7) = (unsigned char)((size & 0xff000000) >> 24);
}


x86 assembly (clang, -O0):
<writedatachunkhead>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x64,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x61,0x1(%rax)
mov    -0x8(%rbp),%rax
movb   $0x74,0x2(%rax)
mov    -0x8(%rbp),%rax
movb   $0x61,0x3(%rax)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x18(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x18(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x18(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x7(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<writedatachunkhead>:
mov    %esi,%eax
lea    0x7(%rdx),%esi
test   %edx,%edx
cmovns %edx,%esi
sar    $0x3,%esi
imul   %ecx,%eax
imul   %esi,%eax
movl   $0x61746164,(%rdi)
mov    %al,0x4(%rdi)
mov    %ah,0x5(%rdi)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x6(%rdi)
shr    $0x18,%eax
mov    %al,0x7(%rdi)
ret

LLVM IR (-O0):
define void @writedatachunkhead(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %6
%11 = load i32, i32* %7
%12 = sdiv i32 %11, 8
%13 = mul nsw i32 %10, %12
%14 = load i32, i32* %8
%15 = mul nsw i32 %13, %14
store i32 %15, i32* %9
%16 = load i8*, i8** %5
store i8 100, i8* %16
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 97, i8* %18
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 2
store i8 116, i8* %20
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 3
store i8 97, i8* %22
%23 = load i32, i32* %9
%24 = and i32 %23, 255
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 4
store i8 %25, i8* %27
%28 = load i32, i32* %9
%29 = and i32 %28, 65280
%30 = ashr i32 %29, 8
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 5
store i8 %31, i8* %33
%34 = load i32, i32* %9
%35 = and i32 %34, 16711680
%36 = ashr i32 %35, 16
%37 = trunc i32 %36 to i8
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 6
store i8 %37, i8* %39
%40 = load i32, i32* %9
%41 = and i32 %40, -16777216
%42 = lshr i32 %41, 24
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i64 7
store i8 %43, i8* %45
ret void
}

LLVM IR (-O2):
define void @writedatachunkhead(i8* nocapture writeonly %0, i32 %1, i32 %2, i32 %3) {
%5 = sdiv i32 %2, 8
%6 = mul nsw i32 %5, %1
%7 = mul nsw i32 %6, %3
store i8 100, i8* %0
%8 = getelementptr inbounds i8, i8* %0, i64 1
store i8 97, i8* %8
%9 = getelementptr inbounds i8, i8* %0, i64 2
store i8 116, i8* %9
%10 = getelementptr inbounds i8, i8* %0, i64 3
store i8 97, i8* %10
%11 = trunc i32 %7 to i8
%12 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %11, i8* %12
%13 = lshr i32 %7, 8
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %14, i8* %15
%16 = lshr i32 %7, 16
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %17, i8* %18
%19 = lshr i32 %7, 24
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %20, i8* %21
ret void
}