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

/* Variables and functions */
size_t u8_charlen(int /*<<< orphan*/);
size_t u8_codingsize(uint32_t *wcstr, size_t n) {
  size_t i, c = 0;
  for (i = 0; i < n; i++) {
    size_t cl = u8_charlen(wcstr[i]);
    if (cl == 0)
      cl = 3;
    c += cl;
  }
  return c;
}


x86 assembly (clang, -O0):
<u8_codingsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1182 <u8_codingsize+0x72>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <u8_charlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1165 <u8_codingsize+0x55>
movq   $0x3,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1130 <u8_codingsize+0x20>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u8_codingsize>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     114e <u8_codingsize+0x3e>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
mov    $0x3,%r13d
xor    %r12d,%r12d
nop
mov    (%r14,%rbx,4),%edi
call   1030 <u8_charlen@plt>
test   %rax,%rax
cmove  %r13,%rax
add    %rax,%r12
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <u8_codingsize+0x20>
jmp    1151 <u8_codingsize+0x41>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @u8_codingsize(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %15, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %13, %4 ], [ 0, %2 ]
%6 = phi i64 [ %12, %4 ], [ 0, %2 ]
%7 = getelementptr inbounds i32, i32* %0, i64 %5
%8 = load i32, i32* %7
%9 = tail call i64 @u8_charlen(i32 %8)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i64 3, i64 %9
%12 = add i64 %11, %6
%13 = add nuw i64 %5, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %15, label %4
15: ; preds = %4, %2
%16 = phi i64 [ 0, %2 ], [ %12, %4 ]
ret i64 %16
}