#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 /*<<< orphan*/ tmp;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
void write_utf16le(unsigned char *buf, int len, FILE *fp) {
  int i;
  char tmp[2];
  tmp[1] = 0;
  for (i = 0; i < len; i++) {
    tmp[0] = buf[i];
    fwrite(tmp, 1, sizeof(tmp), fp);
  }
}


x86 assembly (clang, -O0):
<write_utf16le>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x1d(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116d <write_utf16le+0x5d>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1e(%rbp)
lea    -0x1e(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <fwrite@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <write_utf16le+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_utf16le>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0xf(%rsp)
test   %esi,%esi
jle    1167 <write_utf16le+0x57>
mov    %rdx,%r14
mov    %rdi,%r12
mov    %esi,%r13d
xor    %ebx,%ebx
lea    0xe(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%eax
mov    %al,0xe(%rsp)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %r14,%rcx
call   1030 <fwrite@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1140 <write_utf16le+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @write_utf16le(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [2 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 0, i8* %9
store i32 0, i32* %7
br label %10
10: ; preds = %24, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %19, i8* %20
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i32 @fwrite(i8* %21, i32 1, i32 2, i32* %22)
br label %24
24: ; preds = %14
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %10
27: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @write_utf16le(i8* nocapture %0, i32 %1, i32* nocapture %2) {
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %6
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %5
%14 = call i32 @fwrite(i8* %5, i32 1, i32 2, i32* %2)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10, %3
ret void
}