extern const unsigned short *sqUTF16ToUTF32Iterate(const unsigned short *string,
                                                   int *dest) {
  unsigned int high;
  unsigned int low;
  *dest = 0;
  if (!*string)
    return string;
  while ((high = *string) != 0) {
    ++string;
    if (high < 0xD800 || 0xE000 <= high) {
      *dest = high;
      break;
    } else if (high < 0xDC00) {
      low = *string;
      if (!low)
        break;
      ++string;
      if (0xDC00 <= low && low < 0xE000) {
        *dest = (high - 0xD800) << 10 | (low - 0xDC00);
      }
    } else {
    }
  }
  return string;
}


x86 assembly (clang, -O0):
<sqUTF16ToUTF32Iterate>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpw   $0x0,(%rax)
jne    1131 <sqUTF16ToUTF32Iterate+0x31>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1203 <sqUTF16ToUTF32Iterate+0x103>
jmp    1136 <sqUTF16ToUTF32Iterate+0x36>
mov    -0x10(%rbp),%rax
movzwl (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11fb <sqUTF16ToUTF32Iterate+0xfb>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0xd800,-0x1c(%rbp)
jb     1170 <sqUTF16ToUTF32Iterate+0x70>
mov    $0xe000,%eax
cmp    -0x1c(%rbp),%eax
ja     117e <sqUTF16ToUTF32Iterate+0x7e>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11fb <sqUTF16ToUTF32Iterate+0xfb>
cmpl   $0xdc00,-0x1c(%rbp)
jae    11ec <sqUTF16ToUTF32Iterate+0xec>
mov    -0x10(%rbp),%rax
movzwl (%rax),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11a4 <sqUTF16ToUTF32Iterate+0xa4>
jmp    11fb <sqUTF16ToUTF32Iterate+0xfb>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    $0xdc00,%eax
cmp    -0x20(%rbp),%eax
ja     11e7 <sqUTF16ToUTF32Iterate+0xe7>
cmpl   $0xe000,-0x20(%rbp)
jae    11e7 <sqUTF16ToUTF32Iterate+0xe7>
mov    -0x1c(%rbp),%ecx
sub    $0xd800,%ecx
shl    $0xa,%ecx
mov    -0x20(%rbp),%eax
sub    $0xdc00,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11f1 <sqUTF16ToUTF32Iterate+0xf1>
jmp    11f1 <sqUTF16ToUTF32Iterate+0xf1>
jmp    11f6 <sqUTF16ToUTF32Iterate+0xf6>
jmp    1136 <sqUTF16ToUTF32Iterate+0x36>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqUTF16ToUTF32Iterate>:
movl   $0x0,(%rsi)
movzwl (%rdi),%edx
test   %dx,%dx
jne    112e <sqUTF16ToUTF32Iterate+0x2e>
mov    %rdi,%rax
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rdi
movzwl (%rdi),%edx
mov    %rdi,%rax
test   %dx,%dx
je     117c <sqUTF16ToUTF32Iterate+0x7c>
movzwl %dx,%ecx
lea    0x2(%rdi),%rax
add    $0x2000,%edx
movzwl %dx,%edx
cmp    $0xf7ff,%edx
jbe    117d <sqUTF16ToUTF32Iterate+0x7d>
cmp    $0xdbff,%ecx
ja     1120 <sqUTF16ToUTF32Iterate+0x20>
movzwl (%rax),%edx
test   %edx,%edx
je     117c <sqUTF16ToUTF32Iterate+0x7c>
add    $0x4,%rdi
mov    %edx,%eax
and    $0xfc00,%eax
cmp    $0xdc00,%eax
jne    1123 <sqUTF16ToUTF32Iterate+0x23>
shl    $0xa,%ecx
add    $0xfca00000,%ecx
add    $0xffff2400,%edx
or     %ecx,%edx
mov    %edx,(%rsi)
jmp    1123 <sqUTF16ToUTF32Iterate+0x23>
ret
mov    %ecx,(%rsi)
ret

LLVM IR (-O0):
define i16* @sqUTF16ToUTF32Iterate(i16* %0, i32* %1) {
%3 = alloca i16*
%4 = alloca i16*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i16* %0, i16** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
store i32 0, i32* %8
%9 = load i16*, i16** %4
%10 = load i16, i16* %9
%11 = icmp ne i16 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = load i16*, i16** %4
store i16* %13, i16** %3
br label %63
14: ; preds = %2
br label %15
15: ; preds = %60, %14
%16 = load i16*, i16** %4
%17 = load i16, i16* %16
%18 = zext i16 %17 to i32
store i32 %18, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %61
20: ; preds = %15
%21 = load i16*, i16** %4
%22 = getelementptr inbounds i16, i16* %21, i32 1
store i16* %22, i16** %4
%23 = load i32, i32* %6
%24 = icmp ult i32 %23, 55296
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = load i32, i32* %6
%27 = icmp ule i32 57344, %26
br i1 %27, label %28, label %31
28: ; preds = %25, %20
%29 = load i32, i32* %6
%30 = load i32*, i32** %5
store i32 %29, i32* %30
br label %61
31: ; preds = %25
%32 = load i32, i32* %6
%33 = icmp ult i32 %32, 56320
br i1 %33, label %34, label %58
34: ; preds = %31
%35 = load i16*, i16** %4
%36 = load i16, i16* %35
%37 = zext i16 %36 to i32
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %34
br label %61
41: ; preds = %34
%42 = load i16*, i16** %4
%43 = getelementptr inbounds i16, i16* %42, i32 1
store i16* %43, i16** %4
%44 = load i32, i32* %7
%45 = icmp ule i32 56320, %44
br i1 %45, label %46, label %57
46: ; preds = %41
%47 = load i32, i32* %7
%48 = icmp ult i32 %47, 57344
br i1 %48, label %49, label %57
49: ; preds = %46
%50 = load i32, i32* %6
%51 = sub i32 %50, 55296
%52 = shl i32 %51, 10
%53 = load i32, i32* %7
%54 = sub i32 %53, 56320
%55 = or i32 %52, %54
%56 = load i32*, i32** %5
store i32 %55, i32* %56
br label %57
57: ; preds = %49, %46, %41
br label %59
58: ; preds = %31
br label %59
59: ; preds = %58, %57
br label %60
60: ; preds = %59
br label %15
61: ; preds = %40, %28, %15
%62 = load i16*, i16** %4
store i16* %62, i16** %3
br label %63
63: ; preds = %61, %12
%64 = load i16*, i16** %3
ret i16* %64
}

LLVM IR (-O2):
define i16* @sqUTF16ToUTF32Iterate(i16* %0, i32* nocapture writeonly %1) {
store i32 0, i32* %1
%3 = load i16, i16* %0
%4 = icmp eq i16 %3, 0
br i1 %4, label %32, label %5
5: ; preds = %2, %28
%6 = phi i16* [ %29, %28 ], [ %0, %2 ]
%7 = phi i16 [ %30, %28 ], [ %3, %2 ]
%8 = zext i16 %7 to i32
%9 = getelementptr inbounds i16, i16* %6, i64 1
%10 = add i16 %7, 8192
%11 = icmp ult i16 %10, -2048
br i1 %11, label %12, label %13
12: ; preds = %5
store i32 %8, i32* %1
br label %32
13: ; preds = %5
%14 = icmp ult i16 %7, -9216
br i1 %14, label %15, label %28
15: ; preds = %13
%16 = load i16, i16* %9
%17 = zext i16 %16 to i32
%18 = icmp eq i16 %16, 0
br i1 %18, label %32, label %19
19: ; preds = %15
%20 = getelementptr inbounds i16, i16* %6, i64 2
%21 = and i16 %16, -1024
%22 = icmp eq i16 %21, -9216
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = shl nuw nsw i32 %8, 10
%25 = add nsw i32 %24, -56623104
%26 = add nsw i32 %17, -56320
%27 = or i32 %26, %25
store i32 %27, i32* %1
br label %28
28: ; preds = %23, %19, %13
%29 = phi i16* [ %20, %23 ], [ %20, %19 ], [ %9, %13 ]
%30 = load i16, i16* %29
%31 = icmp eq i16 %30, 0
br i1 %31, label %32, label %5
32: ; preds = %15, %28, %12, %2
%33 = phi i16* [ %0, %2 ], [ %9, %12 ], [ %9, %15 ], [ %29, %28 ]
ret i16* %33
}