#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*/ weed_memset(unsigned char *, int /*<<< orphan*/, int);
void add_bg_pixel(unsigned char *ptr, int pal, int clamping, int trans) {
  if (trans == 1)
    trans = 0;
  else
    trans = 255;
  switch (pal) {
  case 1:
  case 2:
    weed_memset(ptr, 0, 3);
    break;
  case 3:
  case 7:
    weed_memset(ptr, 0, 3);
    ptr[3] = trans;
    break;
  case 4:
    weed_memset(ptr + 1, 0, 3);
    ptr[0] = trans;
    break;
  case 521:
    if (clamping != 0)
      ptr[0] = 0;
    else
      ptr[0] = 16;
    ptr[1] = ptr[2] = 128;
    break;
  case 522:
    if (clamping != 0)
      ptr[0] = 0;
    else
      ptr[0] = 16;
    ptr[1] = ptr[2] = 128;
    ptr[3] = trans;
    break;
  }
}


x86 assembly (clang, -O0):
<add_bg_pixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    113b <add_bg_pixel+0x2b>
movl   $0x0,-0x14(%rbp)
jmp    1142 <add_bg_pixel+0x32>
movl   $0xff,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
add    $0xffffffff,%eax
sub    $0x2,%eax
jb     11b2 <add_bg_pixel+0xa2>
jmp    1159 <add_bg_pixel+0x49>
mov    -0x18(%rbp),%eax
sub    $0x3,%eax
je     11c7 <add_bg_pixel+0xb7>
jmp    116a <add_bg_pixel+0x5a>
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
je     11e8 <add_bg_pixel+0xd8>
jmp    117b <add_bg_pixel+0x6b>
mov    -0x18(%rbp),%eax
sub    $0x7,%eax
je     11c7 <add_bg_pixel+0xb7>
jmp    118c <add_bg_pixel+0x7c>
mov    -0x18(%rbp),%eax
sub    $0x209,%eax
je     120c <add_bg_pixel+0xfc>
jmp    119f <add_bg_pixel+0x8f>
mov    -0x18(%rbp),%eax
sub    $0x20a,%eax
je     123e <add_bg_pixel+0x12e>
jmp    1277 <add_bg_pixel+0x167>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <weed_memset@plt>
jmp    1277 <add_bg_pixel+0x167>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <weed_memset@plt>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
jmp    1277 <add_bg_pixel+0x167>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <weed_memset@plt>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    1277 <add_bg_pixel+0x167>
cmpl   $0x0,-0x10(%rbp)
je     1222 <add_bg_pixel+0x112>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    1229 <add_bg_pixel+0x119>
mov    -0x8(%rbp),%rax
movb   $0x10,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x80,0x2(%rax)
mov    -0x8(%rbp),%rax
movb   $0x80,0x1(%rax)
jmp    1277 <add_bg_pixel+0x167>
cmpl   $0x0,-0x10(%rbp)
je     1254 <add_bg_pixel+0x144>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    125b <add_bg_pixel+0x14b>
mov    -0x8(%rbp),%rax
movb   $0x10,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x80,0x2(%rax)
mov    -0x8(%rbp),%rax
movb   $0x80,0x1(%rax)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_bg_pixel>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x1,%ecx
setne  %bl
neg    %bl
lea    -0x1(%rsi),%eax
cmp    $0x6,%eax
ja     114d <add_bg_pixel+0x3d>
lea    0xed2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x3,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <weed_memset@plt>
cmp    $0x209,%esi
je     119f <add_bg_pixel+0x8f>
cmp    $0x20a,%esi
jne    11b1 <add_bg_pixel+0xa1>
test   %edx,%edx
sete   %al
shl    $0x4,%al
mov    %al,(%r14)
movw   $0x8080,0x1(%r14)
mov    %bl,0x3(%r14)
jmp    11b1 <add_bg_pixel+0xa1>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <weed_memset@plt>
mov    %bl,0x3(%r14)
jmp    11b1 <add_bg_pixel+0xa1>
lea    0x1(%r14),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <weed_memset@plt>
mov    %bl,(%r14)
jmp    11b1 <add_bg_pixel+0xa1>
test   %edx,%edx
sete   %al
shl    $0x4,%al
mov    %al,(%r14)
movw   $0x8080,0x1(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @add_bg_pixel(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp ne i32 %3, 1
%6 = sext i1 %5 to i8
switch i32 %1, label %26 [
i32 1, label %7
i32 2, label %7
i32 3, label %9
i32 7, label %9
i32 4, label %12
i32 521, label %15
i32 522, label %20
]
7: ; preds = %4, %4
%8 = tail call i32 @weed_memset(i8* %0, i32 0, i32 3)
br label %26
9: ; preds = %4, %4
%10 = tail call i32 @weed_memset(i8* %0, i32 0, i32 3)
%11 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %6, i8* %11
br label %26
12: ; preds = %4
%13 = getelementptr inbounds i8, i8* %0, i64 1
%14 = tail call i32 @weed_memset(i8* %13, i32 0, i32 3)
store i8 %6, i8* %0
br label %26
15: ; preds = %4
%16 = icmp eq i32 %2, 0
%17 = select i1 %16, i8 16, i8 0
store i8 %17, i8* %0
%18 = getelementptr inbounds i8, i8* %0, i64 2
store i8 -128, i8* %18
%19 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -128, i8* %19
br label %26
20: ; preds = %4
%21 = icmp eq i32 %2, 0
%22 = select i1 %21, i8 16, i8 0
store i8 %22, i8* %0
%23 = getelementptr inbounds i8, i8* %0, i64 2
store i8 -128, i8* %23
%24 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -128, i8* %24
%25 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %6, i8* %25
br label %26
26: ; preds = %4, %20, %15, %12, %9, %7
ret void
}