#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*/ pthread_attr_t;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_EXPLICIT_SCHED;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setinheritsched(int /*<<< orphan*/ *, int /*<<< orphan*/);
int pthread_attr_setschedparam(int /*<<< orphan*/ *, struct sched_param *);
int pthread_attr_setschedpolicy(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
void init_attr(pthread_attr_t *attr, int sched_policy, int prio) {
  struct sched_param sched_param = {.sched_priority = prio};
  int ret;
  ret = pthread_attr_init(attr);
  if (ret) {
    fprintf(stderr, "pthread_attr_init(): %s\n", strerror(ret));
    exit(2);
  }
  ret = pthread_attr_setschedpolicy(attr, sched_policy);
  if (ret) {
    fprintf(stderr, "pthread_setschedpolicy(): %s\n", strerror(ret));
    exit(2);
  }
  ret = pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED);
  if (ret) {
    fprintf(stderr, "pthread_attr_setinheritsched(): %s\n", strerror(ret));
    exit(2);
  }
  ret = pthread_attr_setschedparam(attr, &sched_param);
  if (ret) {
    fprintf(stderr, "pthread_attr_setschedparam(): %s\n", strerror(ret));
    exit(2);
  }
}


x86 assembly (clang, -O0):
<init_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <pthread_attr_init@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11ce <init_attr+0x5e>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe41(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1217 <init_attr+0xa7>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe11(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
call   1030 <pthread_attr_setinheritsched@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1266 <init_attr+0xf6>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xde0(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <pthread_attr_setschedparam@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12b0 <init_attr+0x140>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xdba(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_attr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %edx,(%rsp)
call   1050 <pthread_attr_init@plt>
test   %eax,%eax
jne    11bd <init_attr+0x4d>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
jne    11d6 <init_attr+0x66>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <pthread_attr_setinheritsched@plt>
test   %eax,%eax
jne    11ef <init_attr+0x7f>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <pthread_attr_setschedparam@plt>
test   %eax,%eax
jne    1208 <init_attr+0x98>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e14(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1090 <strerror@plt>
lea    0xe2c(%rip),%rsi
jmp    121f <init_attr+0xaf>
mov    0x2dfb(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1090 <strerror@plt>
lea    0xe2c(%rip),%rsi
jmp    121f <init_attr+0xaf>
mov    0x2de2(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1090 <strerror@plt>
lea    0xe31(%rip),%rsi
jmp    121f <init_attr+0xaf>
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1090 <strerror@plt>
lea    0xe3c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"pthread_attr_init(): %s\0A\00"
@.str.1 = [30 x i8] c"pthread_setschedpolicy(): %s\0A\00"
@PTHREAD_EXPLICIT_SCHED = global i32 0
@.str.2 = [36 x i8] c"pthread_attr_setinheritsched(): %s\0A\00"
@.str.3 = [34 x i8] c"pthread_attr_setschedparam(): %s\0A\00"
define void @init_attr(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sched_param
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %7, i32 0, i32 0
%10 = load i32, i32* %6
store i32 %10, i32* %9
%11 = load i32*, i32** %4
%12 = call i32 @pthread_attr_init(i32* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i32, i32* %8
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 2)
unreachable
21: ; preds = %3
%22 = load i32*, i32** %4
%23 = load i32, i32* %5
%24 = call i32 @pthread_attr_setschedpolicy(i32* %22, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i32, i32* %8
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %21
%34 = load i32*, i32** %4
%35 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%36 = call i32 @pthread_attr_setinheritsched(i32* %34, i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = load i32, i32* %8
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 2)
unreachable
45: ; preds = %33
%46 = load i32*, i32** %4
%47 = call i32 @pthread_attr_setschedparam(i32* %46, %struct.sched_param* %7)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = load i32, i32* %8
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 2)
unreachable
56: ; preds = %45
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"pthread_attr_init(): %s\0A\00"
@.str.1 = [30 x i8] c"pthread_setschedpolicy(): %s\0A\00"
@PTHREAD_EXPLICIT_SCHED = global i32 0
@.str.2 = [36 x i8] c"pthread_attr_setinheritsched(): %s\0A\00"
@.str.3 = [34 x i8] c"pthread_attr_setschedparam(): %s\0A\00"
define void @init_attr(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 = tail call i32 @pthread_attr_init(i32* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i8* @strerror(i32 %7)
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 2)
unreachable
14: ; preds = %3
%15 = tail call i32 @pthread_attr_setschedpolicy(i32* %0, i32 %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i8* @strerror(i32 %15)
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 2)
unreachable
22: ; preds = %14
%23 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%24 = tail call i32 @pthread_attr_setinheritsched(i32* %0, i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i8* @strerror(i32 %24)
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = tail call i32 @exit(i32 2)
unreachable
31: ; preds = %22
%32 = call i32 @pthread_attr_setschedparam(i32* %0, %struct.sched_param* %4)
%33 = icmp eq i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i8* @strerror(i32 %32)
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 2)
unreachable
39: ; preds = %31
ret void
}