#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 EOF;
int fgetc(int /*<<< orphan*/ *);
char *mymalloc(size_t);
char *myrealloc(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
size_t readline(FILE *fp, char **ret) {
  static char *buffer = (char *)0;
  char *ret_buff;
  static int bufsize = 135;
  int ch;
  size_t len = 0;
  int inc;
  int i;
  if (buffer == (char *)0)
    buffer = (char *)mymalloc(135);
  while (1) {
    ch = fgetc(fp);
    if (ch == EOF)
      break;
    if (ch == '\t') {
      ch = ' ';
      inc = 8 - (len % 8);
    } else
      inc = 1;
    if (len + inc > bufsize - 2) {
      bufsize += 135;
      buffer = myrealloc(buffer, bufsize);
    }
    for (i = 0; i < inc; i++)
      buffer[len + i] = ch;
    len += inc;
    if (ch == '\n')
      break;
  }
  buffer[len] = '\0';
  ret_buff = mymalloc(len + 1);
  strcpy(ret_buff, buffer);
  *ret = ret_buff;
  return len;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,0x2ef0(%rip)
jne    1177 <readline+0x37>
mov    $0x87,%edi
call   1060 <mymalloc@plt>
mov    %rax,0x2ed9(%rip)
jmp    117c <readline+0x3c>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
jne    119f <readline+0x5f>
jmp    1274 <readline+0x134>
cmpl   $0x9,-0x1c(%rbp)
jne    11c8 <readline+0x88>
movl   $0x20,-0x1c(%rbp)
mov    -0x28(%rbp),%rcx
and    $0x7,%rcx
mov    $0x8,%eax
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
jmp    11cf <readline+0x8f>
movl   $0x1,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
mov    0x2e60(%rip),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jbe    1219 <readline+0xd9>
mov    0x2e4b(%rip),%eax
add    $0x87,%eax
mov    %eax,0x2e40(%rip)
mov    0x2e49(%rip),%rdi
mov    0x2e33(%rip),%esi
call   1050 <myrealloc@plt>
mov    %rax,0x2e37(%rip)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1254 <readline+0x114>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    0x2e18(%rip),%rax
mov    -0x28(%rbp),%rcx
movslq -0x30(%rbp),%rsi
add    %rsi,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1220 <readline+0xe0>
movslq -0x2c(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    126f <readline+0x12f>
jmp    1274 <readline+0x134>
jmp    117c <readline+0x3c>
mov    0x2dd5(%rip),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <mymalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2db1(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
mov    %rdi,%r15
cmpq   $0x0,0x2eee(%rip)
jne    117d <readline+0x2d>
mov    $0x87,%edi
call   1070 <mymalloc@plt>
mov    %rax,0x2edb(%rip)
xor    %ebx,%ebx
mov    $0x1,%r14d
jmp    11ac <readline+0x5c>
nopw   0x0(%rax,%rax,1)
add    0x2ec1(%rip),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1040 <memset@plt>
mov    %r12,%rbx
cmp    $0xa,%ebp
je     1219 <readline+0xc9>
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    0x2e2b(%rip),%rax
cmp    (%rax),%ebp
je     1216 <readline+0xc6>
mov    %ebx,%eax
and    $0x7,%eax
mov    $0x8,%r13d
sub    %rax,%r13
cmp    $0x9,%ebp
mov    $0x20,%eax
cmove  %eax,%ebp
cmovne %r14,%r13
lea    (%rbx,%r13,1),%r12
movslq 0x2e5f(%rip),%rsi
lea    -0x2(%rsi),%rax
cmp    %rax,%r12
jbe    1190 <readline+0x40>
add    $0x87,%esi
mov    %esi,0x2e4a(%rip)
mov    0x2e53(%rip),%rdi
call   1060 <myrealloc@plt>
mov    %rax,0x2e47(%rip)
jmp    1190 <readline+0x40>
mov    %rbx,%r12
mov    0x2e38(%rip),%rax
movb   $0x0,(%rax,%r12,1)
lea    0x1(%r12),%rdi
call   1070 <mymalloc@plt>
mov    %rax,%rbx
mov    0x2e1f(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    (%rsp),%rax
mov    %rbx,(%rax)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@readline.buffer = internal global i8* null
@readline.bufsize = internal global i32 135
@EOF = global i32 0
define i64 @readline(i32* %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i8** %1, i8*** %4
store i64 0, i64* %7
%10 = load i8*, i8** @readline.buffer
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i8* @mymalloc(i64 135)
store i8* %13, i8** @readline.buffer
br label %14
14: ; preds = %12, %2
br label %15
15: ; preds = %14, %71
%16 = load i32*, i32** %3
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %15
br label %72
22: ; preds = %15
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 9
br i1 %24, label %25, label %30
25: ; preds = %22
store i32 32, i32* %6
%26 = load i64, i64* %7
%27 = urem i64 %26, 8
%28 = sub i64 8, %27
%29 = trunc i64 %28 to i32
store i32 %29, i32* %8
br label %31
30: ; preds = %22
store i32 1, i32* %8
br label %31
31: ; preds = %30, %25
%32 = load i64, i64* %7
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = add i64 %32, %34
%36 = load i32, i32* @readline.bufsize
%37 = sub nsw i32 %36, 2
%38 = sext i32 %37 to i64
%39 = icmp ugt i64 %35, %38
br i1 %39, label %40, label %46
40: ; preds = %31
%41 = load i32, i32* @readline.bufsize
%42 = add nsw i32 %41, 135
store i32 %42, i32* @readline.bufsize
%43 = load i8*, i8** @readline.buffer
%44 = load i32, i32* @readline.bufsize
%45 = call i8* @myrealloc(i8* %43, i32 %44)
store i8* %45, i8** @readline.buffer
br label %46
46: ; preds = %40, %31
store i32 0, i32* %9
br label %47
47: ; preds = %60, %46
%48 = load i32, i32* %9
%49 = load i32, i32* %8
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %63
51: ; preds = %47
%52 = load i32, i32* %6
%53 = trunc i32 %52 to i8
%54 = load i8*, i8** @readline.buffer
%55 = load i64, i64* %7
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = add i64 %55, %57
%59 = getelementptr inbounds i8, i8* %54, i64 %58
store i8 %53, i8* %59
br label %60
60: ; preds = %51
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %47
63: ; preds = %47
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = load i64, i64* %7
%67 = add i64 %66, %65
store i64 %67, i64* %7
%68 = load i32, i32* %6
%69 = icmp eq i32 %68, 10
br i1 %69, label %70, label %71
70: ; preds = %63
br label %72
71: ; preds = %63
br label %15
72: ; preds = %70, %21
%73 = load i8*, i8** @readline.buffer
%74 = load i64, i64* %7
%75 = getelementptr inbounds i8, i8* %73, i64 %74
store i8 0, i8* %75
%76 = load i64, i64* %7
%77 = add i64 %76, 1
%78 = call i8* @mymalloc(i64 %77)
store i8* %78, i8** %5
%79 = load i8*, i8** %5
%80 = load i8*, i8** @readline.buffer
%81 = call i32 @strcpy(i8* %79, i8* %80)
%82 = load i8*, i8** %5
%83 = load i8**, i8*** %4
store i8* %82, i8** %83
%84 = load i64, i64* %7
ret i64 %84
}

LLVM IR (-O2):
@readline.buffer = internal unnamed_addr global i8* null
@readline.bufsize = internal unnamed_addr global i32 135
@EOF = global i32 0
define i64 @readline(i32* nocapture %0, i8** nocapture writeonly %1) {
%3 = load i8*, i8** @readline.buffer
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i8* @mymalloc(i64 135)
store i8* %6, i8** @readline.buffer
br label %7
7: ; preds = %5, %2
br label %8
8: ; preds = %7, %28
%9 = phi i64 [ %19, %28 ], [ 0, %7 ]
%10 = tail call i32 @fgetc(i32* %0)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %33, label %13
13: ; preds = %8
%14 = icmp eq i32 %10, 9
%15 = and i64 %9, 7
%16 = sub nuw nsw i64 8, %15
%17 = select i1 %14, i32 32, i32 %10
%18 = select i1 %14, i64 %16, i64 1
%19 = add i64 %9, %18
%20 = load i32, i32* @readline.bufsize
%21 = add nsw i32 %20, -2
%22 = sext i32 %21 to i64
%23 = icmp ugt i64 %19, %22
br i1 %23, label %24, label %28
24: ; preds = %13
%25 = add nsw i32 %20, 135
store i32 %25, i32* @readline.bufsize
%26 = load i8*, i8** @readline.buffer
%27 = tail call i8* @myrealloc(i8* %26, i32 %25)
store i8* %27, i8** @readline.buffer
br label %28
28: ; preds = %24, %13
%29 = trunc i32 %17 to i8
%30 = load i8*, i8** @readline.buffer
%31 = getelementptr i8, i8* %30, i64 %9
%32 = icmp eq i32 %17, 10
br i1 %32, label %33, label %8
33: ; preds = %28, %8
%34 = phi i64 [ %9, %8 ], [ %19, %28 ]
%35 = load i8*, i8** @readline.buffer
%36 = getelementptr inbounds i8, i8* %35, i64 %34
store i8 0, i8* %36
%37 = add i64 %34, 1
%38 = tail call i8* @mymalloc(i64 %37)
%39 = load i8*, i8** @readline.buffer
%40 = tail call i32 @strcpy(i8* %38, i8* %39)
store i8* %38, i8** %1
ret i64 %34
}