#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ eiki_assertion_failed(char *);
int /*<<< orphan*/ eiki_free(char *);
char *eiki_malloc(size_t);
int /*<<< orphan*/ eiki_memcpy(char *, char *, size_t);
int eiki_read(int, char *, int);
char *eiki_readln(int fd) {
  char *buf = NULL;
  size_t buf_len = 0;
  size_t buf_sz = 64;
  buf = eiki_malloc(buf_sz);
  if (!buf) {
    goto fail_finish_line;
  }
  while (1) {
    char c;
    ssize_t sz;
    sz = eiki_read(fd, &c, 1);
    if (sz < 0) {
      goto fail_io;
    } else if (!sz) {
      break;
    } else {
      do {
        if (!(sz == 1))
          eiki_assertion_failed(
              "*** eiki: ASSERTION FAILED at "
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/nixprime/eiki/refs/heads/master/eiki.c"
              ":"
              "598"
              ": "
              "sz == 1"
              "\n");
      } while (0);
      if (c == '\n') {
        break;
      }
      if (buf_len == buf_sz - 1) {
        char *new_buf;
        new_buf = eiki_malloc(buf_sz + 64);
        if (!new_buf) {
          goto fail_finish_line;
        }
        eiki_memcpy(new_buf, buf, buf_sz);
        eiki_free(buf);
        buf = new_buf;
        buf_sz += 64;
      }
      buf[buf_len++] = c;
    }
  }
  buf[buf_len] = '\0';
  return buf;
fail_finish_line:
  while (1) {
    char c;
    ssize_t sz;
    sz = eiki_read(fd, &c, 1);
    if (sz <= 0 || c == '\n') {
      break;
    }
  }
fail_io:
  eiki_free(buf);
  return NULL;
}


x86 assembly (clang, -O0):
<eiki_readln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x40,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <eiki_malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <eiki_readln+0x40>
jmp    1299 <eiki_readln+0x149>
jmp    1195 <eiki_readln+0x45>
mov    -0xc(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1050 <eiki_read@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    11b8 <eiki_readln+0x68>
jmp    12d8 <eiki_readln+0x188>
cmpl   $0x0,-0x30(%rbp)
jne    11c7 <eiki_readln+0x77>
jmp    1280 <eiki_readln+0x130>
jmp    11cc <eiki_readln+0x7c>
cmpl   $0x1,-0x30(%rbp)
je     11e2 <eiki_readln+0x92>
lea    0xe23(%rip),%rdi
call   1060 <eiki_assertion_failed@plt>
jmp    11e7 <eiki_readln+0x97>
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
jne    11f9 <eiki_readln+0xa9>
jmp    1280 <eiki_readln+0x130>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    125d <eiki_readln+0x10d>
mov    -0x28(%rbp),%rdi
add    $0x40,%rdi
call   1030 <eiki_malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    122f <eiki_readln+0xdf>
jmp    1299 <eiki_readln+0x149>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <eiki_memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1070 <eiki_free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x28(%rbp)
mov    -0x29(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    127b <eiki_readln+0x12b>
jmp    1195 <eiki_readln+0x45>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12e9 <eiki_readln+0x199>
jmp    129e <eiki_readln+0x14e>
mov    -0xc(%rbp),%edi
lea    -0x39(%rbp),%rsi
mov    $0x1,%edx
call   1050 <eiki_read@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jle    12c9 <eiki_readln+0x179>
movsbl -0x39(%rbp),%eax
cmp    $0xa,%eax
jne    12ce <eiki_readln+0x17e>
jmp    12d3 <eiki_readln+0x183>
jmp    129e <eiki_readln+0x14e>
jmp    12d8 <eiki_readln+0x188>
mov    -0x18(%rbp),%rdi
call   1070 <eiki_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eiki_readln>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x40,%edi
call   1030 <eiki_malloc@plt>
test   %rax,%rax
je     1249 <eiki_readln+0xf9>
mov    %rax,%r13
lea    0x2(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1050 <eiki_read@plt>
test   %eax,%eax
js     127b <eiki_readln+0x12b>
mov    $0x40,%ebp
xor    %r14d,%r14d
lea    0x2(%rsp),%rbx
mov    %r15d,0x4(%rsp)
jmp    11d1 <eiki_readln+0x81>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,0x0(%r13,%r14,1)
add    $0x1,%r14
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <eiki_read@plt>
test   %eax,%eax
js     127b <eiki_readln+0x12b>
cmp    $0x1,%eax
je     11ea <eiki_readln+0x9a>
test   %eax,%eax
je     1288 <eiki_readln+0x138>
lea    0xe1b(%rip),%rdi
call   1060 <eiki_assertion_failed@plt>
movzbl 0x2(%rsp),%eax
cmp    $0xa,%al
je     1288 <eiki_readln+0x138>
lea    -0x1(%rbp),%rcx
cmp    %rcx,%r14
jne    11b0 <eiki_readln+0x60>
mov    %rbx,%r15
lea    0x40(%rbp),%rbx
mov    %rbx,%rdi
call   1030 <eiki_malloc@plt>
test   %rax,%rax
je     12a0 <eiki_readln+0x150>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <eiki_memcpy@plt>
mov    %r13,%rdi
call   1070 <eiki_free@plt>
movzbl 0x2(%rsp),%eax
mov    %r12,%r13
mov    %rbx,%rbp
mov    %r15,%rbx
mov    0x4(%rsp),%r15d
jmp    11b0 <eiki_readln+0x60>
xor    %r13d,%r13d
lea    0x3(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <eiki_read@plt>
test   %eax,%eax
jle    127b <eiki_readln+0x12b>
cmpb   $0xa,0x3(%rsp)
jne    1260 <eiki_readln+0x110>
mov    %r13,%rdi
call   1070 <eiki_free@plt>
xor    %r13d,%r13d
jmp    128e <eiki_readln+0x13e>
movb   $0x0,0x0(%r13,%r14,1)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x4(%rsp),%r15d
jmp    124c <eiki_readln+0xfc>

LLVM IR (-O0):
@.str = [173 x i8] c"*** eiki: ASSERTION FAILED at /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/nixprime/eiki/refs/heads/master/eiki.c:598: sz == 1\0A\00"
define i8* @eiki_readln(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i32
store i32 %0, i32* %3
store i8* null, i8** %4
store i64 0, i64* %5
store i64 64, i64* %6
%12 = load i64, i64* %6
%13 = call i8* @eiki_malloc(i64 %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %1
br label %75
17: ; preds = %1
br label %18
18: ; preds = %17, %69
%19 = load i32, i32* %3
%20 = call i32 @eiki_read(i32 %19, i8* %7, i32 1)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
br label %88
24: ; preds = %18
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %24
br label %70
28: ; preds = %24
br label %29
29: ; preds = %28
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 1
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @eiki_assertion_failed(i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
br label %35
35: ; preds = %34
%36 = load i8, i8* %7
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %40
39: ; preds = %35
br label %70
40: ; preds = %35
%41 = load i64, i64* %5
%42 = load i64, i64* %6
%43 = sub i64 %42, 1
%44 = icmp eq i64 %41, %43
br i1 %44, label %45, label %62
45: ; preds = %40
%46 = load i64, i64* %6
%47 = add i64 %46, 64
%48 = call i8* @eiki_malloc(i64 %47)
store i8* %48, i8** %9
%49 = load i8*, i8** %9
%50 = icmp ne i8* %49, null
br i1 %50, label %52, label %51
51: ; preds = %45
br label %75
52: ; preds = %45
%53 = load i8*, i8** %9
%54 = load i8*, i8** %4
%55 = load i64, i64* %6
%56 = call i32 @eiki_memcpy(i8* %53, i8* %54, i64 %55)
%57 = load i8*, i8** %4
%58 = call i32 @eiki_free(i8* %57)
%59 = load i8*, i8** %9
store i8* %59, i8** %4
%60 = load i64, i64* %6
%61 = add i64 %60, 64
store i64 %61, i64* %6
br label %62
62: ; preds = %52, %40
%63 = load i8, i8* %7
%64 = load i8*, i8** %4
%65 = load i64, i64* %5
%66 = add i64 %65, 1
store i64 %66, i64* %5
%67 = getelementptr inbounds i8, i8* %64, i64 %65
store i8 %63, i8* %67
br label %68
68: ; preds = %62
br label %69
69: ; preds = %68
br label %18
70: ; preds = %39, %27
%71 = load i8*, i8** %4
%72 = load i64, i64* %5
%73 = getelementptr inbounds i8, i8* %71, i64 %72
store i8 0, i8* %73
%74 = load i8*, i8** %4
store i8* %74, i8** %2
br label %91
75: ; preds = %51, %16
br label %76
76: ; preds = %75, %86
%77 = load i32, i32* %3
%78 = call i32 @eiki_read(i32 %77, i8* %10, i32 1)
store i32 %78, i32* %11
%79 = load i32, i32* %11
%80 = icmp sle i32 %79, 0
br i1 %80, label %85, label %81
81: ; preds = %76
%82 = load i8, i8* %10
%83 = sext i8 %82 to i32
%84 = icmp eq i32 %83, 10
br i1 %84, label %85, label %86
85: ; preds = %81, %76
br label %87
86: ; preds = %81
br label %76
87: ; preds = %85
br label %88
88: ; preds = %87, %23
%89 = load i8*, i8** %4
%90 = call i32 @eiki_free(i8* %89)
store i8* null, i8** %2
br label %91
91: ; preds = %88, %70
%92 = load i8*, i8** %2
ret i8* %92
}

LLVM IR (-O2):
@.str = [173 x i8] c"*** eiki: ASSERTION FAILED at /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/nixprime/eiki/refs/heads/master/eiki.c:598: sz == 1\0A\00"
define i8* @eiki_readln(i32 %0) {
%2 = alloca i8
%3 = alloca i8
%4 = tail call i8* @eiki_malloc(i64 64)
%5 = icmp eq i8* %4, null
br i1 %5, label %43, label %6
6: ; preds = %1
%7 = call i32 @eiki_read(i32 %0, i8* %2, i32 1)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %33, %6
%10 = phi i8* [ %4, %6 ], [ %36, %33 ]
br label %51
11: ; preds = %6, %33
%12 = phi i32 [ %39, %33 ], [ %7, %6 ]
%13 = phi i8* [ %36, %33 ], [ %4, %6 ]
%14 = phi i64 [ %37, %33 ], [ 0, %6 ]
%15 = phi i64 [ %35, %33 ], [ 64, %6 ]
switch i32 %12, label %16 [
i32 0, label %41
i32 1, label %18
]
16: ; preds = %11
%17 = call i32 @eiki_assertion_failed(i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %11, %16
%19 = load i8, i8* %2
%20 = icmp eq i8 %19, 10
br i1 %20, label %41, label %21
21: ; preds = %18
%22 = add i64 %15, -1
%23 = icmp eq i64 %14, %22
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = add i64 %15, 64
%26 = call i8* @eiki_malloc(i64 %25)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %24
br label %43
29: ; preds = %24
%30 = call i32 @eiki_memcpy(i8* %26, i8* %13, i64 %15)
%31 = call i32 @eiki_free(i8* %13)
%32 = load i8, i8* %2
br label %33
33: ; preds = %21, %29
%34 = phi i8 [ %32, %29 ], [ %19, %21 ]
%35 = phi i64 [ %25, %29 ], [ %15, %21 ]
%36 = phi i8* [ %26, %29 ], [ %13, %21 ]
%37 = add i64 %14, 1
%38 = getelementptr inbounds i8, i8* %36, i64 %14
store i8 %34, i8* %38
%39 = call i32 @eiki_read(i32 %0, i8* %2, i32 1)
%40 = icmp slt i32 %39, 0
br i1 %40, label %9, label %11
41: ; preds = %11, %18
%42 = getelementptr inbounds i8, i8* %13, i64 %14
store i8 0, i8* %42
br label %54
43: ; preds = %28, %1
%44 = phi i8* [ null, %1 ], [ %13, %28 ]
br label %45
45: ; preds = %45, %43
%46 = call i32 @eiki_read(i32 %0, i8* %3, i32 1)
%47 = icmp slt i32 %46, 1
%48 = load i8, i8* %3
%49 = icmp eq i8 %48, 10
%50 = select i1 %47, i1 true, i1 %49
br i1 %50, label %51, label %45
51: ; preds = %45, %9
%52 = phi i8* [ %10, %9 ], [ %44, %45 ]
%53 = call i32 @eiki_free(i8* %52)
br label %54
54: ; preds = %51, %41
%55 = phi i8* [ null, %51 ], [ %13, %41 ]
ret i8* %55
}