int peak_threshold_segmentation(the_image, out_image, value, segment, rows,
                                cols)
int rows, cols, segment;
short **the_image, **out_image, value;
{
  int peak1, peak2;
  short hi, low;
  unsigned long histogram[255 + 1];
  zero_histogram(histogram, 255 + 1);
  calculate_histogram(the_image, histogram, rows, cols);
  smooth_histogram(histogram, 255 + 1);
  find_peaks(histogram, &peak1, &peak2);
  peaks_high_low(histogram, peak1, peak2, &hi, &low);
  printf("\nPTS> hi=%d low=%d\n", hi, low);
  threshold_image_array(the_image, out_image, hi, low, value, rows, cols);
  if (segment == 1)
    grow(out_image, value, rows, cols);
  return (1);
}


x86 assembly (clang, -O0):
<peak_threshold_segmentation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
lea    -0x830(%rbp),%rdi
mov    $0x100,%esi
mov    $0x0,%al
call   10a0 <zero_histogram@plt>
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    $0x0,%al
call   1070 <calculate_histogram@plt>
lea    -0x830(%rbp),%rdi
mov    $0x100,%esi
mov    $0x0,%al
call   1030 <smooth_histogram@plt>
lea    -0x830(%rbp),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1090 <find_peaks@plt>
lea    -0x830(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    -0x2a(%rbp),%rcx
lea    -0x2c(%rbp),%r8
mov    $0x0,%al
call   1080 <peaks_high_low@plt>
movswl -0x2a(%rbp),%esi
movswl -0x2c(%rbp),%edx
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movswl -0x2a(%rbp),%edx
movswl -0x2c(%rbp),%ecx
movswl -0x12(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x20(%rbp),%eax
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <threshold_image_array@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1270 <peak_threshold_segmentation+0xf0>
mov    -0x10(%rbp),%rdi
movswl -0x12(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    $0x0,%al
call   1040 <grow@plt>
mov    $0x1,%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peak_threshold_segmentation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    %r9d,%r12d
mov    %r8d,%r13d
mov    %ecx,0x14(%rsp)
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   10a0 <zero_histogram@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1070 <calculate_histogram@plt>
mov    %r15,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1030 <smooth_histogram@plt>
lea    0x1c(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    %r15,%rdi
xor    %eax,%eax
call   1090 <find_peaks@plt>
mov    0x1c(%rsp),%esi
mov    0x18(%rsp),%edx
lea    0x12(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %r15,%rdi
xor    %eax,%eax
call   1080 <peaks_high_low@plt>
movswl 0x12(%rsp),%esi
movswl 0x10(%rsp),%edx
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movswl 0x12(%rsp),%edx
movswl 0x10(%rsp),%ecx
movswl %bp,%ebp
mov    %r12d,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%r8d
mov    %r13d,%r9d
xor    %eax,%eax
call   1050 <threshold_image_array@plt>
cmpl   $0x1,0x14(%rsp)
jne    125e <peak_threshold_segmentation+0xde>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <grow@plt>
mov    $0x1,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"\0APTS> hi=%d low=%d\0A\00"
define i32 @peak_threshold_segmentation(i16** %0, i16** %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i16**
%8 = alloca i16**
%9 = alloca i16
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i16
%16 = alloca i16
%17 = alloca [256 x i64]
%18 = trunc i32 %2 to i16
store i16** %0, i16*** %7
store i16** %1, i16*** %8
store i16 %18, i16* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%19 = getelementptr inbounds [256 x i64], [256 x i64]* %17, i64 0, i64 0
%20 = call i32 (i64*, i32, ...) bitcast (i32 (...)* @zero_histogram to i32 (i64*, i32, ...)*)(i64* %19, i32 256)
%21 = load i16**, i16*** %7
%22 = getelementptr inbounds [256 x i64], [256 x i64]* %17, i64 0, i64 0
%23 = load i32, i32* %11
%24 = load i32, i32* %12
%25 = call i32 (i16**, i64*, i32, i32, ...) bitcast (i32 (...)* @calculate_histogram to i32 (i16**, i64*, i32, i32, ...)*)(i16** %21, i64* %22, i32 %23, i32 %24)
%26 = getelementptr inbounds [256 x i64], [256 x i64]* %17, i64 0, i64 0
%27 = call i32 (i64*, i32, ...) bitcast (i32 (...)* @smooth_histogram to i32 (i64*, i32, ...)*)(i64* %26, i32 256)
%28 = getelementptr inbounds [256 x i64], [256 x i64]* %17, i64 0, i64 0
%29 = call i32 (i64*, i32*, i32*, ...) bitcast (i32 (...)* @find_peaks to i32 (i64*, i32*, i32*, ...)*)(i64* %28, i32* %13, i32* %14)
%30 = getelementptr inbounds [256 x i64], [256 x i64]* %17, i64 0, i64 0
%31 = load i32, i32* %13
%32 = load i32, i32* %14
%33 = call i32 (i64*, i32, i32, i16*, i16*, ...) bitcast (i32 (...)* @peaks_high_low to i32 (i64*, i32, i32, i16*, i16*, ...)*)(i64* %30, i32 %31, i32 %32, i16* %15, i16* %16)
%34 = load i16, i16* %15
%35 = sext i16 %34 to i32
%36 = load i16, i16* %16
%37 = sext i16 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %37)
%39 = load i16**, i16*** %7
%40 = load i16**, i16*** %8
%41 = load i16, i16* %15
%42 = sext i16 %41 to i32
%43 = load i16, i16* %16
%44 = sext i16 %43 to i32
%45 = load i16, i16* %9
%46 = sext i16 %45 to i32
%47 = load i32, i32* %11
%48 = load i32, i32* %12
%49 = call i32 (i16**, i16**, i32, i32, i32, i32, i32, ...) bitcast (i32 (...)* @threshold_image_array to i32 (i16**, i16**, i32, i32, i32, i32, i32, ...)*)(i16** %39, i16** %40, i32 %42, i32 %44, i32 %46, i32 %47, i32 %48)
%50 = load i32, i32* %10
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %59
52: ; preds = %6
%53 = load i16**, i16*** %8
%54 = load i16, i16* %9
%55 = sext i16 %54 to i32
%56 = load i32, i32* %11
%57 = load i32, i32* %12
%58 = call i32 (i16**, i32, i32, i32, ...) bitcast (i32 (...)* @grow to i32 (i16**, i32, i32, i32, ...)*)(i16** %53, i32 %55, i32 %56, i32 %57)
br label %59
59: ; preds = %52, %6
ret i32 1
}

LLVM IR (-O2):
@.str = [20 x i8] c"\0APTS> hi=%d low=%d\0A\00"
define i32 @peak_threshold_segmentation(i16** %0, i16** %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i16
%10 = alloca i16
%11 = alloca [256 x i64]
%12 = bitcast i32* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = bitcast i16* %9 to i8*
%15 = bitcast i16* %10 to i8*
%16 = bitcast [256 x i64]* %11 to i8*
%17 = getelementptr inbounds [256 x i64], [256 x i64]* %11, i64 0, i64 0
%18 = call i32 (i64*, i32, ...) bitcast (i32 (...)* @zero_histogram to i32 (i64*, i32, ...)*)(i64* %17, i32 256)
%19 = call i32 (i16**, i64*, i32, i32, ...) bitcast (i32 (...)* @calculate_histogram to i32 (i16**, i64*, i32, i32, ...)*)(i16** %0, i64* %17, i32 %4, i32 %5)
%20 = call i32 (i64*, i32, ...) bitcast (i32 (...)* @smooth_histogram to i32 (i64*, i32, ...)*)(i64* %17, i32 256)
%21 = call i32 (i64*, i32*, i32*, ...) bitcast (i32 (...)* @find_peaks to i32 (i64*, i32*, i32*, ...)*)(i64* %17, i32* %7, i32* %8)
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = call i32 (i64*, i32, i32, i16*, i16*, ...) bitcast (i32 (...)* @peaks_high_low to i32 (i64*, i32, i32, i16*, i16*, ...)*)(i64* %17, i32 %22, i32 %23, i16* %9, i16* %10)
%25 = load i16, i16* %9
%26 = sext i16 %25 to i32
%27 = load i16, i16* %10
%28 = sext i16 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %28)
%30 = load i16, i16* %9
%31 = sext i16 %30 to i32
%32 = load i16, i16* %10
%33 = sext i16 %32 to i32
%34 = shl i32 %2, 16
%35 = ashr exact i32 %34, 16
%36 = call i32 (i16**, i16**, i32, i32, i32, i32, i32, ...) bitcast (i32 (...)* @threshold_image_array to i32 (i16**, i16**, i32, i32, i32, i32, i32, ...)*)(i16** %0, i16** %1, i32 %31, i32 %33, i32 %35, i32 %4, i32 %5)
%37 = icmp eq i32 %3, 1
br i1 %37, label %38, label %40
38: ; preds = %6
%39 = call i32 (i16**, i32, i32, i32, ...) bitcast (i32 (...)* @grow to i32 (i16**, i32, i32, i32, ...)*)(i16** %1, i32 %35, i32 %4, i32 %5)
br label %40
40: ; preds = %38, %6
ret i32 1
}