#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 /*<<< orphan*/ const *wmemchr;
typedef int /*<<< orphan*/ const wchar_t;

/* Variables and functions */
int /*<<< orphan*/ wmemcpy(int /*<<< orphan*/ const *,
                           int /*<<< orphan*/ const *, size_t);
wchar_t *wmemccpy(wchar_t *restrict whither, const wchar_t *restrict whence,
                  wchar_t c, size_t size) {
  wchar_t *stop = (wmemchr)(whence, c, size);
  wchar_t *r = NULL;
  if (stop != NULL)
    size = (size_t)(stop - whence), r = whither + size;
  wmemcpy(whither, whence, size);
  return r;
}


x86 assembly (clang, -O0):
<wmemccpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1168 <wmemccpy+0x58>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <wmemcpy@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wmemccpy>:
push   %rbx
mov    %rcx,%rdx
sub    %rsi,%rdx
lea    (%rdi,%rdx,1),%rbx
sar    $0x2,%rdx
test   %rcx,%rcx
cmove  %rcx,%rdx
cmove  %rcx,%rbx
call   1030 <wmemcpy@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i32* @wmemccpy(i32* noalias %0, i32* noalias %1, i32 %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i64 %3, i64* %8
%11 = load i32*, i32** %6
%12 = load i32, i32* %7
%13 = load i64, i64* %8
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %9
store i32* null, i32** %10
%15 = load i32*, i32** %9
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %27
17: ; preds = %4
%18 = load i32*, i32** %9
%19 = load i32*, i32** %6
%20 = ptrtoint i32* %18 to i64
%21 = ptrtoint i32* %19 to i64
%22 = sub i64 %20, %21
%23 = sdiv exact i64 %22, 4
store i64 %23, i64* %8
%24 = load i32*, i32** %5
%25 = load i64, i64* %8
%26 = getelementptr inbounds i32, i32* %24, i64 %25
store i32* %26, i32** %10
br label %27
27: ; preds = %17, %4
%28 = load i32*, i32** %5
%29 = load i32*, i32** %6
%30 = load i64, i64* %8
%31 = call i32 @wmemcpy(i32* %28, i32* %29, i64 %30)
%32 = load i32*, i32** %10
ret i32* %32
}

LLVM IR (-O2):
define i32* @wmemccpy(i32* noalias %0, i32* noalias %1, i32 %2, i64 %3) {
%5 = icmp eq i64 %3, 0
%6 = ptrtoint i32* %1 to i64
%7 = sub i64 %3, %6
%8 = ashr exact i64 %7, 2
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = select i1 %5, i64 0, i64 %8
%11 = select i1 %5, i32* null, i32* %9
%12 = tail call i32 @wmemcpy(i32* %0, i32* %1, i64 %10)
ret i32* %11
}