#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*/ doLinearScaler_Row(unsigned char const *,
                                      unsigned char const *, unsigned char *,
                                      size_t, size_t);
int doLinearScaler(const void *pSrc, size_t srcWidth, size_t srcHeight,
                   size_t srcStride, void *pDst, size_t dstWidth,
                   size_t dstHeight, size_t dstStride) {
  size_t ratio = srcWidth / dstWidth;
  if (ratio * dstWidth != srcWidth)
    return -1;
  size_t span = ratio / 2;
  const unsigned char *pS = (const unsigned char *)pSrc;
  unsigned char *pD = (unsigned char *)pDst;
  srcStride *= span;
  while (dstHeight--) {
    const unsigned char *pS0, *pS1;
    unsigned char *pDLine;
    pS0 = pS;
    pS1 = pS + srcStride;
    pS = pS1 + srcStride;
    pDLine = pD;
    pD += dstStride;
    doLinearScaler_Row(pS0, pS1, pDLine, dstWidth, span * 2);
  }
}


x86 assembly (clang, -O0):
<doLinearScaler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x18(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x38(%rbp)
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
imul   -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1167 <doLinearScaler+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <doLinearScaler+0xef>
mov    -0x40(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x10(%rbp)
cmp    $0x0,%rax
je     11ff <doLinearScaler+0xef>
mov    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x50(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    0x18(%rbp),%rax
add    -0x58(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x48(%rbp),%r8
shl    $0x1,%r8
call   1030 <doLinearScaler_Row@plt>
jmp    1190 <doLinearScaler+0x80>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doLinearScaler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %rsi,%rax
or     %r9,%rax
shr    $0x20,%rax
je     1137 <doLinearScaler+0x27>
mov    %rsi,%rax
xor    %edx,%edx
div    %r14
mov    %rax,%r15
jmp    1141 <doLinearScaler+0x31>
mov    %esi,%eax
xor    %edx,%edx
div    %r14d
mov    %eax,%r15d
mov    %r15,%rax
imul   %r14,%rax
cmp    %rsi,%rax
jne    119b <doLinearScaler+0x8b>
mov    0x40(%rsp),%rbx
test   %rbx,%rbx
je     119b <doLinearScaler+0x8b>
mov    %r15,%r13
shr    %r13
imul   %rcx,%r13
and    $0xfffffffffffffffe,%r15
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rdi,%r13,1),%rsi
lea    (%rsi,%r13,1),%rbp
mov    0x48(%rsp),%rax
lea    (%r8,%rax,1),%r12
mov    %r8,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1030 <doLinearScaler_Row@plt>
mov    %r12,%r8
mov    %rbp,%rdi
add    $0xffffffffffffffff,%rbx
jne    1170 <doLinearScaler+0x60>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @doLinearScaler(i8* %0, i64 %1, i64 %2, i64 %3, i8* %4, i64 %5, i64 %6, i64 %7) {
%9 = udiv i64 %1, %5
%10 = mul i64 %9, %5
%11 = icmp eq i64 %10, %1
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = lshr i64 %9, 1
%14 = mul i64 %13, %3
%15 = icmp eq i64 %6, 0
br i1 %15, label %28, label %16
16: ; preds = %12
%17 = and i64 %9, -2
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ %6, %16 ], [ %22, %18 ]
%20 = phi i8* [ %4, %16 ], [ %25, %18 ]
%21 = phi i8* [ %0, %16 ], [ %24, %18 ]
%22 = add i64 %19, -1
%23 = getelementptr inbounds i8, i8* %21, i64 %14
%24 = getelementptr inbounds i8, i8* %23, i64 %14
%25 = getelementptr inbounds i8, i8* %20, i64 %7
%26 = tail call i32 @doLinearScaler_Row(i8* %21, i8* %23, i8* %20, i64 %5, i64 %17)
%27 = icmp eq i64 %22, 0
br i1 %27, label %28, label %18
28: ; preds = %18, %12, %8
ret i32 -1
}