#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 strlen(char *);
char *nnodup(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';
  return output;
}


x86 assembly (clang, -O0):
<nnodup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11c4 <nnodup+0xa4>
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)
jne    11b1 <nnodup+0x91>
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    11b6 <nnodup+0x96>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <nnodup+0x35>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nnodup>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1190 <nnodup+0x70>
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    1173 <nnodup+0x53>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    1193 <nnodup+0x73>
movsbq (%rbx,%rbp,1),%rax
cmpl   $0x1,-0x104(%r14,%rax,4)
ff 01
jne    1160 <nnodup+0x40>
movslq %r12d,%rcx
add    $0x1,%r12d
mov    %al,(%r15,%rcx,1)
jmp    1160 <nnodup+0x40>
xor    %r12d,%r12d
movslq %r12d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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