#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 */
char *malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
char *nodup(char *, int *);
int strlen(char *);
char *dup(char *input, int *dict) {
  char *output = malloc(strlen(input) + 1);
  int i, outpt = 0;
  for (i = 0; i < strlen(input); i++)
    if (dict[input[i] - 'A'] > 1)
      output[outpt++] = input[i];
  output[outpt] = '\0';
  int ndict[26];
  memset(ndict, 0, 26 * sizeof(int));
  return nodup(output, ndict);
}


x86 assembly (clang, -O0):
<dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x94(%rbp),%eax
cmp    %ecx,%eax
jge    11ed <dup+0xad>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x41,%ecx
movslq %ecx,%rcx
cmpl   $0x1,(%rax,%rcx,4)
jle    11da <dup+0x9a>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11df <dup+0x9f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <dup+0x38>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x68,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1040 <nodup@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dup>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11b0 <dup+0x70>
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    1193 <dup+0x53>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    11b3 <dup+0x73>
movsbq (%rbx,%rbp,1),%rax
cmpl   $0x2,-0x104(%r15,%rax,4)
ff 02
jl     1180 <dup+0x40>
movslq %r12d,%rcx
add    $0x1,%r12d
mov    %al,(%r14,%rcx,1)
jmp    1180 <dup+0x40>
xor    %r12d,%r12d
movslq %r12d,%rax
movb   $0x0,(%r14,%rax,1)
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x68,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <nodup@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @dup(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [26 x i32]
store i8* %0, i8** %3
store i32* %1, i32** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 1
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %5
store i32 0, i32* %7
store i32 0, i32* %6
br label %13
13: ; preds = %43, %2
%14 = load i32, i32* %6
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %46
18: ; preds = %13
%19 = load i32*, i32** %4
%20 = load i8*, i8** %3
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = sub nsw i32 %25, 65
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %19, i64 %27
%29 = load i32, i32* %28
%30 = icmp sgt i32 %29, 1
br i1 %30, label %31, label %42
31: ; preds = %18
%32 = load i8*, i8** %3
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = load i8*, i8** %5
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 %36, i8* %41
br label %42
42: ; preds = %31, %18
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %13
46: ; preds = %13
%47 = load i8*, i8** %5
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = getelementptr inbounds [26 x i32], [26 x i32]* %8, i64 0, i64 0
%52 = call i32 @memset(i32* %51, i32 0, i32 104)
%53 = load i8*, i8** %5
%54 = getelementptr inbounds [26 x i32], [26 x i32]* %8, i64 0, i64 0
%55 = call i8* @nodup(i8* %53, i32* %54)
ret i8* %55
}

LLVM IR (-O2):
define i8* @dup(i8* %0, i32* nocapture %1) {
%3 = alloca [26 x i32]
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %2, %23
%10 = phi i64 [ %25, %23 ], [ 0, %2 ]
%11 = phi i32 [ %24, %23 ], [ 0, %2 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = sext i8 %13 to i64
%15 = add nsw i64 %14, -65
%16 = getelementptr inbounds i32, i32* %1, i64 %15
%17 = load i32, i32* %16
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %9
%20 = add nsw i32 %11, 1
%21 = sext i32 %11 to i64
%22 = getelementptr inbounds i8, i8* %6, i64 %21
store i8 %13, i8* %22
br label %23
23: ; preds = %9, %19
%24 = phi i32 [ %20, %19 ], [ %11, %9 ]
%25 = add nuw nsw i64 %10, 1
%26 = tail call i32 @strlen(i8* %0)
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %9, label %29
29: ; preds = %23, %2
%30 = phi i32 [ 0, %2 ], [ %24, %23 ]
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %6, i64 %31
store i8 0, i8* %32
%33 = bitcast [26 x i32]* %3 to i8*
%34 = getelementptr inbounds [26 x i32], [26 x i32]* %3, i64 0, i64 0
%35 = call i32 @memset(i32* %34, i32 0, i32 104)
%36 = call i8* @nodup(i8* %6, i32* %34)
ret i8* %36
}