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

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *const, int const *const, size_t const);
void apply_filter(void *arg, const uint64_t ts, const int w, const int h,
                  const uint8_t *const prev_frame,
                  const uint8_t *const current_frame, uint8_t *const result) {
  const size_t bytes = w * h * 3;
  memcpy(result, current_frame, bytes);
  for (size_t i = 0; i < bytes; i += 3)
    result[i + 0] ^= 0xff;
}


x86 assembly (clang, -O0):
<apply_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
imul   $0x3,%eax,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <memcpy@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    118d <apply_filter+0x7d>
mov    0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
xor    $0xff,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x38(%rbp)
jmp    115a <apply_filter+0x4a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_filter>:
push   %r14
push   %rbx
push   %rax
mov    %r9,%rsi
mov    0x20(%rsp),%r14
imul   %ecx,%edx
lea    (%rdx,%rdx,2),%eax
movslq %eax,%rbx
mov    %r14,%rdi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
test   %ebx,%ebx
je     114d <apply_filter+0x3d>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
notb   (%r14,%rax,4)
add    $0x3,%rax
cmp    %rbx,%rax
jb     1140 <apply_filter+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @apply_filter(i8* nocapture readnone %0, i32 %1, i32 %2, i32 %3, i32* nocapture readnone %4, i32* %5, i32* %6) {
%8 = mul i32 %2, 3
%9 = mul i32 %8, %3
%10 = sext i32 %9 to i64
%11 = tail call i32 @memcpy(i32* %6, i32* %5, i64 %10)
%12 = icmp eq i32 %9, 0
br i1 %12, label %13, label %14
13: ; preds = %14, %7
ret void
14: ; preds = %7, %14
%15 = phi i64 [ %19, %14 ], [ 0, %7 ]
%16 = getelementptr inbounds i32, i32* %6, i64 %15
%17 = load i32, i32* %16
%18 = xor i32 %17, 255
store i32 %18, i32* %16
%19 = add i64 %15, 3
%20 = icmp ult i64 %19, %10
br i1 %20, label %14, label %13
}