#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 */
scalar_t__ utf_to_eci(int, unsigned char *, unsigned char *, size_t *);
__attribute__((visibility("hidden"))) int get_best_eci(unsigned char source[],
                                                       size_t length) {
  int eci = 3;
  unsigned char local_source[length + 1];
  do {
    if (utf_to_eci(eci, source, local_source, &length) == 0) {
      return eci;
    }
    eci++;
  } while (eci < 25);
  return 26;
}


x86 assembly (clang, -O0):
<get_best_eci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
mov    -0x18(%rbp),%rdx
mov    %rdx,%rax
add    $0x1,%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
add    $0x10,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdx
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rcx
call   1030 <utf_to_eci@plt>
cmp    $0x0,%rax
jne    1182 <get_best_eci+0x72>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11a3 <get_best_eci+0x93>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x19,-0x1c(%rbp)
jl     1152 <get_best_eci+0x42>
movl   $0x1a,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_best_eci>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    %rsi,-0x28(%rbp)
mov    %rsp,%r15
add    $0x10,%rsi
and    $0xfffffffffffffff0,%rsi
sub    %rsi,%r15
mov    %r15,%rsp
mov    $0x3,%ebx
lea    -0x28(%rbp),%r12
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1030 <utf_to_eci@plt>
test   %rax,%rax
je     1162 <get_best_eci+0x52>
add    $0x1,%ebx
cmp    $0x19,%ebx
jne    1140 <get_best_eci+0x30>
mov    $0x1a,%ebx
mov    %ebx,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define hidden i32 @get_best_eci(i8* %0, i64 %1) {
%3 = alloca i64
store i64 %1, i64* %3
%4 = add i64 %1, 1
%5 = alloca i8, i64 %4
br label %6
6: ; preds = %10, %2
%7 = phi i32 [ 3, %2 ], [ %11, %10 ]
%8 = call i64 @utf_to_eci(i32 %7, i8* %0, i8* %5, i64* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = add nuw nsw i32 %7, 1
%12 = icmp eq i32 %11, 25
br i1 %12, label %13, label %6
13: ; preds = %10, %6
%14 = phi i32 [ %7, %6 ], [ 26, %10 ]
ret i32 %14
}