#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 *, int *);
int get_best_eci(unsigned char source[], int 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    %esi,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rcx
call   1030 <utf_to_eci@plt>
cmp    $0x0,%rax
jne    117f <get_best_eci+0x6f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11a0 <get_best_eci+0x90>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x19,-0x18(%rbp)
jl     114f <get_best_eci+0x3f>
movl   $0x1a,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%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    %esi,-0x24(%rbp)
add    $0x1,%esi
mov    %rsp,%r15
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
sub    %rsi,%r15
mov    %r15,%rsp
mov    $0x3,%ebx
lea    -0x24(%rbp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1030 <utf_to_eci@plt>
test   %rax,%rax
je     1172 <get_best_eci+0x62>
add    $0x1,%ebx
cmp    $0x19,%ebx
jne    1150 <get_best_eci+0x40>
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 i32 @get_best_eci(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 3, i32* %6
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
br label %15
15: ; preds = %25, %2
%16 = load i32, i32* %6
%17 = load i8*, i8** %4
%18 = call i64 @utf_to_eci(i32 %16, i8* %17, i8* %14, i32* %5)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32, i32* %6
store i32 %21, i32* %3
store i32 1, i32* %9
br label %29
22: ; preds = %15
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %25
25: ; preds = %22
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 25
br i1 %27, label %15, label %28
28: ; preds = %25
store i32 26, i32* %3
store i32 1, i32* %9
br label %29
29: ; preds = %28, %20
%30 = load i8*, i8** %7
%31 = load i32, i32* %3
ret i32 %31
}

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