#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
#define EOF 128
int getc(int /*<<< orphan*/ *);
int ASTIL_ReadLine(FILE *fp, char *result) {
  int len = 0;
  for (;;) {
    int c = getc(fp);
    switch (c) {
    case EOF:
      result[0] = '\0';
      return -1;
    case '\n':
      while (len > 0 && (result[len - 1] == ' ' || result[len - 1] == '\t'))
        len--;
      result[len] = '\0';
      return len;
    case '\r':
      break;
    default:
      if (len < 100)
        result[len++] = c;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<ASTIL_ReadLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0xa,%eax
je     117e <ASTIL_ReadLine+0x6e>
jmp    1147 <ASTIL_ReadLine+0x37>
mov    -0x24(%rbp),%eax
sub    $0xd,%eax
je     1206 <ASTIL_ReadLine+0xf6>
jmp    1158 <ASTIL_ReadLine+0x48>
mov    -0x24(%rbp),%eax
sub    $0x80,%eax
jne    120b <ASTIL_ReadLine+0xfb>
jmp    116b <ASTIL_ReadLine+0x5b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <ASTIL_ReadLine+0x129>
jmp    1183 <ASTIL_ReadLine+0x73>
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x25(%rbp)
jle    11d1 <ASTIL_ReadLine+0xc1>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x26(%rbp)
je     11cb <ASTIL_ReadLine+0xbb>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x26(%rbp)
mov    -0x26(%rbp),%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11e1 <ASTIL_ReadLine+0xd1>
jmp    11ef <ASTIL_ReadLine+0xdf>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1183 <ASTIL_ReadLine+0x73>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1239 <ASTIL_ReadLine+0x129>
jmp    1234 <ASTIL_ReadLine+0x124>
cmpl   $0x64,-0x1c(%rbp)
jge    122f <ASTIL_ReadLine+0x11f>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1234 <ASTIL_ReadLine+0x124>
jmp    1127 <ASTIL_ReadLine+0x17>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASTIL_ReadLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r15d,%r15d
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <getc@plt>
cmp    $0xd,%eax
je     1130 <ASTIL_ReadLine+0x20>
cmp    $0x80,%eax
je     1160 <ASTIL_ReadLine+0x50>
cmp    $0xa,%eax
je     1168 <ASTIL_ReadLine+0x58>
cmp    $0x63,%r15d
ja     1130 <ASTIL_ReadLine+0x20>
mov    %r15d,%ecx
add    $0x1,%r15d
mov    %al,(%r14,%rcx,1)
add    $0x1,%rbp
jmp    1130 <ASTIL_ReadLine+0x20>
mov    $0xffffffff,%r15d
jmp    119b <ASTIL_ReadLine+0x8b>
test   %r15d,%r15d
jne    117a <ASTIL_ReadLine+0x6a>
jmp    1195 <ASTIL_ReadLine+0x85>
nop
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
jbe    1192 <ASTIL_ReadLine+0x82>
lea    -0x2(%rbp),%eax
movzbl (%r14,%rax,1),%eax
cmp    $0x20,%al
je     1170 <ASTIL_ReadLine+0x60>
cmp    $0x9,%al
je     1170 <ASTIL_ReadLine+0x60>
add    $0xffffffff,%ebp
mov    %ebp,%r15d
jmp    1195 <ASTIL_ReadLine+0x85>
xor    %r15d,%r15d
movslq %r15d,%rax
add    %rax,%r14
movb   $0x0,(%r14)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ASTIL_ReadLine(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %8
8: ; preds = %63, %2
%9 = load i32*, i32** %4
%10 = call i32 @getc(i32* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
switch i32 %11, label %51 [
i32 128, label %12
i32 10, label %15
i32 13, label %50
]
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %14
store i32 -1, i32* %3
br label %64
15: ; preds = %8
br label %16
16: ; preds = %41, %15
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %39
19: ; preds = %16
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 32
br i1 %27, label %37, label %28
28: ; preds = %19
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 9
br label %37
37: ; preds = %28, %19
%38 = phi i1 [ true, %19 ], [ %36, %28 ]
br label %39
39: ; preds = %37, %16
%40 = phi i1 [ false, %16 ], [ %38, %37 ]
br i1 %40, label %41, label %44
41: ; preds = %39
%42 = load i32, i32* %6
%43 = add nsw i32 %42, -1
store i32 %43, i32* %6
br label %16
44: ; preds = %39
%45 = load i8*, i8** %5
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
%49 = load i32, i32* %6
store i32 %49, i32* %3
br label %64
50: ; preds = %8
br label %63
51: ; preds = %8
%52 = load i32, i32* %6
%53 = icmp slt i32 %52, 100
br i1 %53, label %54, label %62
54: ; preds = %51
%55 = load i32, i32* %7
%56 = trunc i32 %55 to i8
%57 = load i8*, i8** %5
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
store i8 %56, i8* %61
br label %62
62: ; preds = %54, %51
br label %63
63: ; preds = %62, %50
br label %8
64: ; preds = %44, %12
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
define i32 @ASTIL_ReadLine(i32* nocapture %0, i8* nocapture %1) {
br label %3
3: ; preds = %28, %2
%4 = phi i32 [ %30, %28 ], [ 0, %2 ]
%5 = icmp ult i32 %4, 100
br label %6
6: ; preds = %8, %3
%7 = tail call i32 @getc(i32* %0)
switch i32 %7, label %27 [
i32 128, label %33
i32 10, label %9
i32 13, label %8
]
8: ; preds = %6, %27
br label %6
9: ; preds = %6
%10 = icmp eq i32 %4, 0
br i1 %10, label %23, label %11
11: ; preds = %9
%12 = zext i32 %4 to i64
br label %13
13: ; preds = %11, %19
%14 = phi i64 [ %12, %11 ], [ %15, %19 ]
%15 = add nsw i64 %14, -1
%16 = and i64 %15, 4294967295
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
switch i8 %18, label %21 [
i8 32, label %19
i8 9, label %19
]
19: ; preds = %13, %13
%20 = icmp ugt i64 %14, 1
br i1 %20, label %13, label %23
21: ; preds = %13
%22 = trunc i64 %14 to i32
br label %23
23: ; preds = %19, %21, %9
%24 = phi i32 [ %4, %9 ], [ %22, %21 ], [ 0, %19 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
br label %33
27: ; preds = %6
br i1 %5, label %28, label %8
28: ; preds = %27
%29 = trunc i32 %7 to i8
%30 = add nuw nsw i32 %4, 1
%31 = zext i32 %4 to i64
%32 = getelementptr inbounds i8, i8* %1, i64 %31
store i8 %29, i8* %32
br label %3
33: ; preds = %6, %23
%34 = phi i8* [ %26, %23 ], [ %1, %6 ]
%35 = phi i32 [ %24, %23 ], [ -1, %6 ]
store i8 0, i8* %34
ret i32 %35
}