#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 */
typedef int /*<<< orphan*/ cpumask;
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ busy_work(int);
int /*<<< orphan*/ ftrace_write(char *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ pthread_setschedprio(int /*<<< orphan*/, int);
int sched_getcpu();
int /*<<< orphan*/ sched_setaffinity(int /*<<< orphan*/, int,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(int);
void *high_thread(void *ptr) {
  pthread_setschedprio(pthread_self(), 85);
  cpu_set_t cpumask;
  CPU_ZERO(&cpumask);
  CPU_SET(2, &cpumask);
  sched_setaffinity(0, sizeof(cpumask), &cpumask);
  int i;
  for (i = 0; i < 100 * 4; i++) {
    if (i % 10 == 0)
      printf("High thread interfering on cpu %d  -- start\n", sched_getcpu());
    ftrace_write("MSS531:High thread interfering on cpu %d \n", sched_getcpu());
    busy_work(10000);
    usleep(100);
  }
}


x86 assembly (clang, -O0):
<high_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <pthread_self@plt>
mov    %eax,%edi
mov    $0x55,%esi
call   1070 <pthread_setschedprio@plt>
lea    -0x14(%rbp),%rdi
call   1080 <CPU_ZERO@plt>
mov    $0x2,%edi
lea    -0x14(%rbp),%rsi
call   10b0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x14(%rbp),%rdx
call   1060 <sched_setaffinity@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x190,-0x18(%rbp)
jge    125a <high_thread+0xba>
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1223 <high_thread+0x83>
mov    $0x0,%al
call   10a0 <sched_getcpu@plt>
mov    %eax,%esi
lea    0xde2(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   10a0 <sched_getcpu@plt>
mov    %eax,%esi
lea    0xdfa(%rip),%rdi
call   1050 <ftrace_write@plt>
mov    $0x2710,%edi
call   1040 <busy_work@plt>
mov    $0x64,%edi
call   10c0 <usleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ed <high_thread+0x4d>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<high_thread>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <pthread_self@plt>
mov    %eax,%edi
mov    $0x55,%esi
call   1070 <pthread_setschedprio@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <CPU_ZERO@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
call   10b0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1060 <sched_setaffinity@plt>
lea    0xe16(%rip),%r14
lea    0xe3c(%rip),%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1233 <high_thread+0x93>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <sched_getcpu@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <ftrace_write@plt>
mov    $0x2710,%edi
call   1040 <busy_work@plt>
mov    $0x64,%edi
call   10c0 <usleep@plt>
add    $0xffffffff,%ebx
add    $0x1,%ebp
cmp    $0xfffffe70,%ebx
je     125f <high_thread+0xbf>
movzwl %bp,%eax
imul   $0xcccd,%eax,%eax
shr    $0x12,%eax
and    $0xfffffffe,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
cmp    %bx,%ax
jne    1200 <high_thread+0x60>
xor    %eax,%eax
call   10a0 <sched_getcpu@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
jmp    1200 <high_thread+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"High thread interfering on cpu %d -- start\0A\00"
@.str.1 = [43 x i8] c"MSS531:High thread interfering on cpu %d \0A\00"
define i8* @high_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 (...) @pthread_self()
%7 = call i32 @pthread_setschedprio(i32 %6, i32 85)
%8 = call i32 @CPU_ZERO(i32* %4)
%9 = call i32 @CPU_SET(i32 2, i32* %4)
%10 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %4)
store i32 0, i32* %5
br label %11
11: ; preds = %26, %1
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 400
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i32, i32* %5
%16 = srem i32 %15, 10
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 (...) @sched_getcpu()
%20 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %14
%22 = call i32 (...) @sched_getcpu()
%23 = call i32 @ftrace_write(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i32 @busy_work(i32 10000)
%25 = call i32 @usleep(i32 100)
br label %26
26: ; preds = %21
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %11
29: ; preds = %11
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@.str = [45 x i8] c"High thread interfering on cpu %d -- start\0A\00"
@.str.1 = [43 x i8] c"MSS531:High thread interfering on cpu %d \0A\00"
define noalias i8* @high_thread(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = tail call i32 (...) @pthread_self()
%4 = tail call i32 @pthread_setschedprio(i32 %3, i32 85)
%5 = bitcast i32* %2 to i8*
%6 = call i32 @CPU_ZERO(i32* %2)
%7 = call i32 @CPU_SET(i32 2, i32* %2)
%8 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %2)
br label %9
9: ; preds = %1, %17
%10 = phi i32 [ 0, %1 ], [ %22, %17 ]
%11 = trunc i32 %10 to i16
%12 = urem i16 %11, 10
%13 = icmp eq i16 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = call i32 (...) @sched_getcpu()
%16 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %9
%18 = call i32 (...) @sched_getcpu()
%19 = call i32 @ftrace_write(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @busy_work(i32 10000)
%21 = call i32 @usleep(i32 100)
%22 = add nuw nsw i32 %10, 1
%23 = icmp eq i32 %22, 400
br i1 %23, label %24, label %9
24: ; preds = %17
ret i8* undef
}