#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 /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
char *realloc(char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
unsigned int strlen(char *);
int _getline(char **lineptr, size_t *n, FILE *stream) {
  static char line[256];
  char *ptr;
  unsigned int len;
  if (lineptr == NULL || n == NULL) {
    errno = EINVAL;
    return -1;
  }
  if (ferror(stream))
    return -1;
  if (feof(stream))
    return -1;
  fgets(line, 256, stream);
  ptr = strchr(line, '\n');
  if (ptr)
    *ptr = '\0';
  len = strlen(line);
  if ((len + 1) < 256) {
    ptr = realloc(*lineptr, 256);
    if (ptr == NULL)
      return (-1);
    *lineptr = ptr;
    *n = 256;
  }
  strcpy(*lineptr, line);
  return (len);
}


x86 assembly (clang, -O0):
<_getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119a <_getline+0x2a>
cmpq   $0x0,-0x18(%rbp)
jne    11b8 <_getline+0x48>
mov    0x2e37(%rip),%rax
mov    (%rax),%ecx
mov    0x2e36(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <_getline+0x13d>
mov    -0x20(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     11d7 <_getline+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <_getline+0x13d>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     11f6 <_getline+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <_getline+0x13d>
mov    -0x20(%rbp),%rdx
lea    0x2e6f(%rip),%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
lea    0x2e5e(%rip),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1232 <_getline+0xc2>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e37(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cmp    $0x100,%eax
jae    1294 <_getline+0x124>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x100,%esi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    127e <_getline+0x10e>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <_getline+0x13d>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x100,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0x2dce(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     1232 <_getline+0xc2>
mov    %rsi,%r14
test   %rsi,%rsi
je     1232 <_getline+0xc2>
mov    %rdx,%rbx
mov    %rdi,%r12
mov    %rdx,%rdi
call   1040 <ferror@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1249 <_getline+0xd9>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    1249 <_getline+0xd9>
lea    0x2eaf(%rip),%r15
mov    %r15,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %r15,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11e6 <_getline+0x76>
movb   $0x0,(%rax)
lea    0x2e83(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%eax
mov    (%r12),%rdi
cmp    $0xff,%eax
ja     1221 <_getline+0xb1>
mov    $0x100,%esi
call   1090 <realloc@plt>
test   %rax,%rax
je     1249 <_getline+0xd9>
mov    %rax,%rdi
mov    %rax,(%r12)
movq   $0x100,(%r14)
lea    0x2e48(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r15d,%ebp
jmp    1249 <_getline+0xd9>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    0x2d9e(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_getline.line = internal global [256 x i8] zeroinitializer
@EINVAL = global i32 0
@errno = global i32 0
define i32 @_getline(i8** %0, i64* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i32* %2, i32** %7
%10 = load i8**, i8*** %5
%11 = icmp eq i8** %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i64*, i64** %6
%14 = icmp eq i64* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12, %3
%16 = load i32, i32* @EINVAL
store i32 %16, i32* @errno
store i32 -1, i32* %4
br label %56
17: ; preds = %12
%18 = load i32*, i32** %7
%19 = call i64 @ferror(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %4
br label %56
22: ; preds = %17
%23 = load i32*, i32** %7
%24 = call i64 @feof(i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 -1, i32* %4
br label %56
27: ; preds = %22
%28 = load i32*, i32** %7
%29 = call i32 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_getline.line, i64 0, i64 0), i32 256, i32* %28)
%30 = call i8* @strchr(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_getline.line, i64 0, i64 0), i8 signext 10)
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = load i8*, i8** %8
store i8 0, i8* %34
br label %35
35: ; preds = %33, %27
%36 = call i32 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_getline.line, i64 0, i64 0))
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = add i32 %37, 1
%39 = icmp ult i32 %38, 256
br i1 %39, label %40, label %51
40: ; preds = %35
%41 = load i8**, i8*** %5
%42 = load i8*, i8** %41
%43 = call i8* @realloc(i8* %42, i32 256)
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 -1, i32* %4
br label %56
47: ; preds = %40
%48 = load i8*, i8** %8
%49 = load i8**, i8*** %5
store i8* %48, i8** %49
%50 = load i64*, i64** %6
store i64 256, i64* %50
br label %51
51: ; preds = %47, %35
%52 = load i8**, i8*** %5
%53 = load i8*, i8** %52
%54 = call i32 @strcpy(i8* %53, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_getline.line, i64 0, i64 0))
%55 = load i32, i32* %9
store i32 %55, i32* %4
br label %56
56: ; preds = %51, %46, %26, %21, %15
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
@_getline.line = internal global [256 x i8] zeroinitializer
@EINVAL = global i32 0
@errno = global i32 0
define i32 @_getline(i8** %0, i64* writeonly %1, i32* nocapture %2) {
%4 = icmp eq i8** %0, null
%5 = icmp eq i64* %1, null
%6 = or i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = load i32, i32* @EINVAL
store i32 %8, i32* @errno
br label %32
9: ; preds = %3
%10 = tail call i64 @ferror(i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = tail call i64 @feof(i32* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = tail call i32 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_getline.line, i64 0, i64 0), i32 256, i32* %2)
%17 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @_getline.line, i64 0, i64 0), i8 signext 10)
%18 = icmp eq i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %15
store i8 0, i8* %17
br label %20
20: ; preds = %19, %15
%21 = tail call i32 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_getline.line, i64 0, i64 0))
%22 = add i32 %21, 1
%23 = icmp ult i32 %22, 256
%24 = load i8*, i8** %0
br i1 %23, label %25, label %29
25: ; preds = %20
%26 = tail call i8* @realloc(i8* %24, i32 256)
%27 = icmp eq i8* %26, null
br i1 %27, label %32, label %28
28: ; preds = %25
store i8* %26, i8** %0
store i64 256, i64* %1
br label %29
29: ; preds = %20, %28
%30 = phi i8* [ %26, %28 ], [ %24, %20 ]
%31 = tail call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @_getline.line, i64 0, i64 0))
br label %32
32: ; preds = %25, %12, %9, %29, %7
%33 = phi i32 [ -1, %7 ], [ %21, %29 ], [ -1, %9 ], [ -1, %12 ], [ -1, %25 ]
ret i32 %33
}