int main(int argc, char **argv) {
  char *prompt = "Enter something: ";
  char *errmsg = "Need more characters.";
  unsigned char buf[1024];
  char in[1];
  int i = 0;
  int MINLEN = 5;
  int in_fd = 0;
  int out_fd = 1;
  int err_out_fd = 2;
  write(out_fd, prompt, strlen(prompt));
  while (read(in_fd, in, 1)) {
    if (in[0] == '\n') {
      buf[i++] = 0;
      break;
    }
    buf[i++] = in[0];
  }
  write(out_fd, buf, strlen(buf));
  write(out_fd, "\n", 1);
  if (strlen(buf) < MINLEN) {
    write(err_out_fd, errmsg, strlen(errmsg));
    write(err_out_fd, "\n", 1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb0(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xeb7(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x428(%rbp)
movl   $0x5,-0x42c(%rbp)
movl   $0x0,-0x430(%rbp)
movl   $0x1,-0x434(%rbp)
movl   $0x2,-0x438(%rbp)
mov    -0x434(%rbp),%eax
mov    %eax,-0x444(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    %rax,%rdx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x430(%rbp),%edi
lea    -0x421(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%eax
je     123f <main+0x10f>
movsbl -0x421(%rbp),%eax
cmp    $0xa,%eax
jne    121a <main+0xea>
mov    -0x428(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x428(%rbp)
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
jmp    123f <main+0x10f>
mov    -0x421(%rbp),%cl
mov    -0x428(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x428(%rbp)
cltq
mov    %cl,-0x420(%rbp,%rax,1)
jmp    11c8 <main+0x98>
mov    -0x434(%rbp),%eax
mov    %eax,-0x454(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x450(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rsi
mov    %rax,%rdx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x434(%rbp),%edi
lea    0xd9f(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
movslq -0x42c(%rbp),%rcx
cmp    %rcx,%rax
jae    1301 <main+0x1d1>
mov    -0x438(%rbp),%eax
mov    %eax,-0x464(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x460(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x464(%rbp),%edi
mov    -0x460(%rbp),%rsi
mov    %rax,%rdx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x438(%rbp),%edi
lea    0xd33(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x418,%rsp
lea    0xebf(%rip),%rsi
mov    $0x11,%edx
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <write@plt>
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
je     119f <main+0x6f>
lea    0xf(%rsp),%r14
xor    %ebx,%ebx
movzbl 0xf(%rsp),%eax
cmp    $0xa,%al
je     1198 <main+0x68>
mov    %al,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
jne    1170 <main+0x40>
jmp    119f <main+0x6f>
mov    %ebx,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <write@plt>
lea    0xe63(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x4,%rax
ja     1214 <main+0xe4>
lea    0xe27(%rip),%rsi
mov    $0x15,%edx
mov    $0x2,%edi
xor    %eax,%eax
call   1030 <write@plt>
lea    0xe25(%rip),%rsi
mov    $0x2,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Enter something: \00"
@.str.1 = [22 x i8] c"Need more characters.\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca [1 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i32 0, i32* %10
store i32 5, i32* %11
store i32 0, i32* %12
store i32 1, i32* %13
store i32 2, i32* %14
%15 = load i32, i32* %13
%16 = load i8*, i8** %6
%17 = load i8*, i8** %6
%18 = call i64 @strlen(i8* %17)
%19 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %15, i8* %16, i64 %18)
br label %20
20: ; preds = %35, %2
%21 = load i32, i32* %12
%22 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%23 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %21, i8* %22, i32 1)
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %42
25: ; preds = %20
%26 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 1
store i32 %32, i32* %10
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %33
store i8 0, i8* %34
br label %42
35: ; preds = %25
%36 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%37 = load i8, i8* %36
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %40
store i8 %37, i8* %41
br label %20
42: ; preds = %30, %20
%43 = load i32, i32* %13
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%46 = call i64 @strlen(i8* %45)
%47 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %43, i8* %44, i64 %46)
%48 = load i32, i32* %13
%49 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%51 = call i64 @strlen(i8* %50)
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = icmp ult i64 %51, %53
br i1 %54, label %55, label %63
55: ; preds = %42
%56 = load i32, i32* %14
%57 = load i8*, i8** %7
%58 = load i8*, i8** %7
%59 = call i64 @strlen(i8* %58)
%60 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %56, i8* %57, i64 %59)
%61 = load i32, i32* %14
%62 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %63
63: ; preds = %55, %42
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [18 x i8] c"Enter something: \00"
@.str.1 = [22 x i8] c"Need more characters.\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 17)
%8 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %6, i32 1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %2, %17
%11 = phi i64 [ %18, %17 ], [ 0, %2 ]
%12 = load i8, i8* %6
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = and i64 %11, 4294967295
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %15
store i8 0, i8* %16
br label %22
17: ; preds = %10
%18 = add nuw i64 %11, 1
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %11
store i8 %12, i8* %19
%20 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %6, i32 1)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %10
22: ; preds = %17, %2, %14
%23 = call i64 @strlen(i8* %5)
%24 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 1, i8* %5, i64 %23)
%25 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%26 = call i64 @strlen(i8* %5)
%27 = icmp ult i64 %26, 5
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 21)
%30 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %31
31: ; preds = %28, %22
ret i32 0
}