#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;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, char *);
int sched_setscheduler(int /*<<< orphan*/, int, struct sched_param *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int set_policy(pid_t pid, int policy, int priority) {
  int ret;
  struct sched_param sched_p;
  sched_p.__sched_priority = priority;
  ret = sched_setscheduler(pid, policy, &sched_p);
  if (ret)
    fprintf(stderr, "sched_setscheduler returned %d errno=%d (%s).\n", ret,
            errno, strerror(errno));
  return ret;
}


x86 assembly (clang, -O0):
<set_policy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1030 <sched_setscheduler@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11a7 <set_policy+0x77>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    %rax,%r8
lea    0xe5e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_policy>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,0x8(%rsp)
lea    0x8(%rsp),%rdx
call   1030 <sched_setscheduler@plt>
mov    %eax,%ebx
test   %eax,%eax
je     117c <set_policy+0x4c>
mov    0x2e8d(%rip),%rax
mov    (%rax),%r14d
mov    0x2e7b(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1050 <strerror@plt>
lea    0xe93(%rip),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"sched_setscheduler returned %d errno=%d (%s).\0A\00"
@errno = global i32 0
define i32 @set_policy(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sched_param
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %8, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = call i32 @sched_setscheduler(i32 %11, i32 %12, %struct.sched_param* %8)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i32, i32* %7
%19 = load i32, i32* @errno
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19, i8* %21)
br label %23
23: ; preds = %16, %3
%24 = load i32, i32* %7
ret i32 %24
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"sched_setscheduler returned %d errno=%d (%s).\0A\00"
@errno = global i32 0
define i32 @set_policy(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sched_param
%5 = bitcast %struct.sched_param* %4 to i8*
%6 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i64 0, i32 0
store i32 %2, i32* %6
%7 = call i32 @sched_setscheduler(i32 %0, i32 %1, %struct.sched_param* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %11, i8* %12)
br label %14
14: ; preds = %9, %3
ret i32 %7
}