#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 */
size_t BUFSIZ;
int EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
char *malloc(size_t);
char *realloc(char *, size_t);
int /*<<< orphan*/ stderr;
int readline(char **lineptr, size_t *n, FILE *stream) {
  char *bufptr;
  char *p;
  size_t size;
  int c;
  if (lineptr == NULL)
    return -1;
  if (stream == NULL)
    return -1;
  if (n == NULL)
    return -1;
  p = bufptr = *lineptr;
  size = *n;
  c = fgetc(stream);
  if (c == EOF)
    return -1;
  if (bufptr == NULL) {
    bufptr = malloc(BUFSIZ);
    if (bufptr == NULL) {
      fprintf(stderr, "%s:%d - Could not allocate memory for buffer.\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/RecipeML/Recipe/refs/heads/master/"
              "demo/readline.c",
              27);
      return -1;
    }
    size = BUFSIZ;
  }
  p = bufptr;
  while (c != EOF) {
    if ((p - bufptr) > (size - 1)) {
      size += BUFSIZ;
      bufptr = realloc(bufptr, size);
      if (bufptr == NULL) {
        fprintf(stderr, "%s:%d - Could not reallocate memory for buffer.\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/RecipeML/Recipe/refs/heads/"
                "master/demo/readline.c",
                38);
        return -1;
      }
    }
    *p++ = c;
    if (c == '\n') {
      break;
    }
    c = fgetc(stream);
  }
  *p++ = '\0';
  *lineptr = bufptr;
  *n = size;
  return p - bufptr - 1;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <readline+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1347 <readline+0x207>
cmpq   $0x0,-0x20(%rbp)
jne    1182 <readline+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1347 <readline+0x207>
cmpq   $0x0,-0x18(%rbp)
jne    1199 <readline+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1347 <readline+0x207>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%eax
jne    11dd <readline+0x9d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1347 <readline+0x207>
cmpq   $0x0,-0x28(%rbp)
jne    1241 <readline+0x101>
mov    0x2de1(%rip),%rax
mov    (%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1233 <readline+0xf3>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
lea    0xe12(%rip),%rdx
mov    $0x1b,%ecx
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1347 <readline+0x207>
mov    0x2d96(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2d95(%rip),%rcx
cmp    (%rcx),%eax
je     130d <readline+0x1cd>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jbe    12d7 <readline+0x197>
mov    0x2d52(%rip),%rax
mov    (%rax),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12d2 <readline+0x192>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
lea    0xd73(%rip),%rdx
mov    $0x26,%ecx
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1347 <readline+0x207>
jmp    12d7 <readline+0x197>
mov    -0x3c(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
cmpl   $0xa,-0x3c(%rbp)
jne    12fc <readline+0x1bc>
jmp    130d <readline+0x1cd>
mov    -0x20(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x3c(%rbp)
jmp    1249 <readline+0x109>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%eax
test   %rsi,%rsi
je     128f <readline+0x14f>
mov    %rdi,%r13
test   %rdi,%rdi
je     128f <readline+0x14f>
test   %rdx,%rdx
je     128f <readline+0x14f>
mov    %rsi,%r12
mov    0x0(%r13),%r14
mov    (%rsi),%rbx
mov    %rdx,%rdi
mov    %rdx,%r15
call   1030 <fgetc@plt>
mov    %eax,%ebp
mov    0x2e59(%rip),%rax
cmp    (%rax),%ebp
je     128a <readline+0x14a>
mov    %r15,0x10(%rsp)
test   %r14,%r14
jne    11bf <readline+0x7f>
mov    0x2e28(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1269 <readline+0x129>
mov    %r13,(%rsp)
mov    %r12,0x8(%rsp)
lea    0x1(%r14),%rax
mov    %r14,%r15
nop
mov    %r14,%r12
mov    %rax,%r13
mov    %r14,%rax
sub    %r15,%rax
lea    -0x1(%rbx),%rcx
cmp    %rcx,%rax
jbe    1202 <readline+0xc2>
mov    0x2de4(%rip),%rax
add    (%rax),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     124b <readline+0x10b>
mov    %bpl,-0x1(%r13)
cmp    $0xa,%ebp
je     122b <readline+0xeb>
mov    0x10(%rsp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
lea    0x1(%r12),%r14
lea    0x1(%r13),%rax
mov    0x2dc1(%rip),%rcx
cmp    (%rcx),%ebp
jne    11d0 <readline+0x90>
movb   $0x0,0x0(%r13)
mov    (%rsp),%rax
mov    %r15,(%rax)
mov    0x8(%rsp),%rax
mov    %rbx,(%rax)
sub    %r15d,%r12d
add    $0x1,%r12d
mov    %r12d,%eax
jmp    128f <readline+0x14f>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
lea    0xdcd(%rip),%rdx
mov    $0x26,%ecx
jmp    1285 <readline+0x145>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xd87(%rip),%rsi
lea    0xdaf(%rip),%rdx
mov    $0x1b,%ecx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@BUFSIZ = global i64 0
@stderr = global i32 0
@.str = [47 x i8] c"%s:%d - Could not allocate memory for buffer.\0A\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/RecipeML/Recipe/refs/heads/master/demo/readline.c\00"
@.str.2 = [49 x i8] c"%s:%d - Could not reallocate memory for buffer.\0A\00"
define i32 @readline(i8** %0, i64* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i32* %2, i32** %7
%12 = load i8**, i8*** %5
%13 = icmp eq i8** %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %100
15: ; preds = %3
%16 = load i32*, i32** %7
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 -1, i32* %4
br label %100
19: ; preds = %15
%20 = load i64*, i64** %6
%21 = icmp eq i64* %20, null
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 -1, i32* %4
br label %100
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
store i8* %25, i8** %8
store i8* %25, i8** %9
%26 = load i64*, i64** %6
%27 = load i64, i64* %26
store i64 %27, i64* %10
%28 = load i32*, i32** %7
%29 = call i32 @fgetc(i32* %28)
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %23
store i32 -1, i32* %4
br label %100
34: ; preds = %23
%35 = load i8*, i8** %8
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %47
37: ; preds = %34
%38 = load i64, i64* @BUFSIZ
%39 = call i8* @malloc(i64 %38)
store i8* %39, i8** %8
%40 = load i8*, i8** %8
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 27)
store i32 -1, i32* %4
br label %100
45: ; preds = %37
%46 = load i64, i64* @BUFSIZ
store i64 %46, i64* %10
br label %47
47: ; preds = %45, %34
%48 = load i8*, i8** %8
store i8* %48, i8** %9
br label %49
49: ; preds = %83, %47
%50 = load i32, i32* %11
%51 = load i32, i32* @EOF
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %86
53: ; preds = %49
%54 = load i8*, i8** %9
%55 = load i8*, i8** %8
%56 = ptrtoint i8* %54 to i64
%57 = ptrtoint i8* %55 to i64
%58 = sub i64 %56, %57
%59 = load i64, i64* %10
%60 = sub i64 %59, 1
%61 = icmp ugt i64 %58, %60
br i1 %61, label %62, label %75
62: ; preds = %53
%63 = load i64, i64* @BUFSIZ
%64 = load i64, i64* %10
%65 = add i64 %64, %63
store i64 %65, i64* %10
%66 = load i8*, i8** %8
%67 = load i64, i64* %10
%68 = call i8* @realloc(i8* %66, i64 %67)
store i8* %68, i8** %8
%69 = load i8*, i8** %8
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %62
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 38)
store i32 -1, i32* %4
br label %100
74: ; preds = %62
br label %75
75: ; preds = %74, %53
%76 = load i32, i32* %11
%77 = trunc i32 %76 to i8
%78 = load i8*, i8** %9
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %9
store i8 %77, i8* %78
%80 = load i32, i32* %11
%81 = icmp eq i32 %80, 10
br i1 %81, label %82, label %83
82: ; preds = %75
br label %86
83: ; preds = %75
%84 = load i32*, i32** %7
%85 = call i32 @fgetc(i32* %84)
store i32 %85, i32* %11
br label %49
86: ; preds = %82, %49
%87 = load i8*, i8** %9
%88 = getelementptr inbounds i8, i8* %87, i32 1
store i8* %88, i8** %9
store i8 0, i8* %87
%89 = load i8*, i8** %8
%90 = load i8**, i8*** %5
store i8* %89, i8** %90
%91 = load i64, i64* %10
%92 = load i64*, i64** %6
store i64 %91, i64* %92
%93 = load i8*, i8** %9
%94 = load i8*, i8** %8
%95 = ptrtoint i8* %93 to i64
%96 = ptrtoint i8* %94 to i64
%97 = sub i64 %95, %96
%98 = sub nsw i64 %97, 1
%99 = trunc i64 %98 to i32
store i32 %99, i32* %4
br label %100
100: ; preds = %86, %71, %42, %33, %22, %18, %14
%101 = load i32, i32* %4
ret i32 %101
}

LLVM IR (-O2):
@EOF = global i32 0
@BUFSIZ = global i64 0
@stderr = global i32 0
@.str = [47 x i8] c"%s:%d - Could not allocate memory for buffer.\0A\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/RecipeML/Recipe/refs/heads/master/demo/readline.c\00"
@.str.2 = [49 x i8] c"%s:%d - Could not reallocate memory for buffer.\0A\00"
define i32 @readline(i8** %0, i64* %1, i32* %2) {
%4 = icmp eq i8** %0, null
%5 = icmp eq i32* %2, null
%6 = or i1 %4, %5
%7 = icmp eq i64* %1, null
%8 = or i1 %7, %6
br i1 %8, label %62, label %9
9: ; preds = %3
%10 = load i8*, i8** %0
%11 = load i64, i64* %1
%12 = tail call i32 @fgetc(i32* %2)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %62, label %15
15: ; preds = %9
%16 = icmp eq i8* %10, null
br i1 %16, label %17, label %21
17: ; preds = %15
%18 = load i64, i64* @BUFSIZ
%19 = tail call i8* @malloc(i64 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %15, %17
%22 = phi i64 [ %18, %17 ], [ %11, %15 ]
%23 = phi i8* [ %19, %17 ], [ %10, %15 ]
br label %27
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 27)
br label %62
27: ; preds = %21, %51
%28 = phi i32 [ %52, %51 ], [ %12, %21 ]
%29 = phi i64 [ %47, %51 ], [ %22, %21 ]
%30 = phi i8* [ %49, %51 ], [ %23, %21 ]
%31 = phi i8* [ %46, %51 ], [ %23, %21 ]
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = add i64 %29, -1
%36 = icmp ugt i64 %34, %35
br i1 %36, label %37, label %45
37: ; preds = %27
%38 = load i64, i64* @BUFSIZ
%39 = add i64 %38, %29
%40 = tail call i8* @realloc(i8* %31, i64 %39)
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 38)
br label %62
45: ; preds = %37, %27
%46 = phi i8* [ %40, %37 ], [ %31, %27 ]
%47 = phi i64 [ %39, %37 ], [ %29, %27 ]
%48 = trunc i32 %28 to i8
%49 = getelementptr inbounds i8, i8* %30, i64 1
store i8 %48, i8* %30
%50 = icmp eq i32 %28, 10
br i1 %50, label %55, label %51
51: ; preds = %45
%52 = tail call i32 @fgetc(i32* %2)
%53 = load i32, i32* @EOF
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %27
55: ; preds = %51, %45
%56 = getelementptr inbounds i8, i8* %30, i64 2
store i8 0, i8* %49
store i8* %46, i8** %0
store i64 %47, i64* %1
%57 = ptrtoint i8* %56 to i64
%58 = ptrtoint i8* %46 to i64
%59 = xor i64 %58, -1
%60 = add i64 %57, %59
%61 = trunc i64 %60 to i32
br label %62
62: ; preds = %9, %3, %55, %42, %24
%63 = phi i32 [ -1, %24 ], [ -1, %42 ], [ %61, %55 ], [ -1, %3 ], [ -1, %9 ]
ret i32 %63
}