#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*/ boxBlurAlpha(unsigned char *, unsigned char *, int, int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, unsigned char, int);
void blurXAlpha(unsigned char *img, int width, int height, int distance,
                unsigned char borderAlpha, int rx, int ry, int rw, int rh) {
  if (distance < 1) {
    return;
  }
  unsigned char *src = img + (ry * width) + rx;
  int dist2 = distance << 1;
  int windowLength = dist2 + 1;
  unsigned char *lineBufferIn = malloc(rw + dist2);
  memset(lineBufferIn, borderAlpha, dist2);
  memset(lineBufferIn + rw, borderAlpha, dist2);
  for (int y = 0; y < rh; ++y) {
    memcpy(lineBufferIn + dist2, src + distance, rw - dist2);
    boxBlurAlpha(src, lineBufferIn, rw, windowLength);
    src += width;
  }
  free(lineBufferIn);
}


x86 assembly (clang, -O0):
<blurXAlpha>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8b,%al
mov    0x20(%rbp),%r8d
mov    0x18(%rbp),%r8d
mov    0x10(%rbp),%r8d
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    %r9d,-0x1c(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    118a <blurXAlpha+0x3a>
jmp    1261 <blurXAlpha+0x111>
mov    -0x8(%rbp),%rax
mov    0x10(%rbp),%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    0x18(%rbp),%edi
add    -0x2c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x15(%rbp),%al
mov    -0x2c(%rbp),%edx
movzbl %al,%esi
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
movslq 0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x15(%rbp),%al
mov    -0x2c(%rbp),%edx
movzbl %al,%esi
call   1040 <memset@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    0x20(%rbp),%eax
jge    1258 <blurXAlpha+0x108>
mov    -0x38(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    0x18(%rbp),%edx
sub    -0x2c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x18(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   1050 <boxBlurAlpha@plt>
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f9 <blurXAlpha+0xa9>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blurXAlpha>:
test   %ecx,%ecx
jle    1263 <blurXAlpha+0x113>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r12d
mov    %ecx,%r15d
mov    %rdi,0x20(%rsp)
mov    %r9d,0xc(%rsp)
mov    %esi,0x10(%rsp)
mov    0x70(%rsp),%r14d
mov    0x68(%rsp),%ebp
mov    0x60(%rsp),%eax
mov    %eax,0x8(%rsp)
lea    (%r15,%r15,1),%r13d
lea    0x0(%rbp,%r15,2),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
movzbl %r12b,%r12d
mov    %rax,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
call   1040 <memset@plt>
mov    %rbp,0x18(%rsp)
movslq %ebp,%rdi
mov    %rbx,(%rsp)
add    %rbx,%rdi
mov    %r12d,%esi
mov    %r13d,%ebx
mov    %r13d,%edx
call   1040 <memset@plt>
test   %r14d,%r14d
jle    124c <blurXAlpha+0xfc>
lea    (%r15,%r15,1),%eax
add    $0x1,%eax
mov    %eax,0x14(%rsp)
mov    0x10(%rsp),%ecx
mov    0x8(%rsp),%eax
imul   %ecx,%eax
cltq
mov    0x20(%rsp),%rdx
add    %rax,%rdx
movslq 0xc(%rsp),%r13
add    %rdx,%r13
mov    %ebx,%edx
movslq %ebx,%rax
mov    (%rsp),%rbx
add    %rax,%rbx
mov    %r15d,%r12d
mov    0x18(%rsp),%rax
mov    %eax,%ebp
sub    %edx,%ebp
movslq %ecx,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r12,%r13,1),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <memcpy@plt>
mov    %r13,%rdi
mov    (%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    0x14(%rsp),%ecx
call   1050 <boxBlurAlpha@plt>
add    %r15,%r13
add    $0xffffffff,%r14d
jne    1220 <blurXAlpha+0xd0>
mov    (%rsp),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
ret

LLVM IR (-O0):
define void @blurXAlpha(i8* %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i8*
%23 = alloca i32
store i8* %0, i8** %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i8 %4, i8* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i32 %8, i32* %18
%24 = load i32, i32* %13
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %9
br label %88
27: ; preds = %9
%28 = load i8*, i8** %10
%29 = load i32, i32* %16
%30 = load i32, i32* %11
%31 = mul nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
%34 = load i32, i32* %15
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8* %36, i8** %19
%37 = load i32, i32* %13
%38 = shl i32 %37, 1
store i32 %38, i32* %20
%39 = load i32, i32* %20
%40 = add nsw i32 %39, 1
store i32 %40, i32* %21
%41 = load i32, i32* %17
%42 = load i32, i32* %20
%43 = add nsw i32 %41, %42
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %22
%45 = load i8*, i8** %22
%46 = load i8, i8* %14
%47 = load i32, i32* %20
%48 = call i32 @memset(i8* %45, i8 zeroext %46, i32 %47)
%49 = load i8*, i8** %22
%50 = load i32, i32* %17
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %14
%54 = load i32, i32* %20
%55 = call i32 @memset(i8* %52, i8 zeroext %53, i32 %54)
store i32 0, i32* %23
br label %56
56: ; preds = %82, %27
%57 = load i32, i32* %23
%58 = load i32, i32* %18
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %85
60: ; preds = %56
%61 = load i8*, i8** %22
%62 = load i32, i32* %20
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8*, i8** %19
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i32, i32* %17
%70 = load i32, i32* %20
%71 = sub nsw i32 %69, %70
%72 = call i32 @memcpy(i8* %64, i8* %68, i32 %71)
%73 = load i8*, i8** %19
%74 = load i8*, i8** %22
%75 = load i32, i32* %17
%76 = load i32, i32* %21
%77 = call i32 @boxBlurAlpha(i8* %73, i8* %74, i32 %75, i32 %76)
%78 = load i32, i32* %11
%79 = load i8*, i8** %19
%80 = sext i32 %78 to i64
%81 = getelementptr inbounds i8, i8* %79, i64 %80
store i8* %81, i8** %19
br label %82
82: ; preds = %60
%83 = load i32, i32* %23
%84 = add nsw i32 %83, 1
store i32 %84, i32* %23
br label %56
85: ; preds = %56
%86 = load i8*, i8** %22
%87 = call i32 @free(i8* %86)
br label %88
88: ; preds = %85, %26
ret void
}

LLVM IR (-O2):
define void @blurXAlpha(i8* %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = icmp slt i32 %3, 1
br i1 %10, label %43, label %11
11: ; preds = %9
%12 = shl nuw i32 %3, 1
%13 = or i32 %12, 1
%14 = add nsw i32 %12, %7
%15 = tail call i8* @malloc(i32 %14)
%16 = tail call i32 @memset(i8* %15, i8 zeroext %4, i32 %12)
%17 = sext i32 %7 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = tail call i32 @memset(i8* %18, i8 zeroext %4, i32 %12)
%20 = icmp sgt i32 %8, 0
br i1 %20, label %21, label %32
21: ; preds = %11
%22 = mul nsw i32 %6, %1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = sext i32 %5 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = sext i32 %12 to i64
%28 = getelementptr inbounds i8, i8* %15, i64 %27
%29 = zext i32 %3 to i64
%30 = sub nsw i32 %7, %12
%31 = sext i32 %1 to i64
br label %34
32: ; preds = %34, %11
%33 = tail call i32 @free(i8* %15)
br label %43
34: ; preds = %21, %34
%35 = phi i32 [ 0, %21 ], [ %41, %34 ]
%36 = phi i8* [ %26, %21 ], [ %40, %34 ]
%37 = getelementptr inbounds i8, i8* %36, i64 %29
%38 = tail call i32 @memcpy(i8* %28, i8* %37, i32 %30)
%39 = tail call i32 @boxBlurAlpha(i8* %36, i8* %15, i32 %7, i32 %13)
%40 = getelementptr inbounds i8, i8* %36, i64 %31
%41 = add nuw nsw i32 %35, 1
%42 = icmp eq i32 %41, %8
br i1 %42, label %32, label %34
43: ; preds = %9, %32
ret void
}