#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*/ add_bg_pixel(unsigned char *, int, int, int);
void add_bg_row(unsigned char *ptr, int xwidth, int pal, int clamping,
                int trans) {
  register int i;
  int psize = 4;
  if (pal == 1 || pal == 2 || pal == 521)
    psize = 3;
  for (i = 0; i < xwidth; i += psize)
    add_bg_pixel(ptr + i, pal, clamping, trans);
}


x86 assembly (clang, -O0):
<add_bg_row>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
movl   $0x4,-0x20(%rbp)
cmpl   $0x1,-0x10(%rbp)
je     1151 <add_bg_row+0x41>
cmpl   $0x2,-0x10(%rbp)
je     1151 <add_bg_row+0x41>
cmpl   $0x209,-0x10(%rbp)
jne    1158 <add_bg_row+0x48>
movl   $0x3,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1192 <add_bg_row+0x82>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <add_bg_pixel@plt>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <add_bg_row+0x4f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_bg_row>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rdi,%r13
lea    -0x1(%rbp),%eax
cmp    $0x2,%eax
jb     113b <add_bg_row+0x2b>
mov    $0x4,%ebx
cmp    $0x209,%ebp
jne    1140 <add_bg_row+0x30>
mov    $0x3,%ebx
test   %esi,%esi
jle    116d <add_bg_row+0x5d>
xor    %r14d,%r14d
mov    %esi,0x4(%rsp)
nopl   0x0(%rax,%rax,1)
lea    (%r14,%r13,1),%rdi
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <add_bg_pixel@plt>
mov    0x4(%rsp),%esi
add    %rbx,%r14
cmp    %esi,%r14d
jl     1150 <add_bg_row+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @add_bg_row(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 4, i32* %12
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, 1
br i1 %14, label %21, label %15
15: ; preds = %5
%16 = load i32, i32* %8
%17 = icmp eq i32 %16, 2
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 521
br i1 %20, label %21, label %22
21: ; preds = %18, %15, %5
store i32 3, i32* %12
br label %22
22: ; preds = %21, %18
store i32 0, i32* %11
br label %23
23: ; preds = %36, %22
%24 = load i32, i32* %11
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %40
27: ; preds = %23
%28 = load i8*, i8** %6
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = call i32 @add_bg_pixel(i8* %31, i32 %32, i32 %33, i32 %34)
br label %36
36: ; preds = %27
%37 = load i32, i32* %12
%38 = load i32, i32* %11
%39 = add nsw i32 %38, %37
store i32 %39, i32* %11
br label %23
40: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @add_bg_row(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
switch i32 %2, label %7 [
i32 521, label %6
i32 2, label %6
i32 1, label %6
]
6: ; preds = %5, %5, %5
br label %7
7: ; preds = %5, %6
%8 = phi i64 [ 3, %6 ], [ 4, %5 ]
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %17
10: ; preds = %7, %10
%11 = phi i64 [ %14, %10 ], [ 0, %7 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = tail call i32 @add_bg_pixel(i8* %12, i32 %2, i32 %3, i32 %4)
%14 = add i64 %11, %8
%15 = trunc i64 %14 to i32
%16 = icmp slt i32 %15, %1
br i1 %16, label %10, label %17
17: ; preds = %10, %7
ret void
}