#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 _getline(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int length, counter;
  char line[1000];
  while ((length = _getline(line, 1000)) > 0) {
    counter = length - 1;
    int k, character;
    k = 0;
    while (character = line[k] != '\0') {
      ++k;
    }
    printf("line length before strip: %d\n", k);
    while (line[counter] == ' ' || line[counter] == '\n' ||
           line[counter] == '\t') {
      --counter;
    }
    line[++counter] = '\n';
    line[++counter] = '\0';
    k = 0;
    while (character = line[k] != '\0') {
      ++k;
    }
    printf("line length after strip: %d\n", k);
    printf("line without trailing spaces:\n%s", line);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <_getline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    12cf <main+0x1af>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x404(%rbp)
movslq -0x404(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
setne  %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x408(%rbp)
test   $0x1,%al
jne    1192 <main+0x72>
jmp    11a6 <main+0x86>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    1162 <main+0x42>
mov    -0x404(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0xc(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%ecx
ff
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x409(%rbp)
je     120c <main+0xec>
movslq -0xc(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%ecx
ff
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x409(%rbp)
je     120c <main+0xec>
movslq -0xc(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0x9,%eax
sete   %al
mov    %al,-0x409(%rbp)
mov    -0x409(%rbp),%al
test   $0x1,%al
jne    121f <main+0xff>
jmp    122d <main+0x10d>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11ba <main+0x9a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cltq
movb   $0xa,-0x400(%rbp,%rax,1)
0a
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cltq
movb   $0x0,-0x400(%rbp,%rax,1)
movl   $0x0,-0x404(%rbp)
movslq -0x404(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
setne  %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x408(%rbp)
test   $0x1,%al
jne    128d <main+0x16d>
jmp    12a1 <main+0x181>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    125d <main+0x13d>
mov    -0x404(%rbp),%esi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x400(%rbp),%rsi
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1132 <main+0x12>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1040 <_getline@plt>
test   %eax,%eax
jle    123a <main+0x11a>
mov    %eax,%ebp
lea    0xecc(%rip),%r15
lea    0xee2(%rip),%r12
movabs $0x100000600,%r14
movabs $0xffffffff00000000,%r13
ff ff ff
nopl   (%rax)
mov    $0xffffffff,%esi
mov    %rbx,%rax
nopl   0x0(%rax,%rax,1)
add    $0x1,%esi
cmpb   $0x0,(%rax)
lea    0x1(%rax),%rax
jne    1180 <main+0x60>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movslq %ebp,%rax
lea    -0x1(%rsp),%rcx
add    %rax,%rcx
shl    $0x20,%rax
nopl   0x0(%rax)
movzbl (%rcx),%edx
cmp    $0x20,%rdx
ja     11d0 <main+0xb0>
bt     %rdx,%r14
jae    11d0 <main+0xb0>
add    %r13,%rax
add    $0xffffffffffffffff,%rcx
jmp    11b0 <main+0x90>
nopl   0x0(%rax,%rax,1)
mov    %rax,%rcx
sar    $0x20,%rcx
movb   $0xa,(%rsp,%rcx,1)
movabs $0x100000000,%rcx
add    %rcx,%rax
sar    $0x20,%rax
movb   $0x0,(%rsp,%rax,1)
mov    $0xffffffff,%esi
mov    %rbx,%rax
nopl   0x0(%rax,%rax,1)
add    $0x1,%esi
cmpb   $0x0,(%rax)
lea    0x1(%rax),%rax
jne    1200 <main+0xe0>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1040 <_getline@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1170 <main+0x50>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [30 x i8] c"line length before strip: %d\0A\00"
@.str.1 = [29 x i8] c"line length after strip: %d\0A\00"
@.str.2 = [33 x i8] c"line without trailing spaces:\0A%s\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = call i32 @_getline(i8* %2, i32 1000)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %43
5: ; preds = %0, %37
%6 = phi i32 [ %41, %37 ], [ %3, %0 ]
br label %7
7: ; preds = %7, %5
%8 = phi i64 [ %12, %7 ], [ 0, %5 ]
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
%12 = add nuw i64 %8, 1
br i1 %11, label %13, label %7
13: ; preds = %7
%14 = trunc i64 %8 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = sext i32 %6 to i64
br label %17
17: ; preds = %22, %13
%18 = phi i64 [ %16, %13 ], [ %19, %22 ]
%19 = add i64 %18, -1
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
switch i8 %21, label %23 [
i8 32, label %22
i8 10, label %22
i8 9, label %22
]
22: ; preds = %17, %17, %17
br label %17
23: ; preds = %17
%24 = shl i64 %18, 32
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %25
store i8 10, i8* %26
%27 = shl i64 %18, 32
%28 = add i64 %27, 4294967296
%29 = ashr exact i64 %28, 32
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %31, %23
%32 = phi i64 [ %36, %31 ], [ 0, %23 ]
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
%36 = add nuw i64 %32, 1
br i1 %35, label %37, label %31
37: ; preds = %31
%38 = trunc i64 %32 to i32
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%41 = call i32 @_getline(i8* %2, i32 1000)
%42 = icmp sgt i32 %41, 0
br i1 %42, label %5, label %43
43: ; preds = %37, %0
ret i32 0
}