#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 costOfOffset(uint offset, uint len) {
  if (len == 1) {
    if (((offset) >= 0 && (offset) < (1 << 3)))
      return 3;
    if (((offset) >= (1 << 3) && (offset) < (1 << 6)))
      return 6;
    if (((offset) >= (1 << 6) && (offset) < (1 << 8)))
      return 8;
    if (((offset) >= (1 << 8) && (offset) < (1 << 10)))
      return 10;
  } else {
    if (((offset) >= 0 && (offset) < (1 << 4)))
      return 4;
    if (((offset) >= (1 << 4) && (offset) < (1 << 7)))
      return 7;
    if (((offset) >= (1 << 7) && (offset) < (1 << 10)))
      return 10;
    if (((offset) >= (1 << 10) && (offset) < (1 << 13)))
      return 13;
  }
  printf("costOfOffset got wrong offset: %i\n", offset);
  return 10000;
}


x86 assembly (clang, -O0):
<costOfOffset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11b6 <costOfOffset+0xa6>
cmpl   $0x0,-0x8(%rbp)
jl     1148 <costOfOffset+0x38>
cmpl   $0x8,-0x8(%rbp)
jge    1148 <costOfOffset+0x38>
movl   $0x3,-0x4(%rbp)
jmp    1260 <costOfOffset+0x150>
cmpl   $0x8,-0x8(%rbp)
jl     1168 <costOfOffset+0x58>
cmpl   $0x40,-0x8(%rbp)
jge    1168 <costOfOffset+0x58>
movl   $0x6,-0x4(%rbp)
jmp    1260 <costOfOffset+0x150>
cmpl   $0x40,-0x8(%rbp)
jl     118b <costOfOffset+0x7b>
cmpl   $0x100,-0x8(%rbp)
jge    118b <costOfOffset+0x7b>
movl   $0x8,-0x4(%rbp)
jmp    1260 <costOfOffset+0x150>
cmpl   $0x100,-0x8(%rbp)
jl     11b1 <costOfOffset+0xa1>
cmpl   $0x400,-0x8(%rbp)
jge    11b1 <costOfOffset+0xa1>
movl   $0xa,-0x4(%rbp)
jmp    1260 <costOfOffset+0x150>
jmp    124a <costOfOffset+0x13a>
cmpl   $0x0,-0x8(%rbp)
jl     11d6 <costOfOffset+0xc6>
cmpl   $0x10,-0x8(%rbp)
jge    11d6 <costOfOffset+0xc6>
movl   $0x4,-0x4(%rbp)
jmp    1260 <costOfOffset+0x150>
cmpl   $0x10,-0x8(%rbp)
jl     11f9 <costOfOffset+0xe9>
cmpl   $0x80,-0x8(%rbp)
jge    11f9 <costOfOffset+0xe9>
movl   $0x7,-0x4(%rbp)
jmp    1260 <costOfOffset+0x150>
cmpl   $0x80,-0x8(%rbp)
jl     121f <costOfOffset+0x10f>
cmpl   $0x400,-0x8(%rbp)
jge    121f <costOfOffset+0x10f>
movl   $0xa,-0x4(%rbp)
jmp    1260 <costOfOffset+0x150>
cmpl   $0x400,-0x8(%rbp)
jl     1245 <costOfOffset+0x135>
cmpl   $0x2000,-0x8(%rbp)
jge    1245 <costOfOffset+0x135>
movl   $0xd,-0x4(%rbp)
jmp    1260 <costOfOffset+0x150>
jmp    124a <costOfOffset+0x13a>
mov    -0x8(%rbp),%esi
lea    0xdac(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2710,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<costOfOffset>:
mov    %edi,%ecx
cmp    $0x1,%esi
jne    1152 <costOfOffset+0x42>
mov    $0x3,%eax
cmp    $0x8,%ecx
jb     1151 <costOfOffset+0x41>
lea    -0x8(%rcx),%edx
mov    $0x6,%eax
cmp    $0x38,%edx
jb     1151 <costOfOffset+0x41>
lea    -0x40(%rcx),%edx
mov    $0x8,%eax
cmp    $0xc0,%edx
jb     1151 <costOfOffset+0x41>
lea    -0x100(%rcx),%edx
mov    $0xa,%eax
cmp    $0x300,%edx
jae    118c <costOfOffset+0x7c>
ret
mov    $0x4,%eax
cmp    $0x10,%ecx
jb     1151 <costOfOffset+0x41>
lea    -0x10(%rcx),%edx
mov    $0x7,%eax
cmp    $0x70,%edx
jb     1151 <costOfOffset+0x41>
lea    -0x80(%rcx),%edx
mov    $0xa,%eax
cmp    $0x380,%edx
jb     1151 <costOfOffset+0x41>
lea    -0x400(%rcx),%edx
mov    $0xd,%eax
cmp    $0x1c00,%edx
jb     1151 <costOfOffset+0x41>
push   %rax
lea    0xe6c(%rip),%rdi
mov    %ecx,%esi
call   1030 <printf@plt>
mov    $0x2710,%eax
add    $0x8,%rsp
ret

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

LLVM IR (-O2):
@.str = [35 x i8] c"costOfOffset got wrong offset: %i\0A\00"
define i32 @costOfOffset(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 1
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = icmp ult i32 %0, 8
br i1 %5, label %28, label %6
6: ; preds = %4
%7 = add i32 %0, -8
%8 = icmp ult i32 %7, 56
br i1 %8, label %28, label %9
9: ; preds = %6
%10 = add i32 %0, -64
%11 = icmp ult i32 %10, 192
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = add i32 %0, -256
%14 = icmp ult i32 %13, 768
br i1 %14, label %28, label %26
15: ; preds = %2
%16 = icmp ult i32 %0, 16
br i1 %16, label %28, label %17
17: ; preds = %15
%18 = add i32 %0, -16
%19 = icmp ult i32 %18, 112
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = add i32 %0, -128
%22 = icmp ult i32 %21, 896
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = add i32 %0, -1024
%25 = icmp ult i32 %24, 7168
br i1 %25, label %28, label %26
26: ; preds = %23, %12
%27 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %28
28: ; preds = %23, %20, %17, %15, %12, %9, %6, %4, %26
%29 = phi i32 [ 10000, %26 ], [ 3, %4 ], [ 6, %6 ], [ 8, %9 ], [ 10, %12 ], [ 4, %15 ], [ 7, %17 ], [ 10, %20 ], [ 13, %23 ]
ret i32 %29
}