#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 getlines(char *, int);
int len(char *);
int /*<<< orphan*/ print_line(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ reverse(char *, char *);
int rstrip_index(char *);
main() {
  int length;
  int limit = 100;
  char line[limit];
  while ((length = getlines(line, limit)) > 0) {
    print_line(line);
    printf("length: %d\n", len(line));
    char reversed_line[limit];
    reverse(line, reversed_line);
    print_line(reversed_line);
    int i;
    int index = rstrip_index(line);
    char array[index + 1];
    for (i = 0; i <= index; ++i) {
      array[i] = line[i];
    }
    array[index + 1] = '\0';
    printf("\nrstrip: ");
    print_line(array);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <getlines@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    12a7 <main+0x147>
mov    -0x48(%rbp),%rdi
call   1050 <print_line@plt>
mov    -0x48(%rbp),%rdi
call   1030 <len@plt>
mov    %eax,%esi
lea    0xe31(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x58(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
call   1040 <reverse@plt>
mov    -0x58(%rbp),%rdi
call   1050 <print_line@plt>
mov    -0x48(%rbp),%rdi
call   1070 <rstrip_index@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jg     1273 <main+0x113>
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rcx
movslq -0x34(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1243 <main+0xe3>
mov    -0x50(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x50(%rbp),%rdi
call   1050 <print_line@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    119c <main+0x3c>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    -0x90(%rbp),%rdi
mov    $0x64,%esi
call   1090 <getlines@plt>
test   %eax,%eax
jle    125a <main+0xea>
lea    -0x90(%rbp),%r12
lea    0xe64(%rip),%r15
jmp    11db <main+0x6b>
nopw   0x0(%rax,%rax,1)
movb   $0x0,(%rbx,%r14,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <print_line@plt>
mov    %r13,%rsp
mov    %r12,%rdi
mov    $0x64,%esi
call   1090 <getlines@plt>
test   %eax,%eax
jle    125a <main+0xea>
mov    %r12,%rdi
call   1050 <print_line@plt>
mov    %r12,%rdi
call   1030 <len@plt>
lea    0xe0e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r13
lea    -0x70(%rsp),%rbx
mov    %rbx,%rsp
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <reverse@plt>
mov    %rbx,%rdi
call   1050 <print_line@plt>
mov    %r12,%rdi
call   1080 <rstrip_index@plt>
movslq %eax,%rcx
lea    0x1(%rcx),%r14
mov    %r14d,%edx
mov    %rsp,%rbx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
sub    %rdx,%rbx
mov    %rbx,%rsp
test   %ecx,%ecx
js     11b0 <main+0x40>
mov    %eax,%edx
add    $0x1,%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <memcpy@plt>
jmp    11b0 <main+0x40>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"length: %d\0A\00"
@.str.1 = [10 x i8] c"\0Arstrip: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
store i32 0, i32* %1
store i32 100, i32* %3
%11 = load i32, i32* %3
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
br label %15
15: ; preds = %49, %0
%16 = load i32, i32* %3
%17 = call i32 @getlines(i8* %14, i32 %16)
store i32 %17, i32* %2
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %57
19: ; preds = %15
%20 = call i32 @print_line(i8* %14)
%21 = call i32 @len(i8* %14)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %3
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %6
%26 = alloca i8, i64 %24
store i64 %24, i64* %7
%27 = call i32 @reverse(i8* %14, i8* %26)
%28 = call i32 @print_line(i8* %26)
%29 = call i32 @rstrip_index(i8* %14)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
%32 = zext i32 %31 to i64
%33 = alloca i8, i64 %32
store i64 %32, i64* %10
store i32 0, i32* %8
br label %34
34: ; preds = %46, %19
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%37 = icmp sle i32 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %14, i64 %40
%42 = load i8, i8* %41
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %33, i64 %44
store i8 %42, i8* %45
br label %46
46: ; preds = %38
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %34
49: ; preds = %34
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %33, i64 %52
store i8 0, i8* %53
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%55 = call i32 @print_line(i8* %33)
%56 = load i8*, i8** %6
br label %15
57: ; preds = %15
%58 = load i8*, i8** %4
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@.str = [12 x i8] c"length: %d\0A\00"
@.str.1 = [10 x i8] c"\0Arstrip: \00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = call i32 @getlines(i8* %3, i32 100)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %30
6: ; preds = %0, %23
%7 = call i32 @print_line(i8* %3)
%8 = call i32 @len(i8* %3)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i8* @llvm.stacksave()
%11 = alloca [100 x i8]
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%13 = call i32 @reverse(i8* %3, i8* %12)
%14 = call i32 @print_line(i8* %12)
%15 = call i32 @rstrip_index(i8* %3)
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
%19 = icmp slt i32 %15, 0
br i1 %19, label %23, label %20
20: ; preds = %6
%21 = zext i32 %15 to i64
%22 = add nuw nsw i64 %21, 1
br label %23
23: ; preds = %20, %6
%24 = sext i32 %16 to i64
%25 = getelementptr inbounds i8, i8* %18, i64 %24
store i8 0, i8* %25
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @print_line(i8* %18)
%28 = call i32 @getlines(i8* %3, i32 100)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %6, label %30
30: ; preds = %23, %0
ret i32 0
}