#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);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ remove_dup(char *);
int /*<<< orphan*/ remove_dup_sort(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main() {
  char *input = (char *)calloc(100, sizeof(char));
  char *copy;
  fgets(input, 100, stdin);
  input[strlen(input) - 1] = '\0';
  copy = (char *)calloc(strlen(input) + 1, sizeof(char));
  strcpy(copy, input);
  printf("%s\n", input);
  remove_dup_sort(input);
  printf("%s\n\n", input);
  printf("%s\n", copy);
  remove_dup(copy);
  printf("%s\n", copy);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1080 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rsi
lea    0xe02(%rip),%rdi
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <remove_dup_sort@plt>
mov    -0x10(%rbp),%rsi
lea    0xded(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <remove_dup@plt>
mov    -0x18(%rbp),%rsi
lea    0xdc0(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x64,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,%rbx
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe2a(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <remove_dup_sort@plt>
lea    0xe14(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
mov    %r14,%rdi
call   1040 <remove_dup@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [5 x i8] c"%s\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i64 @calloc(i32 100, i32 1)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 100, i32 %7)
%9 = load i8*, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
store i8 0, i8* %14
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 1
%18 = call i64 @calloc(i32 %17, i32 1)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = load i8*, i8** %2
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %2
%26 = call i32 @remove_dup_sort(i8* %25)
%27 = load i8*, i8** %2
%28 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %3
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %3
%32 = call i32 @remove_dup(i8* %31)
%33 = load i8*, i8** %3
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %33)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [5 x i8] c"%s\0A\0A\00"
define i32 @main() {
%1 = tail call i64 @calloc(i32 100, i32 1)
%2 = inttoptr i64 %1 to i8*
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %2, i32 100, i32 %3)
%5 = tail call i32 @strlen(i8* %2)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %2, i64 %7
store i8 0, i8* %8
%9 = tail call i32 @strlen(i8* %2)
%10 = add nsw i32 %9, 1
%11 = tail call i64 @calloc(i32 %10, i32 1)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @strcpy(i8* %12, i8* %2)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%15 = tail call i32 @remove_dup_sort(i8* %2)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
%18 = tail call i32 @remove_dup(i8* %12)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
ret i32 0
}