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

/* Variables and functions */
int /*<<< orphan*/ MB_CUR_MAX;
int mblen(char *, int /*<<< orphan*/);
int _DtHelpFmtFindBreak(char *ptr, int mb_len, int *num_chars) {
  int len = 0;
  int numChars = 0;
  int mySize;
  short done = 0;
  while (0 == done && '\0' != *ptr) {
    mySize = mblen(ptr, MB_CUR_MAX);
    done = 1;
    if (0 < mySize &&
        ((1 != mb_len && 1 != mySize) || (1 == mb_len && 1 == mySize))) {
      numChars++;
      ptr += mySize;
      len += mySize;
      done = 0;
    }
  }
  *num_chars = numChars;
  return len;
}


x86 assembly (clang, -O0):
<_DtHelpFmtFindBreak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movw   $0x0,-0x26(%rbp)
movswl -0x26(%rbp),%edx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %edx,%ecx
mov    %al,-0x27(%rbp)
jne    115b <_DtHelpFmtFindBreak+0x4b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
setne  %al
mov    %al,-0x27(%rbp)
mov    -0x27(%rbp),%al
test   $0x1,%al
jne    116b <_DtHelpFmtFindBreak+0x5b>
jmp    11f7 <_DtHelpFmtFindBreak+0xe7>
mov    -0x8(%rbp),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
call   1030 <mblen@plt>
mov    %eax,-0x24(%rbp)
movw   $0x1,-0x26(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jge    11f2 <_DtHelpFmtFindBreak+0xe2>
mov    $0x1,%eax
cmp    -0xc(%rbp),%eax
je     11ad <_DtHelpFmtFindBreak+0x9d>
mov    $0x1,%eax
cmp    -0x24(%rbp),%eax
jne    11c9 <_DtHelpFmtFindBreak+0xb9>
mov    $0x1,%eax
cmp    -0xc(%rbp),%eax
jne    11f2 <_DtHelpFmtFindBreak+0xe2>
mov    $0x1,%eax
cmp    -0x24(%rbp),%eax
jne    11f2 <_DtHelpFmtFindBreak+0xe2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movw   $0x0,-0x26(%rbp)
jmp    1137 <_DtHelpFmtFindBreak+0x27>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_DtHelpFmtFindBreak>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
cmpb   $0x0,(%rdi)
je     117a <_DtHelpFmtFindBreak+0x6a>
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %r12d,%r12d
mov    0x2ec5(%rip),%r13
xor    %ebp,%ebp
jmp    1152 <_DtHelpFmtFindBreak+0x42>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %eax,%ecx
add    %eax,%r12d
cmpb   $0x0,(%rbx,%rcx,1)
lea    (%rbx,%rcx,1),%rbx
je     117f <_DtHelpFmtFindBreak+0x6f>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1030 <mblen@plt>
test   %eax,%eax
jle    117f <_DtHelpFmtFindBreak+0x6f>
cmp    $0x1,%r15d
je     116d <_DtHelpFmtFindBreak+0x5d>
cmp    $0x1,%eax
jne    1140 <_DtHelpFmtFindBreak+0x30>
cmp    $0x1,%r15d
jne    117f <_DtHelpFmtFindBreak+0x6f>
cmp    $0x1,%eax
je     1140 <_DtHelpFmtFindBreak+0x30>
jmp    117f <_DtHelpFmtFindBreak+0x6f>
xor    %ebp,%ebp
xor    %r12d,%r12d
mov    %ebp,(%r14)
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MB_CUR_MAX = global i32 0
define i32 @_DtHelpFmtFindBreak(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i16
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i16 0, i16* %10
br label %11
11: ; preds = %50, %3
%12 = load i16, i16* %10
%13 = sext i16 %12 to i32
%14 = icmp eq i32 0, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 0, %18
br label %20
20: ; preds = %15, %11
%21 = phi i1 [ false, %11 ], [ %19, %15 ]
br i1 %21, label %22, label %51
22: ; preds = %20
%23 = load i8*, i8** %4
%24 = load i32, i32* @MB_CUR_MAX
%25 = call i32 @mblen(i8* %23, i32 %24)
store i32 %25, i32* %9
store i16 1, i16* %10
%26 = load i32, i32* %9
%27 = icmp slt i32 0, %26
br i1 %27, label %28, label %50
28: ; preds = %22
%29 = load i32, i32* %5
%30 = icmp ne i32 1, %29
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %9
%33 = icmp ne i32 1, %32
br i1 %33, label %40, label %34
34: ; preds = %31, %28
%35 = load i32, i32* %5
%36 = icmp eq i32 1, %35
br i1 %36, label %37, label %50
37: ; preds = %34
%38 = load i32, i32* %9
%39 = icmp eq i32 1, %38
br i1 %39, label %40, label %50
40: ; preds = %37, %31
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
%43 = load i32, i32* %9
%44 = load i8*, i8** %4
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8* %46, i8** %4
%47 = load i32, i32* %9
%48 = load i32, i32* %7
%49 = add nsw i32 %48, %47
store i32 %49, i32* %7
store i16 0, i16* %10
br label %50
50: ; preds = %40, %37, %34, %22
br label %11
51: ; preds = %20
%52 = load i32, i32* %8
%53 = load i32*, i32** %6
store i32 %52, i32* %53
%54 = load i32, i32* %7
ret i32 %54
}

LLVM IR (-O2):
@MB_CUR_MAX = global i32 0
define i32 @_DtHelpFmtFindBreak(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = icmp ne i32 %1, 1
%5 = icmp eq i32 %1, 1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %28, label %8
8: ; preds = %3, %21
%9 = phi i32 [ %25, %21 ], [ 0, %3 ]
%10 = phi i32 [ %22, %21 ], [ 0, %3 ]
%11 = phi i8* [ %24, %21 ], [ %0, %3 ]
%12 = load i32, i32* @MB_CUR_MAX
%13 = tail call i32 @mblen(i8* %11, i32 %12)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %8
%16 = icmp ne i32 %13, 1
%17 = select i1 %4, i1 %16, i1 false
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = icmp eq i32 %13, 1
%20 = select i1 %5, i1 %19, i1 false
br i1 %20, label %21, label %28
21: ; preds = %15, %18
%22 = add nuw nsw i32 %10, 1
%23 = zext i32 %13 to i64
%24 = getelementptr inbounds i8, i8* %11, i64 %23
%25 = add nsw i32 %13, %9
%26 = load i8, i8* %24
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %8
28: ; preds = %21, %18, %8, %3
%29 = phi i32 [ 0, %3 ], [ %22, %21 ], [ %10, %18 ], [ %10, %8 ]
%30 = phi i32 [ 0, %3 ], [ %25, %21 ], [ %9, %18 ], [ %9, %8 ]
store i32 %29, i32* %2
ret i32 %30
}