#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;
int /*<<< orphan*/ exit(int);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void read_line(FILE *file, char *line_buffer) {
  if (file == NULL) {
    printf("Error: file pointer is null.");
    exit(1);
  }
  if (line_buffer == NULL) {
    printf("Error allocating memory for line buffer.");
    exit(1);
  }
  char ch = getc(file);
  int count = 0;
  while ((ch != '\n') && (ch != EOF)) {
    line_buffer[count] = ch;
    count++;
    ch = getc(file);
  }
  line_buffer[count] = '\0';
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1161 <read_line+0x31>
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1182 <read_line+0x52>
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     11bd <read_line+0x8d>
movsbl -0x11(%rbp),%eax
mov    0x2e36(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11cd <read_line+0x9d>
jmp    11f5 <read_line+0xc5>
mov    -0x11(%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)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x11(%rbp)
jmp    1195 <read_line+0x65>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     119c <read_line+0x6c>
mov    %rsi,%r14
test   %rsi,%rsi
je     11a5 <read_line+0x75>
mov    %rdi,%r12
call   1050 <getc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
je     118b <read_line+0x5b>
mov    0x2e8e(%rip),%r15
cmp    (%r15),%al
je     118b <read_line+0x5b>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <getc@plt>
cmp    $0xa,%al
je     1189 <read_line+0x59>
cmp    (%r15),%al
jne    1170 <read_line+0x40>
mov    %ebx,%ecx
movb   $0x0,(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe5d(%rip),%rdi
jmp    11ac <read_line+0x7c>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Error: file pointer is null.\00"
@.str.1 = [41 x i8] c"Error allocating memory for line buffer.\00"
@EOF = global i8 0
define void @read_line(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = load i32*, i32** %3
%20 = call signext i8 @getc(i32* %19)
store i8 %20, i8* %5
store i32 0, i32* %6
br label %21
21: ; preds = %33, %18
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 10
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
%28 = load i8, i8* @EOF
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %27, %29
br label %31
31: ; preds = %25, %21
%32 = phi i1 [ false, %21 ], [ %30, %25 ]
br i1 %32, label %33, label %43
33: ; preds = %31
%34 = load i8, i8* %5
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
%41 = load i32*, i32** %3
%42 = call signext i8 @getc(i32* %41)
store i8 %42, i8* %5
br label %21
43: ; preds = %31
%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 0, i8* %47
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Error: file pointer is null.\00"
@.str.1 = [41 x i8] c"Error allocating memory for line buffer.\00"
@EOF = global i8 0
define void @read_line(i32* %0, i8* writeonly %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = icmp eq i8* %1, null
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %7
%13 = tail call signext i8 @getc(i32* %0)
%14 = icmp ne i8 %13, 10
%15 = load i8, i8* @EOF
%16 = icmp ne i8 %13, %15
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %18, label %30
18: ; preds = %12, %18
%19 = phi i64 [ %22, %18 ], [ 0, %12 ]
%20 = phi i8 [ %23, %18 ], [ %13, %12 ]
%21 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 %20, i8* %21
%22 = add nuw i64 %19, 1
%23 = tail call signext i8 @getc(i32* %0)
%24 = icmp ne i8 %23, 10
%25 = load i8, i8* @EOF
%26 = icmp ne i8 %23, %25
%27 = select i1 %24, i1 %26, i1 false
br i1 %27, label %18, label %28
28: ; preds = %18
%29 = and i64 %22, 4294967295
br label %30
30: ; preds = %28, %12
%31 = phi i64 [ 0, %12 ], [ %29, %28 ]
%32 = getelementptr inbounds i8, i8* %1, i64 %31
store i8 0, i8* %32
ret void
}