#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 = threshold_height; i > 0; --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)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    11d2 <compute_frame_threshold_tiles+0xc2>
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    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    1172 <compute_frame_threshold_tiles+0x62>
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     1183 <compute_frame_threshold_tiles+0x73>
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    $0x2,%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
add    $0xffffffff,%ebp
mov    %r12,%rsi
cmp    $0x1,%ebp
ja     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
%36 = load i32, i32* %17
store i32 %36, i32* %18
br label %37
37: ; preds = %60, %6
%38 = load i32, i32* %18
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %63
40: ; preds = %37
%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 %37
63: ; preds = %37
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 sgt i32 %9, -1
br i1 %10, label %11, label %29
11: ; preds = %6
%12 = add nuw nsw i32 %9, 1
%13 = sdiv i32 %4, -2
%14 = add i32 %13, %2
%15 = sdiv i32 %14, %4
%16 = shl i32 %15, 1
%17 = add i32 %16, 4
%18 = sext i32 %17 to i64
%19 = sext i32 %8 to i64
br label %20
20: ; preds = %11, %20
%21 = phi i32 [ %12, %11 ], [ %27, %20 ]
%22 = phi i8* [ %0, %11 ], [ %26, %20 ]
%23 = phi i8* [ %1, %11 ], [ %24, %20 ]
%24 = getelementptr inbounds i8, i8* %23, i64 %18
%25 = tail call i32 @compute_row_thresholds(i8* %22, i8* %23, i8* %24, i32 %8, i32 %5)
%26 = getelementptr inbounds i8, i8* %22, i64 %19
%27 = add nsw i32 %21, -1
%28 = icmp ugt i32 %21, 1
br i1 %28, label %20, label %29
29: ; preds = %20, %6
ret void
}