int find_cutoff_point(histogram, percent, cutoff, rows, cols)
unsigned long histogram[];
float percent;
long cols, rows;
short *cutoff;
{
  float fd, fsum, sum_div;
  int i, looking;
  long lc, lr, num = 0, sum = 0;
  sum = 0;
  i = 0;
  lr = (long)(rows);
  lc = (long)(cols);
  num = lr * lc;
  fd = (float)(num);
  while (looking) {
    fsum = (float)(sum);
    sum_div = fsum / fd;
    if (sum_div >= percent)
      looking = 0;
    else
      sum = sum + histogram[i++];
  }
  if (i >= (255 + 1))
    i = 255;
  *cutoff = i;
  printf("\nCutoff is %d sum=%ld", *cutoff, sum);
  return (1);
}


x86 assembly (clang, -O0):
<find_cutoff_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
cvtsd2ss %xmm0,%xmm0
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x60(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%rax
imul   -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
cvtsi2ssq -0x58(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11da <find_cutoff_point+0xca>
cvtsi2ssq -0x60(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
divss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
ucomiss -0xc(%rbp),%xmm0
jb     11b7 <find_cutoff_point+0xa7>
movl   $0x0,-0x3c(%rbp)
jmp    11d5 <find_cutoff_point+0xc5>
mov    -0x60(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x38(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0x38(%rbp)
movslq %edx,%rdx
add    (%rcx,%rdx,8),%rax
mov    %rax,-0x60(%rbp)
jmp    1178 <find_cutoff_point+0x68>
cmpl   $0x100,-0x38(%rbp)
jl     11ee <find_cutoff_point+0xde>
movl   $0xff,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x18(%rbp),%rax
movswl (%rax),%esi
mov    -0x60(%rbp),%rdx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_cutoff_point>:
push   %rax
movw   $0x0,(%rsi)
lea    0xee3(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"\0ACutoff is %d sum=%ld\00"
define i32 @find_cutoff_point(i64* %0, double %1, i16* %2, i64 %3, i64 %4) {
%6 = alloca i64*
%7 = alloca float
%8 = alloca i16*
%9 = alloca i64
%10 = alloca i64
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = fptrunc double %1 to float
store i64* %0, i64** %6
store float %20, float* %7
store i16* %2, i16** %8
store i64 %3, i64* %9
store i64 %4, i64* %10
store i64 0, i64* %18
store i64 0, i64* %19
store i64 0, i64* %19
store i32 0, i32* %14
%21 = load i64, i64* %9
store i64 %21, i64* %17
%22 = load i64, i64* %10
store i64 %22, i64* %16
%23 = load i64, i64* %17
%24 = load i64, i64* %16
%25 = mul nsw i64 %23, %24
store i64 %25, i64* %18
%26 = load i64, i64* %18
%27 = sitofp i64 %26 to float
store float %27, float* %11
br label %28
28: ; preds = %50, %5
%29 = load i32, i32* %15
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %51
31: ; preds = %28
%32 = load i64, i64* %19
%33 = sitofp i64 %32 to float
store float %33, float* %12
%34 = load float, float* %12
%35 = load float, float* %11
%36 = fdiv float %34, %35
store float %36, float* %13
%37 = load float, float* %13
%38 = load float, float* %7
%39 = fcmp oge float %37, %38
br i1 %39, label %40, label %41
40: ; preds = %31
store i32 0, i32* %15
br label %50
41: ; preds = %31
%42 = load i64, i64* %19
%43 = load i64*, i64** %6
%44 = load i32, i32* %14
%45 = add nsw i32 %44, 1
store i32 %45, i32* %14
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds i64, i64* %43, i64 %46
%48 = load i64, i64* %47
%49 = add i64 %42, %48
store i64 %49, i64* %19
br label %50
50: ; preds = %41, %40
br label %28
51: ; preds = %28
%52 = load i32, i32* %14
%53 = icmp sge i32 %52, 256
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 255, i32* %14
br label %55
55: ; preds = %54, %51
%56 = load i32, i32* %14
%57 = trunc i32 %56 to i16
%58 = load i16*, i16** %8
store i16 %57, i16* %58
%59 = load i16*, i16** %8
%60 = load i16, i16* %59
%61 = sext i16 %60 to i32
%62 = load i64, i64* %19
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %61, i64 %62)
ret i32 1
}

LLVM IR (-O2):
@.str = [22 x i8] c"\0ACutoff is %d sum=%ld\00"
define i32 @find_cutoff_point(i64* nocapture readnone %0, double %1, i16* nocapture writeonly %2, i64 %3, i64 %4) {
store i16 0, i16* %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 0, i64 0)
ret i32 1
}