#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 */
size_t ucs4_to_utf8_size(const int *in) {
  size_t out_size = 1;
  while (*in) {
    if (*in <= 0x7f) {
      out_size++;
    } else if (*in <= 0x7ff) {
      out_size += 2;
    } else if (*in <= 0xffff) {
      out_size += 3;
    } else {
      out_size += 4;
    }
    ++in;
  }
  return out_size;
}


x86 assembly (clang, -O0):
<ucs4_to_utf8_size>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
je     11a4 <ucs4_to_utf8_size+0xa4>
mov    -0x8(%rbp),%rax
cmpl   $0x7f,(%rax)
jg     113b <ucs4_to_utf8_size+0x3b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1193 <ucs4_to_utf8_size+0x93>
mov    -0x8(%rbp),%rax
cmpl   $0x7ff,(%rax)
jg     115c <ucs4_to_utf8_size+0x5c>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    118e <ucs4_to_utf8_size+0x8e>
mov    -0x8(%rbp),%rax
cmpl   $0xffff,(%rax)
jg     117d <ucs4_to_utf8_size+0x7d>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    1189 <ucs4_to_utf8_size+0x89>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    118e <ucs4_to_utf8_size+0x8e>
jmp    1193 <ucs4_to_utf8_size+0x93>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    1110 <ucs4_to_utf8_size+0x10>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ucs4_to_utf8_size>:
mov    (%rdi),%ecx
test   %ecx,%ecx
je     1159 <ucs4_to_utf8_size+0x59>
add    $0x4,%rdi
mov    $0x1,%eax
jmp    112d <ucs4_to_utf8_size+0x2d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %rdx,%rax
mov    (%rdi),%ecx
add    $0x4,%rdi
test   %ecx,%ecx
je     1158 <ucs4_to_utf8_size+0x58>
mov    $0x1,%edx
cmp    $0x80,%ecx
jl     1120 <ucs4_to_utf8_size+0x20>
mov    $0x2,%edx
cmp    $0x800,%ecx
jb     1120 <ucs4_to_utf8_size+0x20>
cmp    $0x10000,%ecx
mov    $0x4,%edx
sbb    $0x0,%rdx
jmp    1120 <ucs4_to_utf8_size+0x20>
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i64 @ucs4_to_utf8_size(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
store i32* %0, i32** %2
store i64 1, i64* %3
br label %4
4: ; preds = %34, %1
%5 = load i32*, i32** %2
%6 = load i32, i32* %5
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %37
8: ; preds = %4
%9 = load i32*, i32** %2
%10 = load i32, i32* %9
%11 = icmp sle i32 %10, 127
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i64, i64* %3
%14 = add i64 %13, 1
store i64 %14, i64* %3
br label %34
15: ; preds = %8
%16 = load i32*, i32** %2
%17 = load i32, i32* %16
%18 = icmp sle i32 %17, 2047
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i64, i64* %3
%21 = add i64 %20, 2
store i64 %21, i64* %3
br label %33
22: ; preds = %15
%23 = load i32*, i32** %2
%24 = load i32, i32* %23
%25 = icmp sle i32 %24, 65535
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i64, i64* %3
%28 = add i64 %27, 3
store i64 %28, i64* %3
br label %32
29: ; preds = %22
%30 = load i64, i64* %3
%31 = add i64 %30, 4
store i64 %31, i64* %3
br label %32
32: ; preds = %29, %26
br label %33
33: ; preds = %32, %19
br label %34
34: ; preds = %33, %12
%35 = load i32*, i32** %2
%36 = getelementptr inbounds i32, i32* %35, i32 1
store i32* %36, i32** %2
br label %4
37: ; preds = %4
%38 = load i64, i64* %3
ret i64 %38
}

LLVM IR (-O2):
define i64 @ucs4_to_utf8_size(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = icmp eq i32 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1, %14
%5 = phi i32 [ %18, %14 ], [ %2, %1 ]
%6 = phi i64 [ %16, %14 ], [ 1, %1 ]
%7 = phi i32* [ %17, %14 ], [ %0, %1 ]
%8 = icmp slt i32 %5, 128
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = icmp ult i32 %5, 2048
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = icmp ult i32 %5, 65536
%13 = select i1 %12, i64 3, i64 4
br label %14
14: ; preds = %11, %9, %4
%15 = phi i64 [ 1, %4 ], [ 2, %9 ], [ %13, %11 ]
%16 = add i64 %6, %15
%17 = getelementptr inbounds i32, i32* %7, i64 1
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %4
20: ; preds = %14, %1
%21 = phi i64 [ 1, %1 ], [ %16, %14 ]
ret i64 %21
}