#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 */

/* Variables and functions */
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ puts(char *);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  char buf[80], *message;
  puts("Enter a line of text.");
  gets(buf);
  message = realloc(NULL, strlen(buf) + 1);
  strcpy(message, buf);
  puts(message);
  puts("Enter another line of text.");
  gets(buf);
  message = realloc(message, (strlen(message) + strlen(buf) + 1));
  strcat(message, buf);
  puts(message);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
lea    -0x60(%rbp),%rdi
call   1060 <gets@plt>
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rsi
add    $0x1,%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <realloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x68(%rbp),%rdi
call   1040 <puts@plt>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
lea    -0x60(%rbp),%rdi
call   1060 <gets@plt>
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x78(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x78(%rbp),%rsi
mov    -0x70(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1070 <realloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x68(%rbp),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1060 <gets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe58(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1060 <gets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%rsi
add    $0x1,%rsi
mov    %rbx,%rdi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter a line of text.\00"
@.str.1 = [28 x i8] c"Enter another line of text.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%10 = call i32 @gets(i8* %9)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 1
%14 = call i8* @realloc(i8* null, i64 %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %7
%19 = call i32 @puts(i8* %18)
%20 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%22 = call i32 @gets(i8* %21)
%23 = load i8*, i8** %7
%24 = load i8*, i8** %7
%25 = call i64 @strlen(i8* %24)
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 %25, %27
%29 = add nsw i64 %28, 1
%30 = call i8* @realloc(i8* %23, i64 %29)
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = load i8*, i8** %7
%35 = call i32 @puts(i8* %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter a line of text.\00"
@.str.1 = [28 x i8] c"Enter another line of text.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @gets(i8* %4)
%7 = call i64 @strlen(i8* %4)
%8 = add nsw i64 %7, 1
%9 = call i8* @malloc(i64 %8)
%10 = call i32 @strcpy(i8* %9, i8* %4)
%11 = call i32 @puts(i8* dereferenceable(1) %9)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @gets(i8* %4)
%14 = call i64 @strlen(i8* dereferenceable(1) %9)
%15 = call i64 @strlen(i8* %4)
%16 = add i64 %14, 1
%17 = add i64 %16, %15
%18 = call i8* @realloc(i8* %9, i64 %17)
%19 = call i32 @strcat(i8* %18, i8* %4)
%20 = call i32 @puts(i8* dereferenceable(1) %18)
ret i32 0
}