#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 *bufptr;
char *delim;
char *readaline(FILE *fp) {
  static char buffer[2048];
  char *fgets(), *bufptr = buffer;
  char *strchr(), *delim;
  if (fp != NULL)
    if ((bufptr = fgets(buffer, 2047, fp)) != NULL) {
      if ((delim = strchr(bufptr, '\n')) != NULL)
        *delim = '\000';
    }
  return (bufptr);
}


x86 assembly (clang, -O0):
<readaline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f0d(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1194 <readaline+0x74>
mov    -0x8(%rbp),%rdx
lea    0x2ef3(%rip),%rdi
mov    $0x7ff,%esi
mov    $0x0,%al
call   1040 <fgets@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     118f <readaline+0x6f>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     118a <readaline+0x6a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    118f <readaline+0x6f>
jmp    1194 <readaline+0x74>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readaline>:
push   %rbx
test   %rdi,%rdi
je     115b <readaline+0x3b>
mov    %rdi,%rdx
lea    0x2f10(%rip),%rdi
mov    $0x7ff,%esi
xor    %eax,%eax
call   1040 <fgets@plt>
test   %rax,%rax
je     1164 <readaline+0x44>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1166 <readaline+0x46>
movb   $0x0,(%rax)
jmp    1166 <readaline+0x46>
lea    0x2ede(%rip),%rbx
jmp    1166 <readaline+0x46>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@readaline.buffer = internal global [2048 x i8] zeroinitializer
@bufptr = global i8* null
@delim = global i8* null
define i8* @readaline(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
store i32* %0, i32** %2
store i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readaline.buffer, i64 0, i64 0), i8** %3
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = load i32*, i32** %2
%9 = call i8* (i8*, i32, i32*, ...) bitcast (i8* (...)* @fgets to i8* (i8*, i32, i32*, ...)*)(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readaline.buffer, i64 0, i64 0), i32 2047, i32* %8)
store i8* %9, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = call i8* @strchr(i8* %12, i32 10)
store i8* %13, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i8*, i8** %4
store i8 0, i8* %16
br label %17
17: ; preds = %15, %11
br label %18
18: ; preds = %17, %7
br label %19
19: ; preds = %18, %1
%20 = load i8*, i8** %3
ret i8* %20
}

LLVM IR (-O2):
@readaline.buffer = internal global [2048 x i8] zeroinitializer
@bufptr = global i8* null
@delim = global i8* null
define i8* @readaline(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = tail call i8* (i8*, i32, i32*, ...) bitcast (i8* (...)* @fgets to i8* (i8*, i32, i32*, ...)*)(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @readaline.buffer, i64 0, i64 0), i32 2047, i32* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i8* @strchr(i8* %4, i32 10)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %6
store i8 0, i8* %7
br label %10
10: ; preds = %3, %9, %6, %1
%11 = phi i8* [ %4, %9 ], [ %4, %6 ], [ null, %3 ], [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @readaline.buffer, i64 0, i64 0), %1 ]
ret i8* %11
}