#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*/ fprintf(int /*<<< orphan*/, char *, unsigned char);
unsigned char *get_weight_func(unsigned char);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void weight_func_apply(unsigned char *tilebuf, unsigned char tile_index,
                       unsigned char tile_area) {
  if (0 == tile_area || 0 == tile_index) {
    memset(tilebuf, 0, 6 * 6);
  } else {
    const unsigned char *weight_func = get_weight_func(tile_index);
    if (!weight_func) {
      fprintf(stderr,
              "Error: Unable to get the weight function "
              "of tile %d\n",
              tile_index);
      return;
    }
    int x;
    for (x = 0; x < 6 * 6; x++) {
      if (weight_func[x] <= tile_area) {
        tilebuf[x] = 0xff;
      } else {
        tilebuf[x] = 0x00;
      }
    }
  }
}


x86 assembly (clang, -O0):
<weight_func_apply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
movzbl -0xa(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1163 <weight_func_apply+0x33>
movzbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1178 <weight_func_apply+0x48>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x24,%edx
call   1040 <memset@plt>
jmp    120c <weight_func_apply+0xdc>
movzbl -0x9(%rbp),%edi
call   1030 <get_weight_func@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ae <weight_func_apply+0x7e>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
movzbl -0x9(%rbp),%edx
call   1050 <fprintf@plt>
jmp    120c <weight_func_apply+0xdc>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x24,-0x1c(%rbp)
jge    1207 <weight_func_apply+0xd7>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
movzbl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jg     11e8 <weight_func_apply+0xb8>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
jmp    11f4 <weight_func_apply+0xc4>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11f9 <weight_func_apply+0xc9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b5 <weight_func_apply+0x85>
jmp    120c <weight_func_apply+0xdc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weight_func_apply>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %esi,%esi
je     1169 <weight_func_apply+0x39>
mov    %edx,%ebp
test   %bpl,%bpl
je     1169 <weight_func_apply+0x39>
movzbl %sil,%r14d
mov    %r14d,%edi
call   1030 <get_weight_func@plt>
test   %rax,%rax
je     117c <weight_func_apply+0x4c>
lea    0x24(%rax),%rcx
cmp    %rbx,%rcx
jbe    1198 <weight_func_apply+0x68>
lea    0x24(%rbx),%rcx
cmp    %rcx,%rax
jae    1198 <weight_func_apply+0x68>
xor    %ecx,%ecx
jmp    11e0 <weight_func_apply+0xb0>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x24,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <memset@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <fprintf@plt>
movzbl %bpl,%ecx
movd   %ecx,%xmm0
punpcklbw %xmm0,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqu (%rax),%xmm1
movdqa %xmm1,%xmm2
pminub %xmm0,%xmm2
pcmpeqb %xmm1,%xmm2
movdqu %xmm2,(%rbx)
movdqu 0x10(%rax),%xmm1
pminub %xmm1,%xmm0
pcmpeqb %xmm1,%xmm0
movdqu %xmm0,0x10(%rbx)
mov    $0x20,%ecx
nopl   0x0(%rax)
cmp    (%rax,%rcx,1),%bpl
mov    $0x0,%edx
adc    $0xff,%dl
mov    %dl,(%rbx,%rcx,1)
cmp    0x1(%rax,%rcx,1),%bpl
mov    $0x0,%edx
adc    $0xff,%dl
mov    %dl,0x1(%rbx,%rcx,1)
cmp    0x2(%rax,%rcx,1),%bpl
mov    $0x0,%edx
adc    $0xff,%dl
mov    %dl,0x2(%rbx,%rcx,1)
cmp    0x3(%rax,%rcx,1),%bpl
mov    $0x0,%edx
adc    $0xff,%dl
mov    %dl,0x3(%rbx,%rcx,1)
add    $0x4,%rcx
cmp    $0x24,%rcx
jne    11e0 <weight_func_apply+0xb0>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"Error: Unable to get the weight function of tile %d\0A\00"
define void @weight_func_apply(i8* %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%9 = load i8, i8* %6
%10 = zext i8 %9 to i32
%11 = icmp eq i32 0, %10
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load i8, i8* %5
%14 = zext i8 %13 to i32
%15 = icmp eq i32 0, %14
br i1 %15, label %16, label %19
16: ; preds = %12, %3
%17 = load i8*, i8** %4
%18 = call i32 @memset(i8* %17, i32 0, i32 36)
br label %57
19: ; preds = %12
%20 = load i8, i8* %5
%21 = call i8* @get_weight_func(i8 zeroext %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i8, i8* %5
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8 zeroext %26)
br label %57
28: ; preds = %19
store i32 0, i32* %8
br label %29
29: ; preds = %53, %28
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 36
br i1 %31, label %32, label %56
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = load i8, i8* %6
%40 = zext i8 %39 to i32
%41 = icmp sle i32 %38, %40
br i1 %41, label %42, label %47
42: ; preds = %32
%43 = load i8*, i8** %4
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 -1, i8* %46
br label %52
47: ; preds = %32
%48 = load i8*, i8** %4
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %47, %42
br label %53
53: ; preds = %52
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %29
56: ; preds = %29
br label %57
57: ; preds = %24, %56, %16
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"Error: Unable to get the weight function of tile %d\0A\00"
define void @weight_func_apply(i8* %0, i8 zeroext %1, i8 zeroext %2) {
%4 = icmp eq i8 %2, 0
%5 = icmp eq i8 %1, 0
%6 = or i1 %5, %4
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @memset(i8* %0, i32 0, i32 36)
br label %65
9: ; preds = %3
%10 = tail call i8* @get_weight_func(i8 zeroext %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %35, label %12
12: ; preds = %9
%13 = getelementptr i8, i8* %0, i64 36
%14 = getelementptr i8, i8* %10, i64 36
%15 = icmp ugt i8* %14, %0
%16 = icmp ult i8* %10, %13
%17 = and i1 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %20, %12
%19 = phi i64 [ 0, %12 ], [ 32, %20 ]
br label %38
20: ; preds = %12
%21 = insertelement <16 x i8> poison, i8 %2, i64 0
%22 = shufflevector <16 x i8> %21, <16 x i8> poison, <16 x i32> zeroinitializer
%23 = bitcast i8* %10 to <16 x i8>*
%24 = load <16 x i8>, <16 x i8>* %23
%25 = icmp ule <16 x i8> %24, %22
%26 = sext <16 x i1> %25 to <16 x i8>
%27 = bitcast i8* %0 to <16 x i8>*
store <16 x i8> %26, <16 x i8>* %27
%28 = getelementptr inbounds i8, i8* %10, i64 16
%29 = bitcast i8* %28 to <16 x i8>*
%30 = load <16 x i8>, <16 x i8>* %29
%31 = icmp ule <16 x i8> %30, %22
%32 = sext <16 x i1> %31 to <16 x i8>
%33 = getelementptr inbounds i8, i8* %0, i64 16
%34 = bitcast i8* %33 to <16 x i8>*
store <16 x i8> %32, <16 x i8>* %34
br label %18
35: ; preds = %9
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8 zeroext %1)
br label %65
38: ; preds = %38, %18
%39 = phi i64 [ %19, %18 ], [ %63, %38 ]
%40 = getelementptr inbounds i8, i8* %10, i64 %39
%41 = load i8, i8* %40
%42 = icmp ule i8 %41, %2
%43 = sext i1 %42 to i8
%44 = getelementptr inbounds i8, i8* %0, i64 %39
store i8 %43, i8* %44
%45 = or i64 %39, 1
%46 = getelementptr inbounds i8, i8* %10, i64 %45
%47 = load i8, i8* %46
%48 = icmp ule i8 %47, %2
%49 = sext i1 %48 to i8
%50 = getelementptr inbounds i8, i8* %0, i64 %45
store i8 %49, i8* %50
%51 = or i64 %39, 2
%52 = getelementptr inbounds i8, i8* %10, i64 %51
%53 = load i8, i8* %52
%54 = icmp ule i8 %53, %2
%55 = sext i1 %54 to i8
%56 = getelementptr inbounds i8, i8* %0, i64 %51
store i8 %55, i8* %56
%57 = or i64 %39, 3
%58 = getelementptr inbounds i8, i8* %10, i64 %57
%59 = load i8, i8* %58
%60 = icmp ule i8 %59, %2
%61 = sext i1 %60 to i8
%62 = getelementptr inbounds i8, i8* %0, i64 %57
store i8 %61, i8* %62
%63 = add nuw nsw i64 %39, 4
%64 = icmp eq i64 %63, 36
br i1 %64, label %65, label %38
65: ; preds = %38, %35, %7
ret void
}