void *run(void *arg) {
  int count = 0;
  for (;;) {
    printf("Thread:%x; FUNC:%s; %s ;%d\n", (int)pthread_self(), __func__,
           (char *)arg, count);
    sleep(1);
    count++;
    if (count == 5) {
      break;
    }
  }
  return (void *)0;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%r8d
lea    0xea5(%rip),%rdi
lea    0xeba(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
mov    $0x0,%al
call   1050 <sleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jne    118d <run+0x5d>
jmp    1192 <run+0x62>
jmp    1143 <run+0x13>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <pthread_self@plt>
lea    0xeba(%rip),%r15
lea    0xecf(%rip),%r14
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <sleep@plt>
xor    %eax,%eax
call   1040 <pthread_self@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    $0x1,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <sleep@plt>
xor    %eax,%eax
call   1040 <pthread_self@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    $0x2,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <sleep@plt>
xor    %eax,%eax
call   1040 <pthread_self@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    $0x3,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <sleep@plt>
xor    %eax,%eax
call   1040 <pthread_self@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    $0x4,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <sleep@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Thread:%x; FUNC:%s; %s ;%d\0A\00"
@__func__.run = [4 x i8] c"run\00"
define i8* @run(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %15, %1
%5 = call i32 (...) @pthread_self()
%6 = load i8*, i8** %2
%7 = load i32, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__func__.run, i64 0, i64 0), i8* %6, i32 %7)
%9 = call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 5
br i1 %13, label %14, label %15
14: ; preds = %4
br label %16
15: ; preds = %4
br label %4
16: ; preds = %14
ret i8* null
}

LLVM IR (-O2):
@.str = [28 x i8] c"Thread:%x; FUNC:%s; %s ;%d\0A\00"
@__func__.run = [4 x i8] c"run\00"
define i8* @run(i8* %0) {
%2 = tail call i32 (...) @pthread_self()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__func__.run, i64 0, i64 0), i8* %0, i32 0)
%4 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%5 = tail call i32 (...) @pthread_self()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__func__.run, i64 0, i64 0), i8* %0, i32 1)
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%8 = tail call i32 (...) @pthread_self()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__func__.run, i64 0, i64 0), i8* %0, i32 2)
%10 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%11 = tail call i32 (...) @pthread_self()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__func__.run, i64 0, i64 0), i8* %0, i32 3)
%13 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
%14 = tail call i32 (...) @pthread_self()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @__func__.run, i64 0, i64 0), i8* %0, i32 4)
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @sleep to i32 (i32, ...)*)(i32 1)
ret i8* null
}