#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 *append(char *, char);
char getchar();
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
char *weed(char *, char *);
int main(void) {
  char *str = NULL;
  printf("Enter string: ");
  char ch;
  while ((ch = getchar()) != '\n') {
    str = append(str, ch);
  }
  printf("Enter restricted symbols: ");
  char *restricted = malloc(64 * sizeof(char));
  scanf("%s", restricted);
  str = weed(str, restricted);
  printf("\n\nResult: %s\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     11b1 <main+0x51>
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <append@plt>
mov    %rax,-0x10(%rbp)
jmp    1185 <main+0x25>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <weed@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     11a9 <main+0x49>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %rbx,%rdi
call   1030 <append@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1190 <main+0x30>
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe5f(%rip),%rdi
mov    %rax,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <weed@plt>
lea    0xe48(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter string: \00"
@.str.1 = [27 x i8] c"Enter restricted symbols: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [14 x i8] c"\0A\0AResult: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %10, %0
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = load i8, i8* %3
%13 = call i8* @append(i8* %11, i8 signext %12)
store i8* %13, i8** %2
br label %6
14: ; preds = %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%16 = call i8* @malloc(i32 64)
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %2
%20 = load i8*, i8** %4
%21 = call i8* @weed(i8* %19, i8* %20)
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter string: \00"
@.str.1 = [27 x i8] c"Enter restricted symbols: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [14 x i8] c"\0A\0AResult: %s\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = tail call signext i8 (...) @getchar()
%3 = icmp eq i8 %2, 10
br i1 %3, label %10, label %4
4: ; preds = %0, %4
%5 = phi i8 [ %8, %4 ], [ %2, %0 ]
%6 = phi i8* [ %7, %4 ], [ null, %0 ]
%7 = tail call i8* @append(i8* %6, i8 signext %5)
%8 = tail call signext i8 (...) @getchar()
%9 = icmp eq i8 %8, 10
br i1 %9, label %10, label %4
10: ; preds = %4, %0
%11 = phi i8* [ null, %0 ], [ %7, %4 ]
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
%14 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = tail call i8* @weed(i8* %11, i8* %13)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %15)
ret i32 0
}