#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 */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int read_line(char *line, FILE *src) {
  if (src == NULL)
    return -1;
  int i, c;
  for (i = 0; i < 100 - 1 && (c = fgetc(src)) != EOF && c != '\n'; ++i) {
    line[i] = c;
    if (c == '\n') {
      line[i++] = c;
    }
  }
  line[i] = '\0';
  fclose(src);
  return i;
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1147 <read_line+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <read_line+0xdb>
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x63,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
jge    1189 <read_line+0x69>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
xor    %eax,%eax
mov    0x2e74(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x21(%rbp)
je     1189 <read_line+0x69>
cmpl   $0xa,-0x20(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1199 <read_line+0x79>
jmp    11e0 <read_line+0xc0>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0xa,-0x20(%rbp)
jne    11cd <read_line+0xad>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x10(%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    11d2 <read_line+0xb2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114e <read_line+0x2e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1177 <read_line+0x57>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    0x2eac(%rip),%r12
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    $0xa,%eax
je     1166 <read_line+0x46>
cmp    (%r12),%eax
je     1166 <read_line+0x46>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    $0x63,%rbx
jne    1140 <read_line+0x20>
mov    $0x63,%ebx
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    117c <read_line+0x5c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @read_line(i8* nocapture writeonly %0, i32* %1) {
%3 = icmp eq i32* %1, null
br i1 %3, label %23, label %4
4: ; preds = %2, %11
%5 = phi i64 [ %14, %11 ], [ 0, %2 ]
%6 = tail call i32 @fgetc(i32* %1)
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
%9 = icmp ne i32 %6, 10
%10 = and i1 %9, %8
br i1 %10, label %11, label %16
11: ; preds = %4
%12 = trunc i32 %6 to i8
%13 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 %12, i8* %13
%14 = add nuw nsw i64 %5, 1
%15 = icmp eq i64 %14, 99
br i1 %15, label %18, label %4
16: ; preds = %4
%17 = trunc i64 %5 to i32
br label %18
18: ; preds = %11, %16
%19 = phi i32 [ %17, %16 ], [ 99, %11 ]
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 0, i8* %21
%22 = tail call i32 @fclose(i32* %1)
br label %23
23: ; preds = %2, %18
%24 = phi i32 [ %19, %18 ], [ -1, %2 ]
ret i32 %24
}