#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 */
scalar_t__ calloc(int, int);
char *realloc(char *, int);
int /*<<< orphan*/ strchr(char *, char);
scalar_t__ strlen(char *);
char *nodupstring(char *s) {
  int len, i, p;
  char *string;
  len = (int)strlen(s);
  string = (char *)calloc(len + 1, 1);
  p = 0;
  for (i = 0; i < len; i++) {
    if (!strchr(string, s[i])) {
      string[p] = s[i];
      p++;
    }
  }
  string = realloc(string, p + 1);
  return string;
}


x86 assembly (clang, -O0):
<nodupstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d6 <nodupstring+0x96>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
cmp    $0x0,%eax
jne    11c3 <nodupstring+0x83>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c8 <nodupstring+0x88>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117a <nodupstring+0x3a>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nodupstring>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%rbx
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
test   %ebx,%ebx
jle    11ac <nodupstring+0x6c>
mov    %ebx,%r12d
xor    %ebx,%ebx
xor    %r13d,%r13d
jmp    1189 <nodupstring+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     11af <nodupstring+0x6f>
movsbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
call   1040 <strchr@plt>
test   %eax,%eax
jne    1180 <nodupstring+0x40>
movzbl (%r14,%rbx,1),%eax
movslq %r13d,%r13
mov    %al,(%r15,%r13,1)
add    $0x1,%r13d
jmp    1180 <nodupstring+0x40>
xor    %r13d,%r13d
add    $0x1,%r13d
mov    %r15,%rdi
mov    %r13d,%esi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <realloc@plt>

LLVM IR (-O0):
define i8* @nodupstring(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
%12 = call i64 @calloc(i32 %11, i32 1)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
store i32 0, i32* %5
store i32 0, i32* %4
br label %14
14: ; preds = %40, %1
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %43
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = load i8*, i8** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @strchr(i8* %19, i8 signext %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %39, label %27
27: ; preds = %18
%28 = load i8*, i8** %2
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %6
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %39
39: ; preds = %27, %18
br label %40
40: ; preds = %39
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %14
43: ; preds = %14
%44 = load i8*, i8** %6
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
%47 = call i8* @realloc(i8* %44, i32 %46)
store i8* %47, i8** %6
%48 = load i8*, i8** %6
ret i8* %48
}

LLVM IR (-O2):
define i8* @nodupstring(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add nsw i32 %3, 1
%5 = tail call i64 @calloc(i32 %4, i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %26
8: ; preds = %1
%9 = and i64 %2, 4294967295
br label %10
10: ; preds = %8, %22
%11 = phi i64 [ 0, %8 ], [ %24, %22 ]
%12 = phi i32 [ 0, %8 ], [ %23, %22 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %11
%14 = load i8, i8* %13
%15 = tail call i32 @strchr(i8* %6, i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i8, i8* %13
%19 = sext i32 %12 to i64
%20 = getelementptr inbounds i8, i8* %6, i64 %19
store i8 %18, i8* %20
%21 = add nsw i32 %12, 1
br label %22
22: ; preds = %10, %17
%23 = phi i32 [ %12, %10 ], [ %21, %17 ]
%24 = add nuw nsw i64 %11, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %26, label %10
26: ; preds = %22, %1
%27 = phi i32 [ 0, %1 ], [ %23, %22 ]
%28 = add nsw i32 %27, 1
%29 = tail call i8* @realloc(i8* %6, i32 %28)
ret i8* %29
}