#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 count_encoded_length(size_t n, size_t prefix) {
  size_t k = (size_t)((1 << prefix) - 1);
  size_t len = 0;
  if (n < k) {
    return 1;
  }
  n -= k;
  ++len;
  for (; n >= 128; n >>= 7, ++len)
    ;
  return len + 1;
}


x86 assembly (clang, -O0):
<count_encoded_length>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1145 <count_encoded_length+0x45>
movq   $0x1,-0x8(%rbp)
jmp    119c <count_encoded_length+0x9c>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x80,-0x10(%rbp)
jb     1190 <count_encoded_length+0x90>
jmp    1173 <count_encoded_length+0x73>
mov    -0x10(%rbp),%rax
shr    $0x7,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1160 <count_encoded_length+0x60>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_encoded_length>:
mov    %rsi,%rcx
mov    $0xffffffff,%eax
shl    %cl,%eax
not    %eax
movslq %eax,%rcx
mov    $0x1,%eax
cmp    %rdi,%rcx
ja     1154 <count_encoded_length+0x54>
sub    %rcx,%rdi
mov    $0x2,%eax
cmp    $0x80,%rdi
jb     1154 <count_encoded_length+0x54>
mov    $0x2,%eax
mov    %rdi,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
shr    $0x7,%rcx
add    $0x1,%rax
cmp    $0x3fff,%rdi
mov    %rcx,%rdi
ja     1140 <count_encoded_length+0x40>
ret

LLVM IR (-O0):
define i64 @count_encoded_length(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%8 = load i64, i64* %5
%9 = trunc i64 %8 to i32
%10 = shl i32 1, %9
%11 = sub nsw i32 %10, 1
%12 = sext i32 %11 to i64
store i64 %12, i64* %6
store i64 0, i64* %7
%13 = load i64, i64* %4
%14 = load i64, i64* %6
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %2
store i64 1, i64* %3
br label %35
17: ; preds = %2
%18 = load i64, i64* %6
%19 = load i64, i64* %4
%20 = sub i64 %19, %18
store i64 %20, i64* %4
%21 = load i64, i64* %7
%22 = add i64 %21, 1
store i64 %22, i64* %7
br label %23
23: ; preds = %27, %17
%24 = load i64, i64* %4
%25 = icmp uge i64 %24, 128
br i1 %25, label %26, label %32
26: ; preds = %23
br label %27
27: ; preds = %26
%28 = load i64, i64* %4
%29 = lshr i64 %28, 7
store i64 %29, i64* %4
%30 = load i64, i64* %7
%31 = add i64 %30, 1
store i64 %31, i64* %7
br label %23
32: ; preds = %23
%33 = load i64, i64* %7
%34 = add i64 %33, 1
store i64 %34, i64* %3
br label %35
35: ; preds = %32, %16
%36 = load i64, i64* %3
ret i64 %36
}

LLVM IR (-O2):
define i64 @count_encoded_length(i64 %0, i64 %1) {
%3 = trunc i64 %1 to i32
%4 = shl nsw i32 -1, %3
%5 = xor i32 %4, -1
%6 = sext i32 %5 to i64
%7 = icmp ugt i64 %6, %0
br i1 %7, label %17, label %8
8: ; preds = %2
%9 = sub i64 %0, %6
%10 = icmp ugt i64 %9, 127
br i1 %10, label %11, label %17
11: ; preds = %8, %11
%12 = phi i64 [ %15, %11 ], [ 2, %8 ]
%13 = phi i64 [ %14, %11 ], [ %9, %8 ]
%14 = lshr i64 %13, 7
%15 = add nuw nsw i64 %12, 1
%16 = icmp ugt i64 %13, 16383
br i1 %16, label %11, label %17
17: ; preds = %11, %8, %2
%18 = phi i64 [ 1, %2 ], [ 2, %8 ], [ %15, %11 ]
ret i64 %18
}