#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 my_getline(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main() {
  char line[100] = {0};
  int max = 0, len;
  unsigned int tmp;
  while (len = my_getline(line, 100)) {
    printf("len : %d\n", len);
    if (len > 1) {
      if ((line[len] == '\0') && (line[len - 1] == '\n')) {
        tmp = len - 2;
        while (tmp >= 0) {
          if (line[tmp] == ' ' || line[tmp] == '\t') {
            line[tmp] = line[tmp + 1];
            line[tmp + 1] = line[tmp + 2];
          } else
            break;
          tmp--;
        }
      }
    }
    printf("After line : %s strlen(line): %d\n", line, strlen(line));
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
movl   $0x0,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x64,%esi
call   1060 <my_getline@plt>
mov    %eax,-0x78(%rbp)
cmp    $0x0,%eax
je     1278 <main+0x138>
mov    -0x78(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x78(%rbp)
jle    1248 <main+0x108>
movslq -0x78(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
jne    1243 <main+0x103>
mov    -0x78(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    1243 <main+0x103>
mov    -0x78(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jb     123e <main+0xfe>
mov    -0x7c(%rbp),%eax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x20,%eax
je     11fb <main+0xbb>
mov    -0x7c(%rbp),%eax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x9,%eax
jne    122b <main+0xeb>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
mov    -0x70(%rbp,%rax,1),%cl
mov    -0x7c(%rbp),%eax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x7c(%rbp),%eax
add    $0x2,%eax
mov    %eax,%eax
mov    -0x70(%rbp,%rax,1),%cl
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
mov    %cl,-0x70(%rbp,%rax,1)
jmp    1230 <main+0xf0>
jmp    123e <main+0xfe>
mov    -0x7c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x7c(%rbp)
jmp    11cf <main+0x8f>
jmp    1243 <main+0x103>
jmp    1248 <main+0x108>
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1169 <main+0x29>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    %rsp,%rdi
mov    $0x64,%esi
call   1060 <my_getline@plt>
test   %eax,%eax
je     120f <main+0xcf>
mov    %eax,%ebx
lea    0xe6f(%rip),%r14
mov    %rsp,%r12
lea    0xe6f(%rip),%r15
jmp    11ca <main+0x8a>
nopl   (%rax)
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x64,%esi
call   1060 <my_getline@plt>
mov    %eax,%ebx
test   %eax,%eax
je     120f <main+0xcf>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%ebx
jl     11a0 <main+0x60>
mov    %ebx,%eax
cmpb   $0x0,(%rsp,%rax,1)
jne    11a0 <main+0x60>
add    $0xffffffff,%ebx
cmpb   $0xa,(%rsp,%rbx,1)
je     11fc <main+0xbc>
jmp    11a0 <main+0x60>
xchg   %ax,%ax
mov    %ebx,%ecx
movb   $0xa,(%rsp,%rax,1)
movb   $0x0,(%rsp,%rcx,1)
mov    %eax,%ebx
lea    -0x1(%rbx),%eax
movzbl (%rsp,%rax,1),%ecx
cmp    $0x20,%cl
je     11f0 <main+0xb0>
cmp    $0x9,%cl
je     11f0 <main+0xb0>
jmp    11a0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"len : %d\0A\00"
@.str.1 = [34 x i8] c"After line : %s strlen(line): %d\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [100 x i8]* %2 to i8*
store i32 0, i32* %3
br label %7
7: ; preds = %75, %0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%9 = call i32 @my_getline(i8* %8, i32 100)
store i32 %9, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %80
11: ; preds = %7
%12 = load i32, i32* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %75
16: ; preds = %11
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %74
23: ; preds = %16
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br i1 %30, label %31, label %74
31: ; preds = %23
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 2
store i32 %33, i32* %5
br label %34
34: ; preds = %70, %31
%35 = load i32, i32* %5
%36 = icmp uge i32 %35, 0
br i1 %36, label %37, label %73
37: ; preds = %34
%38 = load i32, i32* %5
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 32
br i1 %43, label %51, label %44
44: ; preds = %37
%45 = load i32, i32* %5
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 9
br i1 %50, label %51, label %69
51: ; preds = %44, %37
%52 = load i32, i32* %5
%53 = add i32 %52, 1
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = load i32, i32* %5
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %58
store i8 %56, i8* %59
%60 = load i32, i32* %5
%61 = add i32 %60, 2
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = load i32, i32* %5
%66 = add i32 %65, 1
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %67
store i8 %64, i8* %68
br label %70
69: ; preds = %44
br label %73
70: ; preds = %51
%71 = load i32, i32* %5
%72 = add i32 %71, -1
store i32 %72, i32* %5
br label %34
73: ; preds = %69, %34
br label %74
74: ; preds = %73, %23, %16
br label %75
75: ; preds = %74, %11
%76 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%77 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%78 = call i32 @strlen(i8* %77)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %76, i32 %78)
br label %7
80: ; preds = %7
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"len : %d\0A\00"
@.str.1 = [34 x i8] c"After line : %s strlen(line): %d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @my_getline(i8* %2, i32 100)
%4 = icmp eq i32 %3, 0
br i1 %4, label %37, label %5
5: ; preds = %0, %32
%6 = phi i32 [ %35, %32 ], [ %3, %0 ]
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp sgt i32 %6, 1
br i1 %8, label %9, label %32
9: ; preds = %5
%10 = zext i32 %6 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %9
%15 = add nsw i32 %6, -1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %32
20: ; preds = %14
%21 = add nsw i32 %6, -2
br label %22
22: ; preds = %27, %20
%23 = phi i32 [ %21, %20 ], [ %31, %27 ]
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
switch i8 %26, label %32 [
i8 32, label %27
i8 9, label %27
]
27: ; preds = %22, %22
%28 = add i32 %23, 1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %29
store i8 10, i8* %25
store i8 0, i8* %30
%31 = add i32 %23, -1
br label %22
32: ; preds = %22, %9, %14, %5
%33 = call i32 @strlen(i8* %2)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %33)
%35 = call i32 @my_getline(i8* %2, i32 100)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %5
37: ; preds = %32, %0
%38 = call i32 @putchar(i32 10)
ret i32 0
}