#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 */
typedef int uint8_t;

/* Variables and functions */
int const imin(int, int);
int /*<<< orphan*/ memset(int *, int const, int const);
__attribute__((cold)) void build_nondc_ii_masks(uint8_t *const mask_v,
                                                uint8_t *const mask_h,
                                                uint8_t *const mask_sm,
                                                const int w, const int h,
                                                const int step) {
  static const uint8_t ii_weights_1d[] = {
      60, 52, 45, 39, 34, 30, 26, 22, 19, 17, 15, 13, 11, 10, 8, 7,
      6,  6,  5,  4,  4,  3,  3,  2,  2,  2,  2,  1,  1,  1,  1, 1,
  };
  for (int y = 0, off = 0; y < h; y++, off += w) {
    memset(&mask_v[off], ii_weights_1d[y * step], w);
    for (int x = 0; x < w; x++) {
      mask_sm[off + x] = ii_weights_1d[imin(x, y) * step];
      mask_h[off + x] = ii_weights_1d[x * step];
    }
  }
}


x86 assembly (clang, -O0):
<build_nondc_ii_masks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1211 <build_nondc_ii_masks+0xf1>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%eax
imul   -0x24(%rbp),%eax
movslq %eax,%rcx
lea    0xe87(%rip),%rax
mov    (%rax,%rcx,4),%esi
mov    -0x1c(%rbp),%edx
call   1040 <memset@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f5 <build_nondc_ii_masks+0xd5>
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1030 <imin@plt>
imul   -0x24(%rbp),%eax
movslq %eax,%rcx
lea    0xe50(%rip),%rax
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
imul   -0x24(%rbp),%eax
movslq %eax,%rcx
lea    0xe2c(%rip),%rax
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    118b <build_nondc_ii_masks+0x6b>
jmp    11fa <build_nondc_ii_masks+0xda>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    114d <build_nondc_ii_masks+0x2d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_nondc_ii_masks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9d,0xc(%rsp)
mov    %ecx,0x8(%rsp)
mov    %rdi,0x58(%rsp)
test   %r8d,%r8d
jle    1192 <build_nondc_ii_masks+0x132>
mov    %rdx,%rbp
movslq 0xc(%rsp),%rax
movslq 0x8(%rsp),%rcx
mov    %r8d,%edx
mov    %rdx,0x40(%rsp)
mov    %ecx,%edx
mov    %rdx,0x38(%rsp)
mov    %rax,0x50(%rsp)
lea    0x0(,%rax,4),%rax
mov    %rax,0x30(%rsp)
mov    %rcx,0x48(%rsp)
lea    0x0(,%rcx,4),%rax
mov    %rax,0x28(%rsp)
xor    %edx,%edx
lea    0xf32(%rip),%r8
xor    %edi,%edi
mov    0xc(%rsp),%r15d
mov    0x38(%rsp),%r13
mov    %rsi,0x10(%rsp)
mov    %rbp,0x18(%rsp)
mov    %rdx,0x20(%rsp)
mov    0x58(%rsp),%rax
mov    %rdi,0x60(%rsp)
lea    (%rax,%rdi,4),%rdi
mov    %rdx,%rax
imul   0x50(%rsp),%rax
mov    %r8,%rbx
mov    (%r8,%rax,4),%esi
mov    0x8(%rsp),%r14d
mov    %r14d,%edx
call   1040 <memset@plt>
mov    %rbx,%r8
test   %r14d,%r14d
mov    0x30(%rsp),%rbp
jle    1160 <build_nondc_ii_masks+0x100>
mov    %r8,%r14
xor    %r12d,%r12d
mov    %r12d,%edi
mov    0x20(%rsp),%rsi
call   1030 <imin@plt>
mov    %rbx,%r8
imul   %r15d,%eax
cltq
mov    (%rbx,%rax,4),%eax
mov    0x18(%rsp),%rcx
mov    %eax,(%rcx,%r12,4)
mov    (%r14),%eax
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx,%r12,4)
inc    %r12
add    %rbp,%r14
cmp    %r12,%r13
jne    1127 <build_nondc_ii_masks+0xc7>
mov    0x20(%rsp),%rdx
inc    %rdx
mov    0x60(%rsp),%rdi
add    0x48(%rsp),%rdi
mov    0x28(%rsp),%rax
mov    0x18(%rsp),%rbp
add    %rax,%rbp
mov    0x10(%rsp),%rsi
add    %rax,%rsi
cmp    0x40(%rsp),%rdx
jne    10da <build_nondc_ii_masks+0x7a>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)

LLVM IR (-O0):
@build_nondc_ii_masks.ii_weights_1d = internal constant [32 x i32] [i32 60, i32 52, i32 45, i32 39, i32 34, i32 30, i32 26, i32 22, i32 19, i32 17, i32 15, i32 13, i32 11, i32 10, i32 8, i32 7, i32 6, i32 6, i32 5, i32 4, i32 4, i32 3, i32 3, i32 2, i32 2, i32 2, i32 2, i32 1, i32 1, i32 1, i32 1, i32 1]
define void @build_nondc_ii_masks(i32* %0, i32* %1, i32* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
br label %16
16: ; preds = %68, %6
%17 = load i32, i32* %13
%18 = load i32, i32* %11
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %74
20: ; preds = %16
%21 = load i32*, i32** %7
%22 = load i32, i32* %14
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %13
%26 = load i32, i32* %12
%27 = mul nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [32 x i32], [32 x i32]* @build_nondc_ii_masks.ii_weights_1d, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = load i32, i32* %10
%32 = call i32 @memset(i32* %24, i32 %30, i32 %31)
store i32 0, i32* %15
br label %33
33: ; preds = %64, %20
%34 = load i32, i32* %15
%35 = load i32, i32* %10
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %67
37: ; preds = %33
%38 = load i32, i32* %15
%39 = load i32, i32* %13
%40 = call i32 @imin(i32 %38, i32 %39)
%41 = load i32, i32* %12
%42 = mul nsw i32 %40, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [32 x i32], [32 x i32]* @build_nondc_ii_masks.ii_weights_1d, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = load i32*, i32** %9
%47 = load i32, i32* %14
%48 = load i32, i32* %15
%49 = add nsw i32 %47, %48
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %46, i64 %50
store i32 %45, i32* %51
%52 = load i32, i32* %15
%53 = load i32, i32* %12
%54 = mul nsw i32 %52, %53
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [32 x i32], [32 x i32]* @build_nondc_ii_masks.ii_weights_1d, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = load i32*, i32** %8
%59 = load i32, i32* %14
%60 = load i32, i32* %15
%61 = add nsw i32 %59, %60
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %58, i64 %62
store i32 %57, i32* %63
br label %64
64: ; preds = %37
%65 = load i32, i32* %15
%66 = add nsw i32 %65, 1
store i32 %66, i32* %15
br label %33
67: ; preds = %33
br label %68
68: ; preds = %67
%69 = load i32, i32* %13
%70 = add nsw i32 %69, 1
store i32 %70, i32* %13
%71 = load i32, i32* %10
%72 = load i32, i32* %14
%73 = add nsw i32 %72, %71
store i32 %73, i32* %14
br label %16
74: ; preds = %16
ret void
}

LLVM IR (-O2):
@build_nondc_ii_masks.ii_weights_1d = internal unnamed_addr constant [32 x i32] [i32 60, i32 52, i32 45, i32 39, i32 34, i32 30, i32 26, i32 22, i32 19, i32 17, i32 15, i32 13, i32 11, i32 10, i32 8, i32 7, i32 6, i32 6, i32 5, i32 4, i32 4, i32 3, i32 3, i32 2, i32 2, i32 2, i32 2, i32 1, i32 1, i32 1, i32 1, i32 1]
define void @build_nondc_ii_masks(i32* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32 %3, i32 %4, i32 %5) {
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %14
8: ; preds = %6
%9 = icmp sgt i32 %3, 0
%10 = sext i32 %5 to i64
%11 = sext i32 %3 to i64
%12 = zext i32 %4 to i64
%13 = zext i32 %3 to i64
br label %15
14: ; preds = %25, %6
ret void
15: ; preds = %8, %25
%16 = phi i64 [ 0, %8 ], [ %26, %25 ]
%17 = phi i64 [ 0, %8 ], [ %27, %25 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = mul nsw i64 %16, %10
%20 = getelementptr inbounds [32 x i32], [32 x i32]* @build_nondc_ii_masks.ii_weights_1d, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 @memset(i32* %18, i32 %21, i32 %3)
br i1 %9, label %23, label %25
23: ; preds = %15
%24 = trunc i64 %16 to i32
br label %29
25: ; preds = %29, %15
%26 = add nuw nsw i64 %16, 1
%27 = add nsw i64 %17, %11
%28 = icmp eq i64 %26, %12
br i1 %28, label %14, label %15
29: ; preds = %23, %29
%30 = phi i64 [ 0, %23 ], [ %43, %29 ]
%31 = trunc i64 %30 to i32
%32 = tail call i32 @imin(i32 %31, i32 %24)
%33 = mul nsw i32 %32, %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [32 x i32], [32 x i32]* @build_nondc_ii_masks.ii_weights_1d, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = add nsw i64 %30, %17
%38 = getelementptr inbounds i32, i32* %2, i64 %37
store i32 %36, i32* %38
%39 = mul nsw i64 %30, %10
%40 = getelementptr inbounds [32 x i32], [32 x i32]* @build_nondc_ii_masks.ii_weights_1d, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = getelementptr inbounds i32, i32* %1, i64 %37
store i32 %41, i32* %42
%43 = add nuw nsw i64 %30, 1
%44 = icmp eq i64 %43, %13
br i1 %44, label %25, label %29
}