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


x86 assembly (clang, -O0):
<thread_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x9c(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    -0xb0(%rbp),%rdi
mov    %eax,%edx
lea    0xe7b(%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    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
mov    %eax,-0x9c(%rbp)
jmp    11d2 <thread_main+0x92>

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    0xea0(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
jmp    11a0 <thread_main+0x60>

LLVM IR (-O0):
@.str = [41 x i8] c"echo %ld >> /sys/fs/cgroup/cpu/zz/tasks \00"
@SYS_gettid = global i32 0
@.str.1 = [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
store i32 0, i32* %5
%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 ([41 x i8], [41 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 = load i8*, i8** %2
%13 = ptrtoint i8* %12 to i64
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = load i32, i32* @SYS_gettid
%16 = call i32 @syscall(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i64 %14, i32 %16)
br label %18
18: ; preds = %1, %18
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %18
}

LLVM IR (-O2):
@.str = [41 x i8] c"echo %ld >> /sys/fs/cgroup/cpu/zz/tasks \00"
@SYS_gettid = global i32 0
@.str.1 = [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 ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 @system(i8* %3)
%8 = ptrtoint i8* %0 to i64
%9 = load i32, i32* @SYS_gettid
%10 = tail call i32 @syscall(i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i64 %8, i32 %10)
br label %12
12: ; preds = %12, %1
br label %12
}