#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sleep(int);
void *my_thread(void *p_arg) {
  int external_cnt;
  int local_cnt;
  external_cnt = *(int *)(p_arg);
  for (local_cnt = 0; local_cnt < 10; local_cnt++) {
    printf("[THREAD] - Thread #%d.... local_cnt = %d\n", external_cnt,
           local_cnt);
    sleep(1);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<my_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    1170 <my_thread+0x50>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113c <my_thread+0x1c>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
@.str = [42 x i8] c"[THREAD] - Thread #%d.... local_cnt = %d\0A\00"
define noalias i8* @my_thread(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%5 = tail call i32 @sleep(i32 1)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 1)
%7 = tail call i32 @sleep(i32 1)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 2)
%9 = tail call i32 @sleep(i32 1)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 3)
%11 = tail call i32 @sleep(i32 1)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 4)
%13 = tail call i32 @sleep(i32 1)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 5)
%15 = tail call i32 @sleep(i32 1)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 6)
%17 = tail call i32 @sleep(i32 1)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 7)
%19 = tail call i32 @sleep(i32 1)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 8)
%21 = tail call i32 @sleep(i32 1)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 9)
%23 = tail call i32 @sleep(i32 1)
ret i8* null
}