#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 */
char EOF;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int readln(FILE *fp, char *target) {
  int i = 0;
  memset(target, 0, 4096);
  while (1) {
    target[i] = fgetc(fp);
    if (EOF == target[i]) {
      target[i] = '\n';
      return (EOF);
    }
    if ('\n' == target[i]) {
      target[i] = ' ';
      target[i + 1] = 0;
      break;
    }
    i++;
  }
  return (EOF + 1);
}


x86 assembly (clang, -O0):
<readln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    0x2e84(%rip),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1199 <readln+0x79>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
mov    0x2e5a(%rip),%rax
movsbl (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <readln+0xd2>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    11d4 <readln+0xb4>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11e2 <readln+0xc2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1147 <readln+0x27>
mov    0x2dff(%rip),%rax
movsbl (%rax),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readln>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %al,(%r14)
mov    0x2e97(%rip),%r12
cmp    %al,(%r12)
je     117d <readln+0x5d>
mov    $0x1,%ebx
nopl   0x0(%rax)
cmp    $0xa,%al
je     1189 <readln+0x69>
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %al,(%r12)
jne    1160 <readln+0x40>
add    $0xffffffff,%ebx
movb   $0xa,(%r14,%rbx,1)
movsbl (%r12),%eax
jmp    11a0 <readln+0x80>
lea    -0x1(%rbx),%eax
movb   $0x20,(%r14,%rax,1)
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
movsbl (%r12),%eax
add    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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