void flush_line(char *data, int index) {
  unsigned int i, n;
  unsigned char c;
  n = strlen(data);
  c = 8;
  for (i = index; i < n; i++)
    sio_write(&(data[i]), 1);
  sio_write(" ", 1);
  for (i = index; i < n; i++)
    sio_write(&c, 1);
}


x86 assembly (clang, -O0):
<flush_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movb   $0x8,-0x15(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1175 <flush_line+0x55>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
add    %rax,%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <sio_write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1145 <flush_line+0x25>
lea    0xe84(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <sio_write@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11b8 <flush_line+0x98>
lea    -0x15(%rbp),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <sio_write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118e <flush_line+0x6e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flush_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <strlen@plt>
mov    %rax,%r15
movb   $0x8,0x7(%rsp)
mov    %r15d,%ebx
sub    %r14d,%ebx
jbe    11b0 <flush_line+0x90>
mov    %r14d,%eax
add    %rax,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <sio_write@plt>
add    $0x1,%rbp
add    $0xffffffff,%ebx
jne    1150 <flush_line+0x30>
lea    0xe91(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <sio_write@plt>
sub    %r14d,%r15d
jbe    11a5 <flush_line+0x85>
lea    0x7(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <sio_write@plt>
add    $0xffffffff,%r15d
jne    1190 <flush_line+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe49(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sio_write@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @flush_line(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %6
store i8 8, i8* %7
%11 = load i32, i32* %4
store i32 %11, i32* %5
br label %12
12: ; preds = %22, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @sio_write to i32 (i8*, i32, ...)*)(i8* %20, i32 1)
br label %22
22: ; preds = %16
%23 = load i32, i32* %5
%24 = add i32 %23, 1
store i32 %24, i32* %5
br label %12
25: ; preds = %12
%26 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @sio_write to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%27 = load i32, i32* %4
store i32 %27, i32* %5
br label %28
28: ; preds = %34, %25
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = icmp ult i32 %29, %30
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @sio_write to i32 (i8*, i32, ...)*)(i8* %7, i32 1)
br label %34
34: ; preds = %32
%35 = load i32, i32* %5
%36 = add i32 %35, 1
store i32 %36, i32* %5
br label %28
37: ; preds = %28
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @flush_line(i8* %0, i32 %1) {
%3 = alloca i8
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = trunc i64 %4 to i32
store i8 8, i8* %3
%6 = icmp ugt i32 %5, %1
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @sio_write to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %25
9: ; preds = %2
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ %10, %9 ], [ %15, %11 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @sio_write to i32 (i8*, i32, ...)*)(i8* %13, i32 1)
%15 = add nuw nsw i64 %12, 1
%16 = trunc i64 %15 to i32
%17 = icmp eq i32 %16, %5
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @sio_write to i32 (i8*, i32, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br i1 %6, label %20, label %25
20: ; preds = %18, %20
%21 = phi i32 [ %23, %20 ], [ %1, %18 ]
%22 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @sio_write to i32 (i8*, i32, ...)*)(i8* %3, i32 1)
%23 = add i32 %21, 1
%24 = icmp eq i32 %23, %5
br i1 %24, label %25, label %20
25: ; preds = %20, %7, %18
ret void
}