#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 */
typedef int uint;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
uint costOfLength(uint len) {
  if (len == 1)
    return 1;
  if (len >= 2 && len <= 3)
    return 3;
  if (len >= 4 && len <= 7)
    return 5;
  if (len >= 8 && len <= 15)
    return 7;
  if (len >= 16 && len <= 31)
    return 9;
  if (len >= 32 && len <= 63)
    return 11;
  if (len >= 64 && len <= 127)
    return 13;
  if (len >= 128 && len <= 255)
    return 14;
  printf("costOfLength got wrong value: %i\n", len);
  return 10000;
}


x86 assembly (clang, -O0):
<costOfLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1131 <costOfLength+0x21>
movl   $0x1,-0x4(%rbp)
jmp    122d <costOfLength+0x11d>
cmpl   $0x2,-0x8(%rbp)
jl     1151 <costOfLength+0x41>
cmpl   $0x3,-0x8(%rbp)
jg     1151 <costOfLength+0x41>
movl   $0x3,-0x4(%rbp)
jmp    122d <costOfLength+0x11d>
cmpl   $0x4,-0x8(%rbp)
jl     1171 <costOfLength+0x61>
cmpl   $0x7,-0x8(%rbp)
jg     1171 <costOfLength+0x61>
movl   $0x5,-0x4(%rbp)
jmp    122d <costOfLength+0x11d>
cmpl   $0x8,-0x8(%rbp)
jl     1191 <costOfLength+0x81>
cmpl   $0xf,-0x8(%rbp)
jg     1191 <costOfLength+0x81>
movl   $0x7,-0x4(%rbp)
jmp    122d <costOfLength+0x11d>
cmpl   $0x10,-0x8(%rbp)
jl     11b1 <costOfLength+0xa1>
cmpl   $0x1f,-0x8(%rbp)
jg     11b1 <costOfLength+0xa1>
movl   $0x9,-0x4(%rbp)
jmp    122d <costOfLength+0x11d>
cmpl   $0x20,-0x8(%rbp)
jl     11d1 <costOfLength+0xc1>
cmpl   $0x3f,-0x8(%rbp)
jg     11d1 <costOfLength+0xc1>
movl   $0xb,-0x4(%rbp)
jmp    122d <costOfLength+0x11d>
cmpl   $0x40,-0x8(%rbp)
jl     11f1 <costOfLength+0xe1>
cmpl   $0x7f,-0x8(%rbp)
jg     11f1 <costOfLength+0xe1>
movl   $0xd,-0x4(%rbp)
jmp    122d <costOfLength+0x11d>
cmpl   $0x80,-0x8(%rbp)
jl     1217 <costOfLength+0x107>
cmpl   $0xff,-0x8(%rbp)
jg     1217 <costOfLength+0x107>
movl   $0xe,-0x4(%rbp)
jmp    122d <costOfLength+0x11d>
mov    -0x8(%rbp),%esi
lea    0xddf(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2710,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<costOfLength>:
mov    $0x1,%eax
cmp    $0x1,%edi
je     11a2 <costOfLength+0x92>
mov    %edi,%esi
mov    %edi,%ecx
and    $0xfffffffe,%ecx
mov    $0x3,%eax
cmp    $0x2,%ecx
je     11a2 <costOfLength+0x92>
mov    %esi,%ecx
and    $0xfffffffc,%ecx
mov    $0x5,%eax
cmp    $0x4,%ecx
je     11a2 <costOfLength+0x92>
mov    %esi,%ecx
and    $0xfffffff8,%ecx
mov    $0x7,%eax
cmp    $0x8,%ecx
je     11a2 <costOfLength+0x92>
mov    %esi,%ecx
and    $0xfffffff0,%ecx
mov    $0x9,%eax
cmp    $0x10,%ecx
je     11a2 <costOfLength+0x92>
mov    %esi,%ecx
and    $0xffffffe0,%ecx
mov    $0xb,%eax
cmp    $0x20,%ecx
je     11a2 <costOfLength+0x92>
mov    %esi,%ecx
and    $0xffffffc0,%ecx
mov    $0xd,%eax
cmp    $0x40,%ecx
je     11a2 <costOfLength+0x92>
mov    %esi,%ecx
and    $0xffffff80,%ecx
mov    $0xe,%eax
cmp    $0x80,%ecx
je     11a2 <costOfLength+0x92>
push   %rax
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2710,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"costOfLength got wrong value: %i\0A\00"
define i32 @costOfLength(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 1, i32* %2
br label %59
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp sge i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* %3
%12 = icmp sle i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 3, i32* %2
br label %59
14: ; preds = %10, %7
%15 = load i32, i32* %3
%16 = icmp sge i32 %15, 4
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %3
%19 = icmp sle i32 %18, 7
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 5, i32* %2
br label %59
21: ; preds = %17, %14
%22 = load i32, i32* %3
%23 = icmp sge i32 %22, 8
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %3
%26 = icmp sle i32 %25, 15
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 7, i32* %2
br label %59
28: ; preds = %24, %21
%29 = load i32, i32* %3
%30 = icmp sge i32 %29, 16
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* %3
%33 = icmp sle i32 %32, 31
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 9, i32* %2
br label %59
35: ; preds = %31, %28
%36 = load i32, i32* %3
%37 = icmp sge i32 %36, 32
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i32, i32* %3
%40 = icmp sle i32 %39, 63
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 11, i32* %2
br label %59
42: ; preds = %38, %35
%43 = load i32, i32* %3
%44 = icmp sge i32 %43, 64
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* %3
%47 = icmp sle i32 %46, 127
br i1 %47, label %48, label %49
48: ; preds = %45
store i32 13, i32* %2
br label %59
49: ; preds = %45, %42
%50 = load i32, i32* %3
%51 = icmp sge i32 %50, 128
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i32, i32* %3
%54 = icmp sle i32 %53, 255
br i1 %54, label %55, label %56
55: ; preds = %52
store i32 14, i32* %2
br label %59
56: ; preds = %52, %49
%57 = load i32, i32* %3
%58 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %57)
store i32 10000, i32* %2
br label %59
59: ; preds = %56, %55, %48, %41, %34, %27, %20, %13, %6
%60 = load i32, i32* %2
ret i32 %60
}

LLVM IR (-O2):
@.str = [34 x i8] c"costOfLength got wrong value: %i\0A\00"
define i32 @costOfLength(i32 %0) {
%2 = icmp eq i32 %0, 1
br i1 %2, label %26, label %3
3: ; preds = %1
%4 = and i32 %0, -2
%5 = icmp eq i32 %4, 2
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = and i32 %0, -4
%8 = icmp eq i32 %7, 4
br i1 %8, label %26, label %9
9: ; preds = %6
%10 = and i32 %0, -8
%11 = icmp eq i32 %10, 8
br i1 %11, label %26, label %12
12: ; preds = %9
%13 = and i32 %0, -16
%14 = icmp eq i32 %13, 16
br i1 %14, label %26, label %15
15: ; preds = %12
%16 = and i32 %0, -32
%17 = icmp eq i32 %16, 32
br i1 %17, label %26, label %18
18: ; preds = %15
%19 = and i32 %0, -64
%20 = icmp eq i32 %19, 64
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = and i32 %0, -128
%23 = icmp eq i32 %22, 128
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %26
26: ; preds = %21, %18, %15, %12, %9, %6, %3, %1, %24
%27 = phi i32 [ 10000, %24 ], [ 1, %1 ], [ 3, %3 ], [ 5, %6 ], [ 7, %9 ], [ 9, %12 ], [ 11, %15 ], [ 13, %18 ], [ 14, %21 ]
ret i32 %27
}