#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 */
int /*<<< orphan*/ bt_purify_string(char *, int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(void) {
  char line[1024];
  int line_num;
  int len, i;
  while (!feof(stdin)) {
    if (fgets(line, 1024, stdin)) {
      len = strlen(line);
      if (line[len - 1] == '\n')
        line[len - 1] = '\0';
      line_num++;
      printf("original string = %s\n", line);
      bt_purify_string(line, 0);
      len = strlen(line);
      for (i = len - 1; line[i] == ' '; i--)
        line[i] = (char)0;
      if (len > 0)
        printf("purified string = %s\n", line);
      else
        printf("purified string =\n");
      printf("purified length = %d\n", len);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1185 <main+0x35>
jmp    12c6 <main+0x176>
lea    -0x410(%rbp),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12c1 <main+0x171>
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11ea <main+0x9a>
mov    -0x418(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
call   1070 <bt_purify_string@plt>
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x41c(%rbp)
movslq -0x41c(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    1278 <main+0x128>
movslq -0x41c(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x41c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x41c(%rbp)
jmp    123d <main+0xed>
cmpl   $0x0,-0x418(%rbp)
jle    129f <main+0x14f>
lea    -0x410(%rbp),%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ad <main+0x15d>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x418(%rbp),%esi
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1162 <main+0x12>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    0x2e70(%rip),%r13
mov    0x0(%r13),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     1199 <main+0x39>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbx
lea    0xe5d(%rip),%r14
lea    0xe6c(%rip),%r15
lea    0xe7b(%rip),%r12
jmp    11e5 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%r13),%edi
call   1070 <feof@plt>
test   %eax,%eax
jne    1185 <main+0x25>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11d8 <main+0x78>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1211 <main+0xb1>
movb   $0x0,-0x1(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <bt_purify_string@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
cltq
cmpb   $0x20,-0x1(%rsp,%rax,1)
jne    125d <main+0xfd>
add    $0xffffffffffffffff,%rax
add    %rsp,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%rax)
cmpb   $0x20,-0x1(%rax)
lea    -0x1(%rax),%rax
je     1250 <main+0xf0>
test   %ebp,%ebp
jle    11c0 <main+0x60>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11cc <main+0x6c>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [22 x i8] c"original string = %s\0A\00"
@.str.1 = [22 x i8] c"purified string = %s\0A\00"
@.str.2 = [19 x i8] c"purified string =\0A\00"
@.str.3 = [22 x i8] c"purified length = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %67, %0
%7 = load i32, i32* @stdin
%8 = call i32 @feof(i32 %7)
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
br i1 %10, label %11, label %68
11: ; preds = %6
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i64 @fgets(i8* %12, i32 1024, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %67
16: ; preds = %11
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %31
26: ; preds = %16
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %26, %16
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%37 = call i32 @bt_purify_string(i8* %36, i32 0)
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
store i32 %39, i32* %4
%40 = load i32, i32* %4
%41 = sub nsw i32 %40, 1
store i32 %41, i32* %5
br label %42
42: ; preds = %53, %31
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 32
br i1 %48, label %49, label %56
49: ; preds = %42
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %51
store i8 0, i8* %52
br label %53
53: ; preds = %49
%54 = load i32, i32* %5
%55 = add nsw i32 %54, -1
store i32 %55, i32* %5
br label %42
56: ; preds = %42
%57 = load i32, i32* %4
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %60)
br label %64
62: ; preds = %56
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %64
64: ; preds = %62, %59
%65 = load i32, i32* %4
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64, %11
br label %6
68: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [22 x i8] c"original string = %s\0A\00"
@.str.1 = [22 x i8] c"purified string = %s\0A\00"
@.str.3 = [22 x i8] c"purified length = %d\0A\00"
@str = [18 x i8] c"purified string =\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @feof(i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %46
6: ; preds = %0, %42
%7 = load i32, i32* @stdin
%8 = call i64 @fgets(i8* %2, i32 1024, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %42, label %10
10: ; preds = %6
%11 = call i32 @strlen(i8* %2)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %18
17: ; preds = %10
store i8 0, i8* %14
br label %18
18: ; preds = %17, %10
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %2)
%20 = call i32 @bt_purify_string(i8* %2, i32 0)
%21 = call i32 @strlen(i8* %2)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 32
br i1 %26, label %27, label %34
27: ; preds = %18, %27
%28 = phi i64 [ %30, %27 ], [ %23, %18 ]
%29 = phi i8* [ %31, %27 ], [ %24, %18 ]
store i8 0, i8* %29
%30 = add i64 %28, -1
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 32
br i1 %33, label %27, label %34
34: ; preds = %27, %18
%35 = icmp sgt i32 %21, 0
br i1 %35, label %36, label %38
36: ; preds = %34
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %40
38: ; preds = %34
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %38, %36
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %42
42: ; preds = %40, %6
%43 = load i32, i32* @stdin
%44 = call i32 @feof(i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %6, label %46
46: ; preds = %42, %0
ret i32 0
}