int main(int argc, const char *argv[]) {
  char buf[10];
  int ret;
  while (1) {
    ret = read(0, buf, 10);
    if (ret < 10) {
      buf[ret] = "\0";
      printf("%s\n", buf);
      break;
    } else {
      printf("%s\n", buf);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1a(%rbp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    117b <main+0x5b>
movslq -0x20(%rbp),%rax
lea    0xea0(%rip),%rcx
mov    %cl,-0x1a(%rbp,%rax,1)
lea    -0x1a(%rbp),%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <main+0x72>
lea    -0x1a(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x6(%rsp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
xor    %eax,%eax
call   1040 <read@plt>
cmp    $0xa,%eax
jl     116e <main+0x4e>
lea    0x6(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1040 <read@plt>
cmp    $0xa,%eax
jge    1150 <main+0x30>
cltq
lea    0xe89(%rip),%rcx
mov    %cl,0x6(%rsp,%rax,1)
lea    0x6(%rsp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] zeroinitializer
@.str.1 = [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 [10 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %2, %22
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%10 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %9, i32 10)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 %15
store i8 ptrtoint ([2 x i8]* @.str to i8), i8* %16
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %23
19: ; preds = %8
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19
br label %8
23: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %4, i32 10)
%6 = icmp slt i32 %5, 10
br i1 %6, label %7, label %12
7: ; preds = %12, %2
%8 = phi i32 [ %5, %2 ], [ %14, %12 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %9
store i8 ptrtoint ([2 x i8]* @.str to i8), i8* %10
%11 = call i32 @puts(i8* %4)
ret i32 0
12: ; preds = %2, %12
%13 = call i32 @puts(i8* %4)
%14 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 0, i8* %4, i32 10)
%15 = icmp slt i32 %14, 10
br i1 %15, label %7, label %12
}