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

/* Variables and functions */
int /*<<< orphan*/ SCHED_RR;
int /*<<< orphan*/ printf(char *, char *);
int pthread_attr_setschedpolicy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int pthread_attr_setstacksize(int /*<<< orphan*/ *, size_t);
char *strerror(int);
int set_attr(pthread_attr_t *attr, size_t stksize) {
  int r = -1;
  r = pthread_attr_setstacksize(attr, stksize);
  if (r != 0)
    printf("ERROR: failed to set stack size %s\n", strerror(r));
  r = pthread_attr_setschedpolicy(attr, SCHED_RR);
  if (r != 0)
    printf("ERROR: failed to set sched policy %s\n", strerror(r));
  return r;
}


x86 assembly (clang, -O0):
<set_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <pthread_attr_setstacksize@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1188 <set_attr+0x48>
mov    -0x14(%rbp),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11be <set_attr+0x7e>
mov    -0x14(%rbp),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_attr>:
push   %rbx
mov    %rdi,%rbx
call   1060 <pthread_attr_setstacksize@plt>
test   %eax,%eax
je     1163 <set_attr+0x23>
mov    %eax,%edi
call   1050 <strerror@plt>
lea    0xea5(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1190 <set_attr+0x50>
mov    %ebx,%edi
call   1050 <strerror@plt>
lea    0xe9c(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"ERROR: failed to set stack size %s\0A\00"
@SCHED_RR = global i32 0
@.str.1 = [38 x i8] c"ERROR: failed to set sched policy %s\0A\00"
define i32 @set_attr(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
store i32 -1, i32* %5
%6 = load i32*, i32** %3
%7 = load i64, i64* %4
%8 = call i32 @pthread_attr_setstacksize(i32* %6, i64 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* %5
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %11, %2
%16 = load i32*, i32** %3
%17 = load i32, i32* @SCHED_RR
%18 = call i32 @pthread_attr_setschedpolicy(i32* %16, i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32, i32* %5
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %15
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@.str = [36 x i8] c"ERROR: failed to set stack size %s\0A\00"
@SCHED_RR = global i32 0
@.str.1 = [38 x i8] c"ERROR: failed to set sched policy %s\0A\00"
define i32 @set_attr(i32* %0, i64 %1) {
%3 = tail call i32 @pthread_attr_setstacksize(i32* %0, i64 %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i8* @strerror(i32 %3)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %8
8: ; preds = %5, %2
%9 = load i32, i32* @SCHED_RR
%10 = tail call i32 @pthread_attr_setschedpolicy(i32* %0, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = tail call i8* @strerror(i32 %10)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %8
ret i32 %10
}