#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 wchar_t;

/* Variables and functions */
int /*<<< orphan*/ *wcschr(int *, int);
size_t wcslen(int *);
int /*<<< orphan*/ wcsncat(int *, int *, int);
void copy_without_dupes(wchar_t *dest, wchar_t *src) {
  size_t i;
  size_t len = wcslen(src);
  dest[0] = L'\0';
  for (i = 0; i < len; ++i) {
    if (wcschr(dest, src[i]) == NULL)
      wcsncat(dest, &src[i], 1);
  }
}


x86 assembly (clang, -O0):
<copy_without_dupes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <wcslen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11be <copy_without_dupes+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <wcschr@plt>
cmp    $0x0,%rax
jne    11a8 <copy_without_dupes+0x78>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <wcsncat@plt>
jmp    11ad <copy_without_dupes+0x7d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115f <copy_without_dupes+0x2f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_without_dupes>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <wcslen@plt>
movl   $0x0,(%r14)
test   %rax,%rax
je     118b <copy_without_dupes+0x5b>
mov    %rax,%r15
jmp    116a <copy_without_dupes+0x3a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x4,%rbx
add    $0xffffffffffffffff,%r15
je     118b <copy_without_dupes+0x5b>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1050 <wcschr@plt>
test   %rax,%rax
jne    1160 <copy_without_dupes+0x30>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <wcsncat@plt>
jmp    1160 <copy_without_dupes+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @copy_without_dupes(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = call i64 @wcslen(i32* %7)
store i64 %8, i64* %6
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 0
store i32 0, i32* %10
store i64 0, i64* %5
br label %11
11: ; preds = %30, %2
%12 = load i64, i64* %5
%13 = load i64, i64* %6
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = load i32*, i32** %4
%18 = load i64, i64* %5
%19 = getelementptr inbounds i32, i32* %17, i64 %18
%20 = load i32, i32* %19
%21 = call i32* @wcschr(i32* %16, i32 %20)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %15
%24 = load i32*, i32** %3
%25 = load i32*, i32** %4
%26 = load i64, i64* %5
%27 = getelementptr inbounds i32, i32* %25, i64 %26
%28 = call i32 @wcsncat(i32* %24, i32* %27, i32 1)
br label %29
29: ; preds = %23, %15
br label %30
30: ; preds = %29
%31 = load i64, i64* %5
%32 = add i64 %31, 1
store i64 %32, i64* %5
br label %11
33: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @copy_without_dupes(i32* %0, i32* %1) {
%3 = tail call i64 @wcslen(i32* %1)
store i32 0, i32* %0
%4 = icmp eq i64 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %2, %13
%6 = phi i64 [ %14, %13 ], [ 0, %2 ]
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32* @wcschr(i32* %0, i32 %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @wcsncat(i32* %0, i32* %7, i32 1)
br label %13
13: ; preds = %5, %11
%14 = add nuw i64 %6, 1
%15 = icmp eq i64 %14, %3
br i1 %15, label %16, label %5
16: ; preds = %13, %2
ret void
}