#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 */

/* Variables and functions */
int /*<<< orphan*/ compute_row_thresholds(unsigned char *,
                                          unsigned char const *,
                                          unsigned char const *, int, int);
void compute_frame_threshold_tiles(unsigned char *thresholds_dest,
                                   const unsigned char *min_max, int width,
                                   int height, int tile_size,
                                   int contrast_threshold) {
  int first_vector_size = tile_size / 2;
  int full_span_count = (width - first_vector_size) / tile_size;
  int min_max_width = full_span_count + 2;
  int threshold_width = (width / tile_size) + 1;
  int threshold_height = (height / tile_size) + 1;
  int i;
  for (i = 0; i < threshold_height; ++i) {
    compute_row_thresholds(thresholds_dest, min_max,
                           min_max + min_max_width * 2, threshold_width,
                           contrast_threshold);
    thresholds_dest += threshold_width;
    min_max += min_max_width * 2;
  }
}


x86 assembly (clang, -O0):
<compute_frame_threshold_tiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x24(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11d5 <compute_frame_threshold_tiles+0xc5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdx
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1030 <compute_row_thresholds@plt>
mov    -0x30(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x2c(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1173 <compute_frame_threshold_tiles+0x63>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_frame_threshold_tiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %edx,%ecx
mov    %rdi,%rbx
mov    %edx,%eax
cltd
idiv   %r8d
mov    %eax,%edi
mov    %ebp,%eax
cltd
idiv   %r8d
test   %eax,%eax
js     1180 <compute_frame_threshold_tiles+0x70>
mov    %r9d,%r14d
mov    %eax,%ebp
add    $0x1,%edi
mov    %r8d,%eax
shr    $0x1f,%eax
add    %r8d,%eax
sar    %eax
sub    %eax,%ecx
mov    %ecx,%eax
cltd
idiv   %r8d
add    %eax,%eax
add    $0x4,%eax
movslq %eax,%r13
movslq %edi,%r15
add    $0x1,%ebp
nopl   (%rax)
lea    (%rsi,%r13,1),%r12
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1030 <compute_row_thresholds@plt>
add    %r15,%rbx
mov    %r12,%rsi
add    $0xffffffff,%ebp
jne    1160 <compute_frame_threshold_tiles+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @compute_frame_threshold_tiles(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%19 = load i32, i32* %11
%20 = sdiv i32 %19, 2
store i32 %20, i32* %13
%21 = load i32, i32* %9
%22 = load i32, i32* %13
%23 = sub nsw i32 %21, %22
%24 = load i32, i32* %11
%25 = sdiv i32 %23, %24
store i32 %25, i32* %14
%26 = load i32, i32* %14
%27 = add nsw i32 %26, 2
store i32 %27, i32* %15
%28 = load i32, i32* %9
%29 = load i32, i32* %11
%30 = sdiv i32 %28, %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %16
%32 = load i32, i32* %10
%33 = load i32, i32* %11
%34 = sdiv i32 %32, %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %17
store i32 0, i32* %18
br label %36
36: ; preds = %60, %6
%37 = load i32, i32* %18
%38 = load i32, i32* %17
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %63
40: ; preds = %36
%41 = load i8*, i8** %7
%42 = load i8*, i8** %8
%43 = load i8*, i8** %8
%44 = load i32, i32* %15
%45 = mul nsw i32 %44, 2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = load i32, i32* %16
%49 = load i32, i32* %12
%50 = call i32 @compute_row_thresholds(i8* %41, i8* %42, i8* %47, i32 %48, i32 %49)
%51 = load i32, i32* %16
%52 = load i8*, i8** %7
%53 = sext i32 %51 to i64
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8* %54, i8** %7
%55 = load i32, i32* %15
%56 = mul nsw i32 %55, 2
%57 = load i8*, i8** %8
%58 = sext i32 %56 to i64
%59 = getelementptr inbounds i8, i8* %57, i64 %58
store i8* %59, i8** %8
br label %60
60: ; preds = %40
%61 = load i32, i32* %18
%62 = add nsw i32 %61, 1
store i32 %62, i32* %18
br label %36
63: ; preds = %36
ret void
}

LLVM IR (-O2):
define void @compute_frame_threshold_tiles(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = sdiv i32 %2, %4
%8 = add nsw i32 %7, 1
%9 = sdiv i32 %3, %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %6
%12 = sdiv i32 %4, -2
%13 = add i32 %12, %2
%14 = sdiv i32 %13, %4
%15 = shl i32 %14, 1
%16 = add i32 %15, 4
%17 = sext i32 %16 to i64
%18 = sext i32 %8 to i64
br label %19
19: ; preds = %11, %19
%20 = phi i32 [ 0, %11 ], [ %26, %19 ]
%21 = phi i8* [ %0, %11 ], [ %25, %19 ]
%22 = phi i8* [ %1, %11 ], [ %23, %19 ]
%23 = getelementptr inbounds i8, i8* %22, i64 %17
%24 = tail call i32 @compute_row_thresholds(i8* %21, i8* %22, i8* %23, i32 %8, i32 %5)
%25 = getelementptr inbounds i8, i8* %21, i64 %18
%26 = add nuw i32 %20, 1
%27 = icmp eq i32 %20, %9
br i1 %27, label %28, label %19
28: ; preds = %19, %6
ret void
}