#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*/ chomp(char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strncat(char *, char *, int);
void read_lines_from_stdin(char *dst, int size) {
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  int remaining_size;
  remaining_size = size - 1;
  while ((read = getline(&line, &len, stdin)) != -1) {
    strncat(dst, line, remaining_size);
    remaining_size -= read;
    if (remaining_size <= 0)
      break;
  }
  chomp(dst);
  free(line);
}


x86 assembly (clang, -O0):
<read_lines_from_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     11b9 <read_lines_from_stdin+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1040 <strncat@plt>
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     11b4 <read_lines_from_stdin+0x74>
jmp    11b9 <read_lines_from_stdin+0x79>
jmp    1168 <read_lines_from_stdin+0x28>
mov    -0x8(%rbp),%rdi
call   1050 <chomp@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_lines_from_stdin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r12
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
add    $0xffffffff,%ebp
mov    0x2e79(%rip),%r13
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
nopl   0x0(%rax)
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     11a9 <read_lines_from_stdin+0x69>
mov    %eax,%ebx
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
mov    %ebp,%edx
call   1040 <strncat@plt>
sub    %ebx,%ebp
jg     1180 <read_lines_from_stdin+0x40>
mov    %r12,%rdi
call   1050 <chomp@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define void @read_lines_from_stdin(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %5
store i64 0, i64* %6
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %8
br label %11
11: ; preds = %26, %2
%12 = load i32, i32* @stdin
%13 = call i32 @getline(i8** %5, i64* %6, i32 %12)
store i32 %13, i32* %7
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = load i8*, i8** %5
%18 = load i32, i32* %8
%19 = call i32 @strncat(i8* %16, i8* %17, i32 %18)
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = sub nsw i32 %21, %20
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %15
br label %27
26: ; preds = %15
br label %11
27: ; preds = %25, %11
%28 = load i8*, i8** %3
%29 = call i32 @chomp(i8* %28)
%30 = load i8*, i8** %5
%31 = call i32 @free(i8* %30)
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
define void @read_lines_from_stdin(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = add nsw i32 %1, -1
br label %8
8: ; preds = %13, %2
%9 = phi i32 [ %7, %2 ], [ %16, %13 ]
%10 = load i32, i32* @stdin
%11 = call i32 @getline(i8** %3, i64* %4, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 @strncat(i8* %0, i8* %14, i32 %9)
%16 = sub nsw i32 %9, %11
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %8
18: ; preds = %13, %8
%19 = call i32 @chomp(i8* %0)
%20 = load i8*, i8** %3
%21 = call i32 @free(i8* %20)
ret void
}