unsigned int amplitude2bargraph(int input) {
  if (input < 0) {
    input = -input;
  }
  if (input > 23166) {
    return (0xFFFF);
  } else if (input > 16384) {
    return (0xFFFF);
  } else if (input > 11583) {
    return (0xFFFF);
  } else if (input > 8192) {
    return (0xFFFF);
  } else if (input > 5791) {
    return (0xFFFF);
  } else if (input > 4096) {
    return (0xFFFF);
  } else if (input > 2896) {
    return (0xFFFF);
  } else if (input > 2048) {
    return (0xFFFF);
  } else if (input > 1448) {
    return (0xFFFF);
  } else if (input > 1024) {
    return (0xFFFE);
  } else if (input > 724) {
    return (0xFFFC);
  } else if (input > 512) {
    return (0xFFF8);
  } else if (input > 362) {
    return (0xFFF0);
  } else if (input > 256) {
    return (0xFFE0);
  } else if (input > 181) {
    return (0xFFC0);
  } else if (input > 128) {
    return (0xFF80);
  } else if (input > 90) {
    return (0xFF00);
  } else if (input > 64) {
    return (0xFE00);
  } else if (input > 45) {
    return (0xFC00);
  } else if (input > 32) {
    return (0xF800);
  } else if (input > 22) {
    return (0xF000);
  } else if (input > 16) {
    return (0xE000);
  } else if (input > 11) {
    return (0xC000);
  } else if (input > 8) {
    return (0x8000);
  } else {
    return (0);
  }
}


x86 assembly (clang, -O0):
<amplitude2bargraph>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1119 <amplitude2bargraph+0x19>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x5a7e,-0x8(%rbp)
jle    1132 <amplitude2bargraph+0x32>
movl   $0xffff,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x4000,-0x8(%rbp)
jle    114b <amplitude2bargraph+0x4b>
movl   $0xffff,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x2d3f,-0x8(%rbp)
jle    1164 <amplitude2bargraph+0x64>
movl   $0xffff,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x2000,-0x8(%rbp)
jle    117d <amplitude2bargraph+0x7d>
movl   $0xffff,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x169f,-0x8(%rbp)
jle    1196 <amplitude2bargraph+0x96>
movl   $0xffff,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x1000,-0x8(%rbp)
jle    11af <amplitude2bargraph+0xaf>
movl   $0xffff,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0xb50,-0x8(%rbp)
jle    11c8 <amplitude2bargraph+0xc8>
movl   $0xffff,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x800,-0x8(%rbp)
jle    11e1 <amplitude2bargraph+0xe1>
movl   $0xffff,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x5a8,-0x8(%rbp)
jle    11fa <amplitude2bargraph+0xfa>
movl   $0xffff,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x400,-0x8(%rbp)
jle    1213 <amplitude2bargraph+0x113>
movl   $0xfffe,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x2d4,-0x8(%rbp)
jle    122c <amplitude2bargraph+0x12c>
movl   $0xfffc,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x200,-0x8(%rbp)
jle    1245 <amplitude2bargraph+0x145>
movl   $0xfff8,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x16a,-0x8(%rbp)
jle    125e <amplitude2bargraph+0x15e>
movl   $0xfff0,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x100,-0x8(%rbp)
jle    1277 <amplitude2bargraph+0x177>
movl   $0xffe0,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0xb5,-0x8(%rbp)
jle    1290 <amplitude2bargraph+0x190>
movl   $0xffc0,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x80,-0x8(%rbp)
jle    12a9 <amplitude2bargraph+0x1a9>
movl   $0xff80,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x5a,-0x8(%rbp)
jle    12bf <amplitude2bargraph+0x1bf>
movl   $0xff00,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x40,-0x8(%rbp)
jle    12d5 <amplitude2bargraph+0x1d5>
movl   $0xfe00,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x2d,-0x8(%rbp)
jle    12eb <amplitude2bargraph+0x1eb>
movl   $0xfc00,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x20,-0x8(%rbp)
jle    1301 <amplitude2bargraph+0x201>
movl   $0xf800,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x16,-0x8(%rbp)
jle    1317 <amplitude2bargraph+0x217>
movl   $0xf000,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x10,-0x8(%rbp)
jle    132d <amplitude2bargraph+0x22d>
movl   $0xe000,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0xb,-0x8(%rbp)
jle    1343 <amplitude2bargraph+0x243>
movl   $0xc000,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
cmpl   $0x8,-0x8(%rbp)
jle    1359 <amplitude2bargraph+0x259>
movl   $0x8000,-0x4(%rbp)
jmp    1360 <amplitude2bargraph+0x260>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<amplitude2bargraph>:
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
mov    $0xffff,%eax
cmp    $0x5a8,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xfffe,%eax
cmp    $0x400,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xfffc,%eax
cmp    $0x2d4,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xfff8,%eax
cmp    $0x200,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xfff0,%eax
cmp    $0x16a,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xffe0,%eax
cmp    $0x100,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xffc0,%eax
cmp    $0xb5,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xff80,%eax
cmp    $0x80,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xff00,%eax
cmp    $0x5a,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xfe00,%eax
cmp    $0x40,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xfc00,%eax
cmp    $0x2d,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xf800,%eax
cmp    $0x20,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xf000,%eax
cmp    $0x16,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xe000,%eax
cmp    $0x10,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
mov    $0xc000,%eax
cmp    $0xb,%ecx
ja     11d0 <amplitude2bargraph+0xd0>
xor    %eax,%eax
cmp    $0x9,%ecx
setae  %al
shl    $0xf,%eax
ret

LLVM IR (-O0):
define i32 @amplitude2bargraph(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %3
%8 = sub nsw i32 0, %7
store i32 %8, i32* %3
br label %9
9: ; preds = %6, %1
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 23166
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 65535, i32* %2
br label %106
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 16384
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 65535, i32* %2
br label %106
17: ; preds = %13
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 11583
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 65535, i32* %2
br label %106
21: ; preds = %17
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, 8192
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 65535, i32* %2
br label %106
25: ; preds = %21
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, 5791
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 65535, i32* %2
br label %106
29: ; preds = %25
%30 = load i32, i32* %3
%31 = icmp sgt i32 %30, 4096
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 65535, i32* %2
br label %106
33: ; preds = %29
%34 = load i32, i32* %3
%35 = icmp sgt i32 %34, 2896
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 65535, i32* %2
br label %106
37: ; preds = %33
%38 = load i32, i32* %3
%39 = icmp sgt i32 %38, 2048
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 65535, i32* %2
br label %106
41: ; preds = %37
%42 = load i32, i32* %3
%43 = icmp sgt i32 %42, 1448
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 65535, i32* %2
br label %106
45: ; preds = %41
%46 = load i32, i32* %3
%47 = icmp sgt i32 %46, 1024
br i1 %47, label %48, label %49
48: ; preds = %45
store i32 65534, i32* %2
br label %106
49: ; preds = %45
%50 = load i32, i32* %3
%51 = icmp sgt i32 %50, 724
br i1 %51, label %52, label %53
52: ; preds = %49
store i32 65532, i32* %2
br label %106
53: ; preds = %49
%54 = load i32, i32* %3
%55 = icmp sgt i32 %54, 512
br i1 %55, label %56, label %57
56: ; preds = %53
store i32 65528, i32* %2
br label %106
57: ; preds = %53
%58 = load i32, i32* %3
%59 = icmp sgt i32 %58, 362
br i1 %59, label %60, label %61
60: ; preds = %57
store i32 65520, i32* %2
br label %106
61: ; preds = %57
%62 = load i32, i32* %3
%63 = icmp sgt i32 %62, 256
br i1 %63, label %64, label %65
64: ; preds = %61
store i32 65504, i32* %2
br label %106
65: ; preds = %61
%66 = load i32, i32* %3
%67 = icmp sgt i32 %66, 181
br i1 %67, label %68, label %69
68: ; preds = %65
store i32 65472, i32* %2
br label %106
69: ; preds = %65
%70 = load i32, i32* %3
%71 = icmp sgt i32 %70, 128
br i1 %71, label %72, label %73
72: ; preds = %69
store i32 65408, i32* %2
br label %106
73: ; preds = %69
%74 = load i32, i32* %3
%75 = icmp sgt i32 %74, 90
br i1 %75, label %76, label %77
76: ; preds = %73
store i32 65280, i32* %2
br label %106
77: ; preds = %73
%78 = load i32, i32* %3
%79 = icmp sgt i32 %78, 64
br i1 %79, label %80, label %81
80: ; preds = %77
store i32 65024, i32* %2
br label %106
81: ; preds = %77
%82 = load i32, i32* %3
%83 = icmp sgt i32 %82, 45
br i1 %83, label %84, label %85
84: ; preds = %81
store i32 64512, i32* %2
br label %106
85: ; preds = %81
%86 = load i32, i32* %3
%87 = icmp sgt i32 %86, 32
br i1 %87, label %88, label %89
88: ; preds = %85
store i32 63488, i32* %2
br label %106
89: ; preds = %85
%90 = load i32, i32* %3
%91 = icmp sgt i32 %90, 22
br i1 %91, label %92, label %93
92: ; preds = %89
store i32 61440, i32* %2
br label %106
93: ; preds = %89
%94 = load i32, i32* %3
%95 = icmp sgt i32 %94, 16
br i1 %95, label %96, label %97
96: ; preds = %93
store i32 57344, i32* %2
br label %106
97: ; preds = %93
%98 = load i32, i32* %3
%99 = icmp sgt i32 %98, 11
br i1 %99, label %100, label %101
100: ; preds = %97
store i32 49152, i32* %2
br label %106
101: ; preds = %97
%102 = load i32, i32* %3
%103 = icmp sgt i32 %102, 8
br i1 %103, label %104, label %105
104: ; preds = %101
store i32 32768, i32* %2
br label %106
105: ; preds = %101
store i32 0, i32* %2
br label %106
106: ; preds = %105, %104, %100, %96, %92, %88, %84, %80, %76, %72, %68, %64, %60, %56, %52, %48, %44, %40, %36, %32, %28, %24, %20, %16, %12
%107 = load i32, i32* %2
ret i32 %107
}

LLVM IR (-O2):
define i32 @amplitude2bargraph(i32 %0) {
%2 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%3 = icmp ugt i32 %2, 1448
br i1 %3, label %35, label %4
4: ; preds = %1
%5 = icmp ugt i32 %2, 1024
br i1 %5, label %35, label %6
6: ; preds = %4
%7 = icmp ugt i32 %2, 724
br i1 %7, label %35, label %8
8: ; preds = %6
%9 = icmp ugt i32 %2, 512
br i1 %9, label %35, label %10
10: ; preds = %8
%11 = icmp ugt i32 %2, 362
br i1 %11, label %35, label %12
12: ; preds = %10
%13 = icmp ugt i32 %2, 256
br i1 %13, label %35, label %14
14: ; preds = %12
%15 = icmp ugt i32 %2, 181
br i1 %15, label %35, label %16
16: ; preds = %14
%17 = icmp ugt i32 %2, 128
br i1 %17, label %35, label %18
18: ; preds = %16
%19 = icmp ugt i32 %2, 90
br i1 %19, label %35, label %20
20: ; preds = %18
%21 = icmp ugt i32 %2, 64
br i1 %21, label %35, label %22
22: ; preds = %20
%23 = icmp ugt i32 %2, 45
br i1 %23, label %35, label %24
24: ; preds = %22
%25 = icmp ugt i32 %2, 32
br i1 %25, label %35, label %26
26: ; preds = %24
%27 = icmp ugt i32 %2, 22
br i1 %27, label %35, label %28
28: ; preds = %26
%29 = icmp ugt i32 %2, 16
br i1 %29, label %35, label %30
30: ; preds = %28
%31 = icmp ugt i32 %2, 11
br i1 %31, label %35, label %32
32: ; preds = %30
%33 = icmp ugt i32 %2, 8
%34 = select i1 %33, i32 32768, i32 0
br label %35
35: ; preds = %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10, %8, %6, %4, %1
%36 = phi i32 [ 65535, %1 ], [ 65534, %4 ], [ 65532, %6 ], [ 65528, %8 ], [ 65520, %10 ], [ 65504, %12 ], [ 65472, %14 ], [ 65408, %16 ], [ 65280, %18 ], [ 65024, %20 ], [ 64512, %22 ], [ 63488, %24 ], [ 61440, %26 ], [ 57344, %28 ], [ 49152, %30 ], [ %34, %32 ]
ret i32 %36
}