#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__ chr_cnt(unsigned char const *, int, char);
scalar_t__ chr_range_cnt(unsigned char const *, int, int /*<<< orphan*/, int);
__attribute__((visibility("hidden"))) int
get_eci_length(const int eci, const unsigned char source[], int length) {
  if (eci == 20) {
    length += chr_cnt(source, length, '\\');
  } else if (eci == 25) {
    length += chr_range_cnt(source, length, 0, 0x7F);
  } else if (eci == 29) {
    length *= 2;
  }
  return length;
}


x86 assembly (clang, -O0):
<get_eci_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x14,-0x4(%rbp)
jne    115f <get_eci_length+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x5c,%edx
call   1030 <chr_cnt@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    11ab <get_eci_length+0x8b>
cmpl   $0x19,-0x4(%rbp)
jne    118e <get_eci_length+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %edx,%edx
mov    $0x7f,%ecx
call   1040 <chr_range_cnt@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    11a6 <get_eci_length+0x86>
cmpl   $0x1d,-0x4(%rbp)
jne    11a1 <get_eci_length+0x81>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <get_eci_length+0x86>
jmp    11ab <get_eci_length+0x8b>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_eci_length>:
push   %rbx
mov    %edx,%ebx
cmp    $0x1d,%edi
je     1143 <get_eci_length+0x23>
cmp    $0x19,%edi
je     1147 <get_eci_length+0x27>
cmp    $0x14,%edi
jne    115c <get_eci_length+0x3c>
mov    %rsi,%rdi
mov    %ebx,%esi
mov    $0x5c,%edx
call   1030 <chr_cnt@plt>
jmp    1158 <get_eci_length+0x38>
add    %ebx,%ebx
jmp    115c <get_eci_length+0x3c>
mov    %rsi,%rdi
mov    %ebx,%esi
xor    %edx,%edx
mov    $0x7f,%ecx
call   1040 <chr_range_cnt@plt>
add    %ebx,%eax
mov    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define hidden i32 @get_eci_length(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 20
br i1 %8, label %9, label %17
9: ; preds = %3
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i64 @chr_cnt(i8* %10, i32 %11, i8 signext 92)
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = add nsw i64 %14, %12
%16 = trunc i64 %15 to i32
store i32 %16, i32* %6
br label %36
17: ; preds = %3
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 25
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = call i64 @chr_range_cnt(i8* %21, i32 %22, i32 0, i32 127)
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = add nsw i64 %25, %23
%27 = trunc i64 %26 to i32
store i32 %27, i32* %6
br label %35
28: ; preds = %17
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 29
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %6
%33 = mul nsw i32 %32, 2
store i32 %33, i32* %6
br label %34
34: ; preds = %31, %28
br label %35
35: ; preds = %34, %20
br label %36
36: ; preds = %35, %9
%37 = load i32, i32* %6
ret i32 %37
}

LLVM IR (-O2):
define hidden i32 @get_eci_length(i32 %0, i8* %1, i32 %2) {
switch i32 %0, label %14 [
i32 20, label %4
i32 25, label %8
i32 29, label %12
]
4: ; preds = %3
%5 = tail call i64 @chr_cnt(i8* %1, i32 %2, i8 signext 92)
%6 = trunc i64 %5 to i32
%7 = add i32 %6, %2
br label %14
8: ; preds = %3
%9 = tail call i64 @chr_range_cnt(i8* %1, i32 %2, i32 0, i32 127)
%10 = trunc i64 %9 to i32
%11 = add i32 %10, %2
br label %14
12: ; preds = %3
%13 = shl nsw i32 %2, 1
br label %14
14: ; preds = %3, %8, %12, %4
%15 = phi i32 [ %7, %4 ], [ %11, %8 ], [ %13, %12 ], [ %2, %3 ]
ret i32 %15
}