#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 ActualFileRead(int, int, char *);
int INIReadLine(int infile, char *buffer) {
  int charcount;
  int i;
  char tempin[2];
  int retflag;
  int retval;
  charcount = 0;
  i = 0;
  tempin[1] = 0;
  retflag = 0;
  while ((i < 255) && (retflag < 2)) {
    retval = ActualFileRead(infile, 1, tempin);
    charcount++;
    if (retval != 1) {
      retflag = 2;
      charcount--;
    } else if (tempin[0] == '\n') {
      retflag = 2;
    } else if (tempin[0] >= ' ') {
      *(buffer + i) = tempin[0];
      i++;
    }
  }
  *(buffer + i) = 0;
  return (charcount);
}


x86 assembly (clang, -O0):
<INIReadLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0xff,-0x18(%rbp)
mov    %al,-0x25(%rbp)
jge    1154 <INIReadLine+0x44>
cmpl   $0x2,-0x20(%rbp)
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1164 <INIReadLine+0x54>
jmp    11ec <INIReadLine+0xdc>
mov    -0x4(%rbp),%edi
lea    -0x1a(%rbp),%rdx
mov    $0x1,%esi
call   1030 <ActualFileRead@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     11a0 <INIReadLine+0x90>
movl   $0x2,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <INIReadLine+0xd7>
movsbl -0x1a(%rbp),%eax
cmp    $0xa,%eax
jne    11b9 <INIReadLine+0xa9>
movl   $0x2,-0x20(%rbp)
jmp    11e2 <INIReadLine+0xd2>
movsbl -0x1a(%rbp),%eax
cmp    $0x20,%eax
jl     11dd <INIReadLine+0xcd>
mov    -0x1a(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e2 <INIReadLine+0xd2>
jmp    11e7 <INIReadLine+0xd7>
jmp    1138 <INIReadLine+0x28>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<INIReadLine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%r12d
movb   $0x0,0xf(%rsp)
xor    %eax,%eax
lea    0xe(%rsp),%r15
xor    %ebp,%ebp
jmp    114b <INIReadLine+0x3b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbx),%eax
cmp    $0xff,%ebp
jge    117b <INIReadLine+0x6b>
mov    %eax,%ebx
mov    %r12d,%edi
mov    $0x1,%esi
mov    %r15,%rdx
call   1030 <ActualFileRead@plt>
cmp    $0x1,%eax
jne    117e <INIReadLine+0x6e>
movzbl 0xe(%rsp),%eax
cmp    $0xa,%al
je     117b <INIReadLine+0x6b>
cmp    $0x20,%al
jl     1140 <INIReadLine+0x30>
movslq %ebp,%rbp
mov    %al,(%r14,%rbp,1)
add    $0x1,%ebp
jmp    1140 <INIReadLine+0x30>
add    $0x1,%ebx
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @INIReadLine(i32 %0, i8* nocapture writeonly %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %5
br label %6
6: ; preds = %2, %21
%7 = phi i32 [ 0, %2 ], [ %10, %21 ]
%8 = phi i32 [ 0, %2 ], [ %22, %21 ]
%9 = call i32 @ActualFileRead(i32 %0, i32 1, i8* %4)
%10 = add nuw nsw i32 %7, 1
%11 = icmp eq i32 %9, 1
br i1 %11, label %12, label %24
12: ; preds = %6
%13 = load i8, i8* %4
%14 = icmp eq i8 %13, 10
br i1 %14, label %24, label %15
15: ; preds = %12
%16 = icmp sgt i8 %13, 31
br i1 %16, label %17, label %21
17: ; preds = %15
%18 = sext i32 %8 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 %13, i8* %19
%20 = add nsw i32 %8, 1
br label %21
21: ; preds = %17, %15
%22 = phi i32 [ %20, %17 ], [ %8, %15 ]
%23 = icmp slt i32 %22, 255
br i1 %23, label %6, label %24
24: ; preds = %12, %6, %21
%25 = phi i32 [ %10, %21 ], [ %10, %12 ], [ %7, %6 ]
%26 = phi i32 [ %22, %21 ], [ %8, %12 ], [ %8, %6 ]
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
store i8 0, i8* %28
ret i32 %25
}