#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 */
struct sched_param {
  int sched_priority;
};

/* Variables and functions */
int /*<<< orphan*/ SCHED_RR;
int /*<<< orphan*/ perror(char *);
scalar_t__ pthread_getschedparam(int /*<<< orphan*/, int *,
                                 struct sched_param *);
int /*<<< orphan*/ pthread_self();
scalar_t__ pthread_setschedparam(int /*<<< orphan*/, int /*<<< orphan*/,
                                 struct sched_param *);
int /*<<< orphan*/ update();
int /*<<< orphan*/ usleep(int);
void *spy(void *ignored) {
#pragma unused(ignored)
  struct sched_param params;
  int policy;
  if (pthread_getschedparam(pthread_self(), &policy, &params))
    perror("getschedparam");
  params.sched_priority += 9;
  if (pthread_setschedparam(pthread_self(), SCHED_RR, &params))
    perror("setschedparam");
  for (;;) {
    update();
    usleep(10000);
  }
}


x86 assembly (clang, -O0):
<spy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
lea    -0x14(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <pthread_getschedparam@plt>
cmp    $0x0,%rax
je     1198 <spy+0x38>
lea    0xe6d(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%eax
add    $0x9,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <pthread_setschedparam@plt>
cmp    $0x0,%rax
je     11d2 <spy+0x72>
lea    0xe41(%rip),%rdi
call   1070 <perror@plt>
jmp    11d7 <spy+0x77>
mov    $0x0,%al
call   1030 <update@plt>
mov    $0x2710,%edi
call   1080 <usleep@plt>
jmp    11d7 <spy+0x77>

x86 assembly (clang, -O2):
<spy>:
push   %rax
xor    %eax,%eax
call   1060 <pthread_self@plt>
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %eax,%edi
call   1050 <pthread_getschedparam@plt>
test   %rax,%rax
jne    11b3 <spy+0x53>
addl   $0x9,(%rsp)
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    0x2e4a(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1040 <pthread_setschedparam@plt>
test   %rax,%rax
jne    11c1 <spy+0x61>
nop
xor    %eax,%eax
call   1030 <update@plt>
mov    $0x2710,%edi
call   1080 <usleep@plt>
jmp    11a0 <spy+0x40>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
jmp    117c <spy+0x1c>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
jmp    11a0 <spy+0x40>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [14 x i8] c"getschedparam\00"
@SCHED_RR = global i32 0
@.str.1 = [14 x i8] c"setschedparam\00"
define i8* @spy(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.sched_param
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @pthread_self()
%6 = call i64 @pthread_getschedparam(i32 %5, i32* %4, %struct.sched_param* %3)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 9
store i32 %13, i32* %11
%14 = call i32 (...) @pthread_self()
%15 = load i32, i32* @SCHED_RR
%16 = call i64 @pthread_setschedparam(i32 %14, i32 %15, %struct.sched_param* %3)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %10
br label %21
21: ; preds = %21, %20
%22 = call i32 (...) @update()
%23 = call i32 @usleep(i32 10000)
br label %21
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [14 x i8] c"getschedparam\00"
@SCHED_RR = global i32 0
@.str.1 = [14 x i8] c"setschedparam\00"
define noalias i8* @spy(i8* nocapture readnone %0) {
%2 = alloca %struct.sched_param
%3 = alloca i32
%4 = bitcast %struct.sched_param* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 (...) @pthread_self()
%7 = call i64 @pthread_getschedparam(i32 %6, i32* %3, %struct.sched_param* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 9
store i32 %14, i32* %12
%15 = call i32 (...) @pthread_self()
%16 = load i32, i32* @SCHED_RR
%17 = call i64 @pthread_setschedparam(i32 %15, i32 %16, %struct.sched_param* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %11
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %11
br label %22
22: ; preds = %21, %22
%23 = call i32 (...) @update()
%24 = call i32 @usleep(i32 10000)
br label %22
}