void *rutina(void *arg) {
  for (int i = 0; i < 10; i++) {
    printf("               Hola %d del hilo%d\n", i, (int *)arg);
    sleep((i + 1) / 2);
  }
}


x86 assembly (clang, -O0):
<rutina>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1177 <rutina+0x57>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    $0x0,%al
call   1040 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <rutina+0x13>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rutina>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xed2(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
xor    %eax,%eax
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%edi
xor    %eax,%eax
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%edi
xor    %eax,%eax
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x3,%edi
xor    %eax,%eax
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    $0x6,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x3,%edi
xor    %eax,%eax
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    $0x7,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x4,%edi
xor    %eax,%eax
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    $0x8,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x4,%edi
xor    %eax,%eax
call   1040 <sleep@plt>
mov    %r14,%rdi
mov    $0x9,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x5,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <sleep@plt>

LLVM IR (-O0):
@.str = [35 x i8] c" Hola %d del hilo%d\0A\00"
define i8* @rutina(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
br label %5
5: ; preds = %17, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load i32, i32* %4
%10 = load i8*, i8** %3
%11 = bitcast i8* %10 to i32*
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %9, i32* %11)
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
%15 = sdiv i32 %14, 2
%16 = call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 %15)
br label %17
17: ; preds = %8
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %5
20: ; preds = %5
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@.str = [35 x i8] c" Hola %d del hilo%d\0A\00"
define i8* @rutina(i8* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 0, i8* %0)
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 0)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 1, i8* %0)
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 2, i8* %0)
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 3, i8* %0)
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 2)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 4, i8* %0)
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 2)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 5, i8* %0)
%13 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 3)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 6, i8* %0)
%15 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 3)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 7, i8* %0)
%17 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 4)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 8, i8* %0)
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 4)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 9, i8* %0)
%21 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 5)
ret i8* undef
}