float chop(float x, int *index) {
  int i;
  static float stptyp[] = {0.0f, 0.1f, 0.2f,  0.25f, 0.3f, 0.4f,
                           0.5f, 0.6f, 0.75f, 0.8f,  1.0f};
  for (i = 0; i < sizeof(stptyp); i++) {
    if (x >= stptyp[i] && x <= stptyp[i + 1]) {
      *index = ++i;
      break;
    }
  }
  return (stptyp[i]);
}


x86 assembly (clang, -O0):
<chop>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x2c,%rax
jae    1186 <chop+0x86>
movss  -0x4(%rbp),%xmm0
movslq -0x14(%rbp),%rcx
lea    0x2efe(%rip),%rax
ucomiss (%rax,%rcx,4),%xmm0
jb     1173 <chop+0x73>
movss  -0x4(%rbp),%xmm1
mov    -0x14(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2edf(%rip),%rax
movss  (%rax,%rcx,4),%xmm0
ucomiss %xmm1,%xmm0
jb     1173 <chop+0x73>
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1186 <chop+0x86>
jmp    1178 <chop+0x78>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1114 <chop+0x14>
movslq -0x14(%rbp),%rcx
lea    0x2e9f(%rip),%rax
movss  (%rax,%rcx,4),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<chop>:
mov    $0x2,%ecx
lea    0xef4(%rip),%rax
jmp    111a <chop+0x1a>
xchg   %ax,%ax
add    $0x2,%rcx
cmp    $0x2e,%rcx
je     113f <chop+0x3f>
ucomiss -0x8(%rax,%rcx,4),%xmm0
jb     112c <chop+0x2c>
movss  -0x4(%rax,%rcx,4),%xmm1
ucomiss %xmm0,%xmm1
jae    114a <chop+0x4a>
ucomiss -0x4(%rax,%rcx,4),%xmm0
jb     1110 <chop+0x10>
movss  (%rax,%rcx,4),%xmm1
ucomiss %xmm0,%xmm1
jb     1110 <chop+0x10>
jmp    114e <chop+0x4e>
mov    $0x2c,%ecx
movss  (%rax,%rcx,4),%xmm0
ret
add    $0xffffffffffffffff,%rcx
mov    %ecx,(%rdi)
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
ret

LLVM IR (-O0):
@chop.stptyp = internal global [11 x float] [float 0.000000e+00, float 0x3FB99999A0000000, float 0x3FC99999A0000000, float 2.500000e-01, float 0x3FD3333340000000, float 0x3FD99999A0000000, float 5.000000e-01, float 0x3FE3333340000000, float 7.500000e-01, float 0x3FE99999A0000000, float 1.000000e+00]
define float @chop(float %0, i32* %1) {
%3 = alloca float
%4 = alloca i32*
%5 = alloca i32
store float %0, float* %3
store i32* %1, i32** %4
store i32 0, i32* %5
br label %6
6: ; preds = %30, %2
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = icmp ult i64 %8, 44
br i1 %9, label %10, label %33
10: ; preds = %6
%11 = load float, float* %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [11 x float], [11 x float]* @chop.stptyp, i64 0, i64 %13
%15 = load float, float* %14
%16 = fcmp oge float %11, %15
br i1 %16, label %17, label %29
17: ; preds = %10
%18 = load float, float* %3
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [11 x float], [11 x float]* @chop.stptyp, i64 0, i64 %21
%23 = load float, float* %22
%24 = fcmp ole float %18, %23
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
%28 = load i32*, i32** %4
store i32 %27, i32* %28
br label %33
29: ; preds = %17, %10
br label %30
30: ; preds = %29
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %6
33: ; preds = %25, %6
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [11 x float], [11 x float]* @chop.stptyp, i64 0, i64 %35
%37 = load float, float* %36
ret float %37
}

LLVM IR (-O2):
@chop.stptyp = internal unnamed_addr constant [11 x float] [float 0.000000e+00, float 0x3FB99999A0000000, float 0x3FC99999A0000000, float 2.500000e-01, float 0x3FD3333340000000, float 0x3FD99999A0000000, float 5.000000e-01, float 0x3FE3333340000000, float 7.500000e-01, float 0x3FE99999A0000000, float 1.000000e+00]
define float @chop(float %0, i32* nocapture writeonly %1) {
br label %3
3: ; preds = %27, %2
%4 = phi i64 [ 0, %2 ], [ %22, %27 ]
%5 = getelementptr inbounds [11 x float], [11 x float]* @chop.stptyp, i64 0, i64 %4
%6 = load float, float* %5
%7 = fcmp ugt float %6, %0
%8 = or i64 %4, 1
br i1 %7, label %18, label %9
9: ; preds = %3
%10 = getelementptr inbounds [11 x float], [11 x float]* @chop.stptyp, i64 0, i64 %8
%11 = load float, float* %10
%12 = fcmp ult float %11, %0
br i1 %12, label %18, label %13
13: ; preds = %23, %9
%14 = phi i64 [ %8, %9 ], [ %22, %23 ]
%15 = trunc i64 %14 to i32
store i32 %15, i32* %1
%16 = shl i64 %14, 32
%17 = ashr exact i64 %16, 32
br label %29
18: ; preds = %3, %9
%19 = getelementptr inbounds [11 x float], [11 x float]* @chop.stptyp, i64 0, i64 %8
%20 = load float, float* %19
%21 = fcmp ugt float %20, %0
%22 = add nuw nsw i64 %4, 2
br i1 %21, label %27, label %23
23: ; preds = %18
%24 = getelementptr inbounds [11 x float], [11 x float]* @chop.stptyp, i64 0, i64 %22
%25 = load float, float* %24
%26 = fcmp ult float %25, %0
br i1 %26, label %27, label %13
27: ; preds = %23, %18
%28 = icmp eq i64 %22, 44
br i1 %28, label %29, label %3
29: ; preds = %27, %13
%30 = phi i64 [ %17, %13 ], [ 44, %27 ]
%31 = getelementptr inbounds [11 x float], [11 x float]* @chop.stptyp, i64 0, i64 %30
%32 = load float, float* %31
ret float %32
}