#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*/ fprintf(int /*<<< orphan*/, char *, long,
                           int /*<<< orphan*/);
int /*<<< orphan*/ sched_getcpu();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
void *thread_function(void *arg) {
  int i;
  long num = (long)arg;
  for (;;) {
    for (i = 0; i < 500000000; i++)
      ;
    fprintf(stderr, "[%ld] CPU -> %d\n", num, sched_getcpu());
    sleep(1);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<thread_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x1dcd6500,-0xc(%rbp)
jge    116b <thread_function+0x3b>
jmp    115d <thread_function+0x2d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <thread_function+0x1b>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <sched_getcpu@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
lea    0xe6a(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1144 <thread_function+0x14>

x86 assembly (clang, -O2):
<thread_function>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9f(%rip),%r15
lea    0xeb8(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r15),%ebp
xor    %eax,%eax
call   1040 <sched_getcpu@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1150 <thread_function+0x20>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"[%ld] CPU -> %d\0A\00"
define i8* @thread_function(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = ptrtoint i8* %5 to i64
store i64 %6, i64* %4
br label %7
7: ; preds = %15, %1
store i32 0, i32* %3
br label %8
8: ; preds = %12, %7
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 500000000
br i1 %10, label %11, label %15
11: ; preds = %8
br label %12
12: ; preds = %11
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %8
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = load i64, i64* %4
%18 = call i32 (...) @sched_getcpu()
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %17, i32 %18)
%20 = call i32 @sleep(i32 1)
br label %7
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"[%ld] CPU -> %d\0A\00"
define noalias i8* @thread_function(i8* %0) {
%2 = ptrtoint i8* %0 to i64
br label %3
3: ; preds = %3, %1
%4 = load i32, i32* @stderr
%5 = tail call i32 (...) @sched_getcpu()
%6 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %2, i32 %5)
%7 = tail call i32 @sleep(i32 1)
br label %3
}