#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*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void cleanString(char *key) {
  int i;
  if (((int)key[0] == 10) || ((int)key[0] == 32)) {
    printf("aa -%s-\n", key);
    i = 0;
    while (((int)key[i] == 10) || ((int)key[i] == 32)) {
      ++i;
    }
    strcpy(key, key + i);
    printf("ab -%s-\n", key);
    i = strlen(key);
    --i;
    printf("1 i %i\n", i);
    while (((int)key[i] == 10) || ((int)key[i] == 32)) {
      --i;
    }
    ++i;
    printf("2 i %i\n", i);
    key[i] = '\0';
    printf("ac -%s-\n", key);
  }
}


x86 assembly (clang, -O0):
<cleanString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     115c <cleanString+0x2c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1293 <cleanString+0x163>
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0xd(%rbp)
je     11a4 <cleanString+0x74>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11b4 <cleanString+0x84>
jmp    11c2 <cleanString+0x92>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <cleanString+0x45>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rsi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0xe(%rbp)
je     123d <cleanString+0x10d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
test   $0x1,%al
jne    124d <cleanString+0x11d>
jmp    125b <cleanString+0x12b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    120e <cleanString+0xde>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rsi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%al
cmp    $0x20,%al
je     1145 <cleanString+0x15>
cmp    $0xa,%al
jne    1204 <cleanString+0xd4>
lea    0xeb4(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1164 <cleanString+0x34>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
movzbl (%r14,%rbx,1),%eax
cmp    $0x20,%al
je     1160 <cleanString+0x30>
cmp    $0xa,%al
je     1160 <cleanString+0x30>
mov    %ebx,%esi
add    %r14,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xe84(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%esi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movslq %ebx,%rax
add    %r14,%rax
add    $0xffffffffffffffff,%rax
jmp    11c7 <cleanString+0x97>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%rax
movzbl (%rax),%ecx
cmp    $0x20,%cl
je     11c0 <cleanString+0x90>
cmp    $0xa,%cl
je     11c0 <cleanString+0x90>
lea    0xe3f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
lea    0xe2f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"aa -%s-\0A\00"
@.str.1 = [9 x i8] c"ab -%s-\0A\00"
@.str.2 = [8 x i8] c"1 i %i\0A\00"
@.str.3 = [8 x i8] c"2 i %i\0A\00"
@.str.4 = [9 x i8] c"ac -%s-\0A\00"
define void @cleanString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 10
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 32
br i1 %14, label %15, label %86
15: ; preds = %9, %1
%16 = load i8*, i8** %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 0, i32* %3
br label %18
18: ; preds = %36, %15
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%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 = icmp eq i32 %24, 10
br i1 %25, label %34, label %26
26: ; preds = %18
%27 = load i8*, i8** %2
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 32
br label %34
34: ; preds = %26, %18
%35 = phi i1 [ true, %18 ], [ %33, %26 ]
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %18
39: ; preds = %34
%40 = load i8*, i8** %2
%41 = load i8*, i8** %2
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = call i32 @strcpy(i8* %40, i8* %44)
%46 = load i8*, i8** %2
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %2
%49 = call i32 @strlen(i8* %48)
store i32 %49, i32* %3
%50 = load i32, i32* %3
%51 = add nsw i32 %50, -1
store i32 %51, i32* %3
%52 = load i32, i32* %3
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %72, %39
%55 = load i8*, i8** %2
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 10
br i1 %61, label %70, label %62
62: ; preds = %54
%63 = load i8*, i8** %2
%64 = load i32, i32* %3
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 32
br label %70
70: ; preds = %62, %54
%71 = phi i1 [ true, %54 ], [ %69, %62 ]
br i1 %71, label %72, label %75
72: ; preds = %70
%73 = load i32, i32* %3
%74 = add nsw i32 %73, -1
store i32 %74, i32* %3
br label %54
75: ; preds = %70
%76 = load i32, i32* %3
%77 = add nsw i32 %76, 1
store i32 %77, i32* %3
%78 = load i32, i32* %3
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %78)
%80 = load i8*, i8** %2
%81 = load i32, i32* %3
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 0, i8* %83
%84 = load i8*, i8** %2
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %84)
br label %86
86: ; preds = %75, %9
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"aa -%s-\0A\00"
@.str.1 = [9 x i8] c"ab -%s-\0A\00"
@.str.2 = [8 x i8] c"1 i %i\0A\00"
@.str.3 = [8 x i8] c"2 i %i\0A\00"
@.str.4 = [9 x i8] c"ac -%s-\0A\00"
define void @cleanString(i8* %0) {
%2 = load i8, i8* %0
switch i8 %2, label %33 [
i8 10, label %3
i8 32, label %3
]
3: ; preds = %1, %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %5
5: ; preds = %9, %3
%6 = phi i64 [ %10, %9 ], [ 0, %3 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %11 [
i8 10, label %9
i8 32, label %9
]
9: ; preds = %5, %5
%10 = add nuw i64 %6, 1
br label %5
11: ; preds = %5
%12 = and i64 %6, 4294967295
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i32 @strcpy(i8* %0, i8* %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = tail call i32 @strlen(i8* %0)
%17 = add nsw i32 %16, -1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = sext i32 %17 to i64
br label %20
20: ; preds = %24, %11
%21 = phi i64 [ %25, %24 ], [ %19, %11 ]
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
switch i8 %23, label %26 [
i8 10, label %24
i8 32, label %24
]
24: ; preds = %20, %20
%25 = add i64 %21, -1
br label %20
26: ; preds = %20
%27 = trunc i64 %21 to i32
%28 = add nsw i32 %27, 1
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
store i8 0, i8* %31
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %33
33: ; preds = %1, %26
ret void
}