#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*/ ENOMEM;
int /*<<< orphan*/ errno;
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(char *, size_t);
size_t strlen(char *);
int main(int argc, const char **argv) {
  const char *INPUT_TOO_SHORT_MSG = "Your input was shorter than "
                                    "80"
                                    " characters.";
  size_t bufferCapacity = 128;
  char *buffer = (char *)malloc(sizeof(char) * 128);
  if (!buffer) {
    errno = ENOMEM;
    return 1;
  }
  size_t bufferCount = 0;
  char c = 0;
  while (1) {
    bufferCount = 0;
    memset(buffer, 0, sizeof(char) * bufferCapacity);
    printf(">>> ");
    while ((c = getchar()) && c != '\n') {
      if (bufferCount >= bufferCapacity - 1) {
        bufferCapacity = (bufferCapacity > 0) ? bufferCapacity * 2 : 128;
        buffer = (char *)realloc(buffer, bufferCapacity);
        if (!buffer) {
          errno = ENOMEM;
          return 1;
        }
      }
      buffer[bufferCount] = c;
      ++bufferCount;
    }
    buffer[bufferCount] = 0;
    size_t inputLen = strlen(buffer);
    if (inputLen < 80) {
      printf("%s\n", INPUT_TOO_SHORT_MSG);
    } else {
      printf("%s\n", buffer);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x80,-0x20(%rbp)
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c0 <main+0x60>
mov    0x2e37(%rip),%rax
mov    (%rax),%ecx
mov    0x2e26(%rip),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x1c6>
movq   $0x0,-0x30(%rbp)
movb   $0x0,-0x31(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x31(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x41(%rbp)
je     121f <main+0xbf>
movsbl -0x31(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    122f <main+0xcf>
jmp    12d4 <main+0x174>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jb     12b5 <main+0x155>
cmpq   $0x0,-0x20(%rbp)
jbe    1260 <main+0x100>
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    126e <main+0x10e>
mov    $0x80,%eax
mov    %rax,-0x50(%rbp)
jmp    126e <main+0x10e>
mov    -0x50(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12b0 <main+0x150>
mov    0x2d47(%rip),%rax
mov    (%rax),%ecx
mov    0x2d36(%rip),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1326 <main+0x1c6>
jmp    12b5 <main+0x155>
mov    -0x31(%rbp),%dl
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11f7 <main+0x97>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x50,-0x40(%rbp)
jae    130f <main+0x1af>
mov    -0x18(%rbp),%rsi
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1321 <main+0x1c1>
mov    -0x28(%rbp),%rsi
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cc <main+0x6c>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x80,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1234 <main+0xc4>
mov    %rax,%r15
mov    $0x80,%ebp
mov    $0x80,%r12d
jmp    11c4 <main+0x54>
xchg   %ax,%ax
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x50,%rax
mov    %r15,%rdi
lea    0xe45(%rip),%rax
cmovb  %rax,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1060 <memset@plt>
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %r14d,%r14d
jmp    11f8 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %bl,(%r15,%r14,1)
add    $0x1,%r14
xor    %eax,%eax
call   1070 <getchar@plt>
test   %al,%al
je     11a0 <main+0x30>
mov    %eax,%ebx
cmp    $0xa,%al
je     11a0 <main+0x30>
lea    -0x1(%r12),%rax
cmp    %rax,%r14
jb     11f0 <main+0x80>
lea    (%r12,%r12,1),%r13
test   %r12,%r12
cmove  %rbp,%r13
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <realloc@plt>
mov    %rax,%r15
mov    %r13,%r12
test   %rax,%rax
jne    11f0 <main+0x80>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    0x2d94(%rip),%rcx
mov    %eax,(%rcx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Your input was shorter than 80 characters.\00"
@ENOMEM = global i32 0
@errno = global i32 0
@.str.1 = [5 x i8] c">>> \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8** %6
store i64 128, i64* %7
%12 = call i64 @malloc(i32 128)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = load i32, i32* @ENOMEM
store i32 %17, i32* @errno
store i32 1, i32* %3
br label %81
18: ; preds = %2
store i64 0, i64* %9
store i8 0, i8* %10
br label %19
19: ; preds = %18, %80
store i64 0, i64* %9
%20 = load i8*, i8** %8
%21 = load i64, i64* %7
%22 = mul i64 1, %21
%23 = trunc i64 %22 to i32
%24 = call i32 @memset(i8* %20, i32 0, i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %59, %19
%27 = call signext i8 (...) @getchar()
store i8 %27, i8* %10
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i8, i8* %10
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 10
br label %34
34: ; preds = %30, %26
%35 = phi i1 [ false, %26 ], [ %33, %30 ]
br i1 %35, label %36, label %66
36: ; preds = %34
%37 = load i64, i64* %9
%38 = load i64, i64* %7
%39 = sub i64 %38, 1
%40 = icmp uge i64 %37, %39
br i1 %40, label %41, label %59
41: ; preds = %36
%42 = load i64, i64* %7
%43 = icmp ugt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i64, i64* %7
%46 = mul i64 %45, 2
br label %48
47: ; preds = %41
br label %48
48: ; preds = %47, %44
%49 = phi i64 [ %46, %44 ], [ 128, %47 ]
store i64 %49, i64* %7
%50 = load i8*, i8** %8
%51 = load i64, i64* %7
%52 = call i64 @realloc(i8* %50, i64 %51)
%53 = inttoptr i64 %52 to i8*
store i8* %53, i8** %8
%54 = load i8*, i8** %8
%55 = icmp ne i8* %54, null
br i1 %55, label %58, label %56
56: ; preds = %48
%57 = load i32, i32* @ENOMEM
store i32 %57, i32* @errno
store i32 1, i32* %3
br label %81
58: ; preds = %48
br label %59
59: ; preds = %58, %36
%60 = load i8, i8* %10
%61 = load i8*, i8** %8
%62 = load i64, i64* %9
%63 = getelementptr inbounds i8, i8* %61, i64 %62
store i8 %60, i8* %63
%64 = load i64, i64* %9
%65 = add i64 %64, 1
store i64 %65, i64* %9
br label %26
66: ; preds = %34
%67 = load i8*, i8** %8
%68 = load i64, i64* %9
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8 0, i8* %69
%70 = load i8*, i8** %8
%71 = call i64 @strlen(i8* %70)
store i64 %71, i64* %11
%72 = load i64, i64* %11
%73 = icmp ult i64 %72, 80
br i1 %73, label %74, label %77
74: ; preds = %66
%75 = load i8*, i8** %6
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %75)
br label %80
77: ; preds = %66
%78 = load i8*, i8** %8
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %77, %74
br label %19
81: ; preds = %56, %16
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [43 x i8] c"Your input was shorter than 80 characters.\00"
@ENOMEM = global i32 0
@errno = global i32 0
@.str.1 = [5 x i8] c">>> \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 128)
%4 = icmp eq i64 %3, 0
br i1 %4, label %39, label %5
5: ; preds = %2
%6 = inttoptr i64 %3 to i8*
br label %7
7: ; preds = %33, %5
%8 = phi i64 [ 128, %5 ], [ %14, %33 ]
%9 = phi i8* [ %6, %5 ], [ %15, %33 ]
%10 = trunc i64 %8 to i32
%11 = tail call i32 @memset(i8* %9, i32 0, i32 %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %28, %7
%14 = phi i64 [ %8, %7 ], [ %29, %28 ]
%15 = phi i8* [ %9, %7 ], [ %30, %28 ]
%16 = phi i64 [ 0, %7 ], [ %32, %28 ]
%17 = tail call signext i8 (...) @getchar()
switch i8 %17, label %18 [
i8 10, label %33
i8 0, label %33
]
18: ; preds = %13
%19 = add i64 %14, -1
%20 = icmp ult i64 %16, %19
br i1 %20, label %28, label %21
21: ; preds = %18
%22 = icmp eq i64 %14, 0
%23 = shl i64 %14, 1
%24 = select i1 %22, i64 128, i64 %23
%25 = tail call i64 @realloc(i8* %15, i64 %24)
%26 = inttoptr i64 %25 to i8*
%27 = icmp eq i64 %25, 0
br i1 %27, label %39, label %28
28: ; preds = %21, %18
%29 = phi i64 [ %24, %21 ], [ %14, %18 ]
%30 = phi i8* [ %26, %21 ], [ %15, %18 ]
%31 = getelementptr inbounds i8, i8* %30, i64 %16
store i8 %17, i8* %31
%32 = add i64 %16, 1
br label %13
33: ; preds = %13, %13
%34 = getelementptr inbounds i8, i8* %15, i64 %16
store i8 0, i8* %34
%35 = tail call i64 @strlen(i8* dereferenceable(1) %15)
%36 = icmp ult i64 %35, 80
%37 = select i1 %36, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %15
%38 = tail call i32 @puts(i8* dereferenceable(1) %37)
br label %7
39: ; preds = %21, %2
%40 = load i32, i32* @ENOMEM
store i32 %40, i32* @errno
ret i32 1
}