#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*/ png_apply_specific_filter_32(int, unsigned char *,
                                                unsigned char *, unsigned int);
int /*<<< orphan*/ png_apply_specific_filter_8(int, unsigned char *,
                                               unsigned char *, unsigned int);
int png_find_best_filter(unsigned char *, unsigned int, int, int);
int png_apply_filter(unsigned char *dest, unsigned char *src, unsigned width,
                     int y, int bpp) {
  int best_nr = 0;
  best_nr = png_find_best_filter(src, width, bpp, y);
  if (bpp == 8)
    png_apply_specific_filter_8(best_nr, dest, src, width);
  else
    png_apply_specific_filter_32(best_nr, dest, src, width);
  return best_nr;
}


x86 assembly (clang, -O0):
<png_apply_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <png_find_best_filter@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jne    1188 <png_apply_filter+0x58>
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1050 <png_apply_specific_filter_8@plt>
jmp    119b <png_apply_filter+0x6b>
mov    -0x20(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1030 <png_apply_specific_filter_32@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<png_apply_filter>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%ebp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
mov    %edx,%esi
mov    %r8d,%edx
call   1040 <png_find_best_filter@plt>
mov    %eax,%r12d
mov    %eax,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
cmp    $0x8,%ebp
jne    116b <png_apply_filter+0x3b>
call   1050 <png_apply_specific_filter_8@plt>
jmp    1170 <png_apply_filter+0x40>
call   1030 <png_apply_specific_filter_32@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @png_apply_filter(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 0, i32* %11
%12 = load i8*, i8** %7
%13 = load i32, i32* %8
%14 = load i32, i32* %10
%15 = load i32, i32* %9
%16 = call i32 @png_find_best_filter(i8* %12, i32 %13, i32 %14, i32 %15)
store i32 %16, i32* %11
%17 = load i32, i32* %10
%18 = icmp eq i32 %17, 8
br i1 %18, label %19, label %25
19: ; preds = %5
%20 = load i32, i32* %11
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = call i32 @png_apply_specific_filter_8(i32 %20, i8* %21, i8* %22, i32 %23)
br label %31
25: ; preds = %5
%26 = load i32, i32* %11
%27 = load i8*, i8** %6
%28 = load i8*, i8** %7
%29 = load i32, i32* %8
%30 = call i32 @png_apply_specific_filter_32(i32 %26, i8* %27, i8* %28, i32 %29)
br label %31
31: ; preds = %25, %19
%32 = load i32, i32* %11
ret i32 %32
}

LLVM IR (-O2):
define i32 @png_apply_filter(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 @png_find_best_filter(i8* %1, i32 %2, i32 %4, i32 %3)
%7 = icmp eq i32 %4, 8
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @png_apply_specific_filter_8(i32 %6, i8* %0, i8* %1, i32 %2)
br label %12
10: ; preds = %5
%11 = tail call i32 @png_apply_specific_filter_32(i32 %6, i8* %0, i8* %1, i32 %2)
br label %12
12: ; preds = %10, %8
ret i32 %6
}