#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
char *malloc(size_t);
char *realloc(char *, size_t);
char *str_convert(char *);
int /*<<< orphan*/ strcat(char *, char *);
size_t strlen(char *);
size_t strspn(char *, char *);
char *read_until_blank_line(FILE *fp, int *line_num) {
  char buffer[256], *str_read = NULL;
  while (fgets(buffer, 256, fp)) {
    size_t length = strlen(buffer);
    ++*line_num;
    if (strspn(buffer, " \n\r\t\v\f") == length) {
      return str_convert(str_read);
    }
    if (str_read) {
      if (!(str_read = realloc(str_read, strlen(str_read) + length + 2)))
        return NULL;
      strcat(str_read, " ");
    } else {
      if (!(str_read = malloc(length + 1)))
        return NULL;
      str_read[0] = '\0';
    }
    strcat(str_read, buffer);
  }
  return str_read;
}


x86 assembly (clang, -O0):
<read_until_blank_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12c8 <read_until_blank_line+0x158>
lea    -0x120(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x130(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
lea    -0x120(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1040 <strspn@plt>
cmp    -0x130(%rbp),%rax
jne    1200 <read_until_blank_line+0x90>
mov    -0x128(%rbp),%rdi
call   1070 <str_convert@plt>
mov    %rax,-0x8(%rbp)
jmp    12d3 <read_until_blank_line+0x163>
cmpq   $0x0,-0x128(%rbp)
je     1278 <read_until_blank_line+0x108>
mov    -0x128(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x128(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x138(%rbp),%rdi
mov    %rax,%rsi
add    -0x130(%rbp),%rsi
add    $0x2,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    1260 <read_until_blank_line+0xf0>
movq   $0x0,-0x8(%rbp)
jmp    12d3 <read_until_blank_line+0x163>
mov    -0x128(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1090 <strcat@plt>
jmp    12b0 <read_until_blank_line+0x140>
mov    -0x130(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    12a6 <read_until_blank_line+0x136>
movq   $0x0,-0x8(%rbp)
jmp    12d3 <read_until_blank_line+0x163>
mov    -0x128(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x128(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1090 <strcat@plt>
jmp    118e <read_until_blank_line+0x1e>
mov    -0x128(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_until_blank_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     123c <read_until_blank_line+0xcc>
mov    %rsp,%r12
lea    0xe56(%rip),%r13
xor    %ebx,%ebx
jmp    11ff <read_until_blank_line+0x8f>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbp,1),%rsi
add    $0x2,%rsi
mov    %rbx,%rdi
call   1080 <realloc@plt>
test   %rax,%rax
je     123c <read_until_blank_line+0xcc>
mov    %rax,%rbx
mov    %rax,%rdi
lea    0xe2d(%rip),%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     124b <read_until_blank_line+0xdb>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbp
addl   $0x1,(%r14)
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <strspn@plt>
cmp    %rbp,%rax
je     1240 <read_until_blank_line+0xd0>
test   %rbx,%rbx
jne    11b0 <read_until_blank_line+0x40>
add    $0x1,%rbp
mov    %rbp,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     123c <read_until_blank_line+0xcc>
mov    %rax,%rbx
movb   $0x0,(%rax)
jmp    11df <read_until_blank_line+0x6f>
xor    %ebx,%ebx
jmp    124b <read_until_blank_line+0xdb>
mov    %rbx,%rdi
call   1070 <str_convert@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c" \0A\0D\09\0B\0C\00"
@.str.1 = [2 x i8] c" \00"
define i8* @read_until_blank_line(i32* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* null, i8** %7
br label %9
9: ; preds = %52, %2
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = load i32*, i32** %4
%12 = call i64 @fgets(i8* %10, i32 256, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %56
14: ; preds = %9
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %8
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = call i64 @strspn(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%22 = load i64, i64* %8
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = load i8*, i8** %7
%26 = call i8* @str_convert(i8* %25)
store i8* %26, i8** %3
br label %58
27: ; preds = %14
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %43
30: ; preds = %27
%31 = load i8*, i8** %7
%32 = load i8*, i8** %7
%33 = call i64 @strlen(i8* %32)
%34 = load i64, i64* %8
%35 = add i64 %33, %34
%36 = add i64 %35, 2
%37 = call i8* @realloc(i8* %31, i64 %36)
store i8* %37, i8** %7
%38 = icmp ne i8* %37, null
br i1 %38, label %40, label %39
39: ; preds = %30
store i8* null, i8** %3
br label %58
40: ; preds = %30
%41 = load i8*, i8** %7
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %52
43: ; preds = %27
%44 = load i64, i64* %8
%45 = add i64 %44, 1
%46 = call i8* @malloc(i64 %45)
store i8* %46, i8** %7
%47 = icmp ne i8* %46, null
br i1 %47, label %49, label %48
48: ; preds = %43
store i8* null, i8** %3
br label %58
49: ; preds = %43
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i64 0
store i8 0, i8* %51
br label %52
52: ; preds = %49, %40
%53 = load i8*, i8** %7
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%55 = call i32 @strcat(i8* %53, i8* %54)
br label %9
56: ; preds = %9
%57 = load i8*, i8** %7
store i8* %57, i8** %3
br label %58
58: ; preds = %56, %48, %39, %24
%59 = load i8*, i8** %3
ret i8* %59
}

LLVM IR (-O2):
@.str = [7 x i8] c" \0A\0D\09\0B\0C\00"
@.str.1 = [2 x i8] c" \00"
define i8* @read_until_blank_line(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i64 @fgets(i8* %4, i32 256, i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %36, label %7
7: ; preds = %2, %31
%8 = phi i8* [ %32, %31 ], [ null, %2 ]
%9 = call i64 @strlen(i8* %4)
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %1
%12 = call i64 @strspn(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, %9
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = call i8* @str_convert(i8* %8)
br label %36
16: ; preds = %7
%17 = icmp eq i8* %8, null
br i1 %17, label %26, label %18
18: ; preds = %16
%19 = call i64 @strlen(i8* %8)
%20 = add i64 %9, 2
%21 = add i64 %20, %19
%22 = call i8* @realloc(i8* %8, i64 %21)
%23 = icmp eq i8* %22, null
br i1 %23, label %36, label %24
24: ; preds = %18
%25 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %31
26: ; preds = %16
%27 = add i64 %9, 1
%28 = call i8* @malloc(i64 %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %36, label %30
30: ; preds = %26
store i8 0, i8* %28
br label %31
31: ; preds = %24, %30
%32 = phi i8* [ %22, %24 ], [ %28, %30 ]
%33 = call i32 @strcat(i8* %32, i8* %4)
%34 = call i64 @fgets(i8* %4, i32 256, i32* %0)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %7
36: ; preds = %31, %18, %26, %2, %14
%37 = phi i8* [ %15, %14 ], [ null, %2 ], [ %32, %31 ], [ null, %18 ], [ null, %26 ]
ret i8* %37
}