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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fputc_err(char, int /*<<< orphan*/ *);
void WriteUnicodeString(FILE *outf, char *str) {
  unsigned long ctr = 0;
  (assert(outf != NULL));
  if (str != NULL) {
    for (ctr = 0; str[ctr] != '\0'; ctr++) {
      fputc_err(str[ctr], outf);
      fputc_err(0, outf);
    }
  }
  fputc_err(0, outf);
  fputc_err(0, outf);
}


x86 assembly (clang, -O0):
<WriteUnicodeString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
je     11aa <WriteUnicodeString+0x8a>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11a5 <WriteUnicodeString+0x85>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc_err@plt>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc_err@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115d <WriteUnicodeString+0x3d>
jmp    11aa <WriteUnicodeString+0x8a>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc_err@plt>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc_err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteUnicodeString>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
test   %rbx,%rbx
je     1170 <WriteUnicodeString+0x50>
mov    (%rbx),%al
test   %al,%al
je     1170 <WriteUnicodeString+0x50>
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r14,%rsi
call   1040 <fputc_err@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <fputc_err@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <WriteUnicodeString+0x30>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <fputc_err@plt>
xor    %edi,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fputc_err@plt>

LLVM IR (-O0):
define void @WriteUnicodeString(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
store i32* %0, i32** %3
store i8* %1, i8** %4
store i64 0, i64* %5
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %33
12: ; preds = %2
store i64 0, i64* %5
br label %13
13: ; preds = %29, %12
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = load i64, i64* %5
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8, i8* %23
%25 = load i32*, i32** %3
%26 = call i32 @fputc_err(i8 signext %24, i32* %25)
%27 = load i32*, i32** %3
%28 = call i32 @fputc_err(i8 signext 0, i32* %27)
br label %29
29: ; preds = %20
%30 = load i64, i64* %5
%31 = add i64 %30, 1
store i64 %31, i64* %5
br label %13
32: ; preds = %13
br label %33
33: ; preds = %32, %2
%34 = load i32*, i32** %3
%35 = call i32 @fputc_err(i8 signext 0, i32* %34)
%36 = load i32*, i32** %3
%37 = call i32 @fputc_err(i8 signext 0, i32* %36)
ret void
}

LLVM IR (-O2):
define void @WriteUnicodeString(i32* %0, i8* %1) {
%3 = icmp ne i32* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp eq i8* %1, null
br i1 %6, label %19, label %7
7: ; preds = %2
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7, %10
%11 = phi i8 [ %17, %10 ], [ %8, %7 ]
%12 = phi i64 [ %15, %10 ], [ 0, %7 ]
%13 = tail call i32 @fputc_err(i8 signext %11, i32* %0)
%14 = tail call i32 @fputc_err(i8 signext 0, i32* %0)
%15 = add i64 %12, 1
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %10
19: ; preds = %10, %7, %2
%20 = tail call i32 @fputc_err(i8 signext 0, i32* %0)
%21 = tail call i32 @fputc_err(i8 signext 0, i32* %0)
ret void
}