#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 size_t ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, ...);
size_t getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int);
extern char *_getline(FILE *f, int eof, char *file, int line) {
  char *s = 0;
  size_t z = 0;
  ssize_t n = getline(&s, &z, f);
  int err = errno;
  if (n < 0) {
    if (feof(f))
      if (eof)
        return 0;
      else
        fprintf(stderr, "%s:%d: getline(): unexpected EOF\n", file, line);
    else
      fprintf(stderr, "%s:%d: getline() failed: %s\n", file, line,
              strerror(err));
    fflush(stderr);
    exit(1);
  }
  if (n > 0)
    s[--n] = 0;
  return s;
}


x86 assembly (clang, -O0):
<_getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1060 <getline@plt>
mov    %rax,-0x40(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
cmpq   $0x0,-0x40(%rbp)
jae    1254 <_getline+0xf4>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     11ff <_getline+0x9f>
cmpl   $0x0,-0x14(%rbp)
je     11dc <_getline+0x7c>
movq   $0x0,-0x8(%rbp)
jmp    127f <_getline+0x11f>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    123c <_getline+0xdc>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%edi
call   1080 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%ecx
mov    %rax,%r8
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x40(%rbp)
jbe    1277 <_getline+0x117>
mov    -0x30(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x40(%rbp)
movb   $0x0,-0x1(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_getline>:
sub    $0x18,%rsp
mov    %rdi,%rdx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <getline@plt>
test   %rax,%rax
je     1147 <_getline+0x37>
mov    0x8(%rsp),%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
mov    0x8(%rsp),%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@errno = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"%s:%d: getline(): unexpected EOF\0A\00"
@.str.1 = [29 x i8] c"%s:%d: getline() failed: %s\0A\00"
define i8* @_getline(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* null, i8** %10
store i64 0, i64* %11
%14 = load i32*, i32** %6
%15 = call i64 @getline(i8** %10, i64* %11, i32* %14)
store i64 %15, i64* %12
%16 = load i32, i32* @errno
store i32 %16, i32* %13
%17 = load i64, i64* %12
%18 = icmp ult i64 %17, 0
br i1 %18, label %19, label %44
19: ; preds = %4
%20 = load i32*, i32** %6
%21 = call i64 @feof(i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
store i8* null, i8** %5
br label %54
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %8
%30 = load i32, i32* %9
%31 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %30)
br label %32
32: ; preds = %27
br label %40
33: ; preds = %19
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %8
%36 = load i32, i32* %9
%37 = load i32, i32* %13
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %35, i32 %36, i8* %38)
br label %40
40: ; preds = %33, %32
%41 = load i32, i32* @stderr
%42 = call i32 @fflush(i32 %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %4
%45 = load i64, i64* %12
%46 = icmp ugt i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %44
%48 = load i8*, i8** %10
%49 = load i64, i64* %12
%50 = add i64 %49, -1
store i64 %50, i64* %12
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %47, %44
%53 = load i8*, i8** %10
store i8* %53, i8** %5
br label %54
54: ; preds = %52, %26
%55 = load i8*, i8** %5
ret i8* %55
}

LLVM IR (-O2):
@errno = global i32 0
@stderr = global i32 0
define i8* @_getline(i32* %0, i32 %1, i8* nocapture readnone %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%8 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%9 = call i64 @getline(i8** %5, i64* %6, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %4
%12 = load i8*, i8** %5
%13 = add i64 %9, -1
%14 = getelementptr inbounds i8, i8* %12, i64 %13
store i8 0, i8* %14
br label %15
15: ; preds = %4, %11
%16 = load i8*, i8** %5
ret i8* %16
}