#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;

/* Variables and functions */
scalar_t__ UnicodeUtilities_is_utf16_surrogate(int /*<<< orphan*/ const);
size_t StringUtilities_code_point_length_for_part(const wchar_t *string,
                                                  const int length) {
  int code_points = 0;
  int i;
  for (i = 0; i < length; ++i) {
    ++code_points;
    if (UnicodeUtilities_is_utf16_surrogate(string[i])) {
      ++i;
    }
  }
  return code_points;
}


x86 assembly (clang, -O0):
<StringUtilities_code_point_length_for_part>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1178 <StringUtilities_code_point_length_for_part+0x68>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <UnicodeUtilities_is_utf16_surrogate@plt>
cmp    $0x0,%rax
je     1165 <StringUtilities_code_point_length_for_part+0x55>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116a <StringUtilities_code_point_length_for_part+0x5a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <StringUtilities_code_point_length_for_part+0x1d>
movslq -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StringUtilities_code_point_length_for_part>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %esi,%esi
jle    1151 <StringUtilities_code_point_length_for_part+0x41>
mov    %esi,%r15d
mov    %rdi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebp,%rbp
mov    (%r14,%rbp,4),%edi
call   1030 <UnicodeUtilities_is_utf16_surrogate@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0x1,%ebp
add    $0x1,%rbx
cmp    %r15d,%ebp
jl     1130 <StringUtilities_code_point_length_for_part+0x20>
jmp    1153 <StringUtilities_code_point_length_for_part+0x43>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @StringUtilities_code_point_length_for_part(i32* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %19
4: ; preds = %2, %4
%5 = phi i32 [ %15, %4 ], [ 0, %2 ]
%6 = phi i32 [ %7, %4 ], [ 0, %2 ]
%7 = add nuw nsw i32 %6, 1
%8 = sext i32 %5 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = tail call i64 @UnicodeUtilities_is_utf16_surrogate(i32 %10)
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i32
%14 = add nsw i32 %5, 1
%15 = add i32 %14, %13
%16 = icmp slt i32 %15, %1
br i1 %16, label %4, label %17
17: ; preds = %4
%18 = zext i32 %7 to i64
br label %19
19: ; preds = %17, %2
%20 = phi i64 [ 0, %2 ], [ %18, %17 ]
ret i64 %20
}