void writeriffhead(unsigned char *hdr, int flength) {
  *(hdr) = 'R';
  *(hdr + 1) = 'I';
  *(hdr + 2) = 'F';
  *(hdr + 3) = 'F';
  *(hdr + 4) = (unsigned char)(flength & 0xff);
  *(hdr + 5) = (unsigned char)((flength & 0xff00) >> 8);
  *(hdr + 6) = (unsigned char)((flength & 0xff0000) >> 16);
  *(hdr + 7) = (unsigned char)((flength & 0xff000000) >> 24);
  *(hdr + 8) = 'W';
  *(hdr + 9) = 'A';
  *(hdr + 10) = 'V';
  *(hdr + 11) = 'E';
}


x86 assembly (clang, -O0):
<writeriffhead>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x52,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x49,0x1(%rax)
mov    -0x8(%rbp),%rax
movb   $0x46,0x2(%rax)
mov    -0x8(%rbp),%rax
movb   $0x46,0x3(%rax)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0xc(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0xc(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0xc(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x8(%rbp),%rax
movb   $0x57,0x8(%rax)
mov    -0x8(%rbp),%rax
movb   $0x41,0x9(%rax)
mov    -0x8(%rbp),%rax
movb   $0x56,0xa(%rax)
mov    -0x8(%rbp),%rax
movb   $0x45,0xb(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeriffhead>:
mov    %esi,%eax
movl   $0x46464952,(%rdi)
mov    %al,0x4(%rdi)
mov    %ah,0x5(%rdi)
mov    %esi,%ecx
shr    $0x10,%ecx
mov    %cl,0x6(%rdi)
shr    $0x18,%eax
mov    %al,0x7(%rdi)
movl   $0x45564157,0x8(%rdi)
ret

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

LLVM IR (-O2):
define void @writeriffhead(i8* nocapture writeonly %0, i32 %1) {
store i8 82, i8* %0
%3 = getelementptr inbounds i8, i8* %0, i64 1
store i8 73, i8* %3
%4 = getelementptr inbounds i8, i8* %0, i64 2
store i8 70, i8* %4
%5 = getelementptr inbounds i8, i8* %0, i64 3
store i8 70, i8* %5
%6 = trunc i32 %1 to i8
%7 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %6, i8* %7
%8 = lshr i32 %1, 8
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %9, i8* %10
%11 = lshr i32 %1, 16
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %12, i8* %13
%14 = lshr i32 %1, 24
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %15, i8* %16
%17 = getelementptr inbounds i8, i8* %0, i64 8
store i8 87, i8* %17
%18 = getelementptr inbounds i8, i8* %0, i64 9
store i8 65, i8* %18
%19 = getelementptr inbounds i8, i8* %0, i64 10
store i8 86, i8* %19
%20 = getelementptr inbounds i8, i8* %0, i64 11
store i8 69, i8* %20
ret void
}