#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*/ SYS_gettid;
int /*<<< orphan*/ printf(char *, long, int /*<<< orphan*/);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ syscall(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
void *thread_main(void *threadid) {
  char cmd[128];
  sprintf(cmd, "echo %ld >> /sys/fs/cgroup/cpu/klose/tasks",
          syscall(SYS_gettid));
  system(cmd);
  sprintf(cmd, "echo %ld >> /sys/fs/cgroup/cpuset/klose/tasks",
          syscall(SYS_gettid));
  system(cmd);
  long tid;
  tid = (long)threadid;
  printf("Hello World! It's me, thread #%ld, pid #%ld!\n", tid,
         syscall(SYS_gettid));
  int a = 0;
  while (1) {
    a++;
  }
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<thread_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%edx
lea    0xe85(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1030 <system@plt>
lea    -0x90(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    -0xb0(%rbp),%rdi
mov    %eax,%edx
lea    0xe73(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1030 <system@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
mov    %eax,-0x9c(%rbp)
jmp    120f <thread_main+0xcf>

x86 assembly (clang, -O2):
<thread_main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%r14
mov    0x2e92(%rip),%r15
mov    (%r15),%edi
call   1050 <syscall@plt>
lea    0xe9b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
mov    (%r15),%edi
call   1050 <syscall@plt>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
mov    (%r15),%edi
call   1050 <syscall@plt>
lea    0xeaf(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
jmp    11c0 <thread_main+0x80>

LLVM IR (-O0):
@.str = [43 x i8] c"echo %ld >> /sys/fs/cgroup/cpu/klose/tasks\00"
@SYS_gettid = global i32 0
@.str.1 = [46 x i8] c"echo %ld >> /sys/fs/cgroup/cpuset/klose/tasks\00"
@.str.2 = [46 x i8] c"Hello World! It's me, thread #%ld, pid #%ld!\0A\00"
define i8* @thread_main(i8* %0) {
%2 = alloca i8*
%3 = alloca [128 x i8]
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @SYS_gettid
%8 = call i32 @syscall(i32 %7)
%9 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%11 = call i32 @system(i8* %10)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* @SYS_gettid
%14 = call i32 @syscall(i32 %13)
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%17 = call i32 @system(i8* %16)
%18 = load i8*, i8** %2
%19 = ptrtoint i8* %18 to i64
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = load i32, i32* @SYS_gettid
%22 = call i32 @syscall(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 %20, i32 %22)
store i32 0, i32* %5
br label %24
24: ; preds = %1, %24
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %24
}

LLVM IR (-O2):
@.str = [43 x i8] c"echo %ld >> /sys/fs/cgroup/cpu/klose/tasks\00"
@SYS_gettid = global i32 0
@.str.1 = [46 x i8] c"echo %ld >> /sys/fs/cgroup/cpuset/klose/tasks\00"
@.str.2 = [46 x i8] c"Hello World! It's me, thread #%ld, pid #%ld!\0A\00"
define noalias i8* @thread_main(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @SYS_gettid
%5 = tail call i32 @syscall(i32 %4)
%6 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @system(i8* %3)
%8 = load i32, i32* @SYS_gettid
%9 = tail call i32 @syscall(i32 %8)
%10 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @system(i8* %3)
%12 = ptrtoint i8* %0 to i64
%13 = load i32, i32* @SYS_gettid
%14 = tail call i32 @syscall(i32 %13)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 %12, i32 %14)
br label %16
16: ; preds = %16, %1
br label %16
}