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

/* Variables and functions */
scalar_t__ uint32WriteToFP(int /*<<< orphan*/ *, size_t *);
char *wchar_to_utf8(int /*<<< orphan*/ const *, int /*<<< orphan*/, size_t *);
int /*<<< orphan*/ wcslen(int /*<<< orphan*/ const *);
scalar_t__ write_FP(int /*<<< orphan*/ *, char const *, size_t);
size_t ustringWriteToFP(FILE *fp, const wchar_t **data) {
  uint32_t count = 0;
  uint32_t utf8_size;
  const char *utf8_text;
  if (*data == NULL) {
    utf8_size = 0;
  } else {
    utf8_text = wchar_to_utf8(*data, wcslen(*data), &utf8_size);
  }
  count += uint32WriteToFP(fp, &utf8_size);
  count += write_FP(fp, utf8_text, utf8_size);
  return count;
}


x86 assembly (clang, -O0):
<ustringWriteToFP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1173 <ustringWriteToFP+0x33>
movq   $0x0,-0x20(%rbp)
jmp    119d <ustringWriteToFP+0x5d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <wcslen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
call   1030 <wchar_to_utf8@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <uint32WriteToFP@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <write_FP@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ustringWriteToFP>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    (%rsi),%rbx
test   %rbx,%rbx
je     1170 <ustringWriteToFP+0x30>
mov    %rbx,%rdi
call   1040 <wcslen@plt>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <wchar_to_utf8@plt>
mov    %rax,%r14
jmp    1179 <ustringWriteToFP+0x39>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1060 <uint32WriteToFP@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <write_FP@plt>
add    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @ustringWriteToFP(i32* %0, i32** %1) {
%3 = alloca i32*
%4 = alloca i32**
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i32* %0, i32** %3
store i32** %1, i32*** %4
store i64 0, i64* %5
%8 = load i32**, i32*** %4
%9 = load i32*, i32** %8
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i64 0, i64* %6
br label %19
12: ; preds = %2
%13 = load i32**, i32*** %4
%14 = load i32*, i32** %13
%15 = load i32**, i32*** %4
%16 = load i32*, i32** %15
%17 = call i32 @wcslen(i32* %16)
%18 = call i8* @wchar_to_utf8(i32* %14, i32 %17, i64* %6)
store i8* %18, i8** %7
br label %19
19: ; preds = %12, %11
%20 = load i32*, i32** %3
%21 = call i64 @uint32WriteToFP(i32* %20, i64* %6)
%22 = load i64, i64* %5
%23 = add i64 %22, %21
store i64 %23, i64* %5
%24 = load i32*, i32** %3
%25 = load i8*, i8** %7
%26 = load i64, i64* %6
%27 = call i64 @write_FP(i32* %24, i8* %25, i64 %26)
%28 = load i64, i64* %5
%29 = add i64 %28, %27
store i64 %29, i64* %5
%30 = load i64, i64* %5
ret i64 %30
}

LLVM IR (-O2):
define i64 @ustringWriteToFP(i32* %0, i32** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %2
store i64 0, i64* %3
br label %11
8: ; preds = %2
%9 = tail call i32 @wcslen(i32* %5)
%10 = call i8* @wchar_to_utf8(i32* %5, i32 %9, i64* %3)
br label %11
11: ; preds = %8, %7
%12 = phi i8* [ undef, %7 ], [ %10, %8 ]
%13 = call i64 @uint32WriteToFP(i32* %0, i64* %3)
%14 = load i64, i64* %3
%15 = call i64 @write_FP(i32* %0, i8* %12, i64 %14)
%16 = add i64 %15, %13
ret i64 %16
}