#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*/ printf(char *, char *, char *, char *, int);
int /*<<< orphan*/ pthread_attr_destroy(int /*<<< orphan*/ *);
int pthread_attr_init(int /*<<< orphan*/ *);
int pthread_attr_setschedpolicy(int /*<<< orphan*/ *, int);
char *strerror(int);
int set_policy(char *label, int policy) {
  int rc;
  int status;
  pthread_attr_t attr;
  rc = pthread_attr_init(&attr);
  if (rc) {
    printf("Failed: %s function: %s error: %s (%u)\n", "",
           "pthread_attr_init()", strerror(rc), rc);
    return 2;
  }
  status = 0;
  rc = pthread_attr_setschedpolicy(&attr, policy);
  if (rc) {
    printf("Failed: %s function: %s error: %s (%u)\n", label,
           "pthread_attr_setschedpolicy()", strerror(rc), rc);
    status = 1;
  }
  (void)pthread_attr_destroy(&attr);
  return status;
}


x86 assembly (clang, -O0):
<set_policy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <pthread_attr_init@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11aa <set_policy+0x5a>
mov    -0x18(%rbp),%edi
call   1070 <strerror@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%r8d
lea    0xe75(%rip),%rdi
lea    0xe95(%rip),%rsi
lea    0xe8f(%rip),%rdx
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    120e <set_policy+0xbe>
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   1040 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11ff <set_policy+0xaf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rcx
mov    -0x18(%rbp),%r8d
lea    0xe14(%rip),%rdi
lea    0xe49(%rip),%rdx
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <pthread_attr_destroy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_policy>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xc(%rsp),%rdi
call   1050 <pthread_attr_init@plt>
test   %eax,%eax
je     119b <set_policy+0x4b>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <strerror@plt>
lea    0xe85(%rip),%rdi
lea    0xea5(%rip),%rsi
lea    0xe9f(%rip),%rdx
mov    %rax,%rcx
mov    %ebp,%r8d
call   1030 <printf@plt>
mov    $0x2,%ebx
jmp    11e3 <set_policy+0x93>
lea    0xc(%rsp),%rdi
mov    %ebx,%esi
call   1040 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
je     11d7 <set_policy+0x87>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <strerror@plt>
lea    0xe45(%rip),%rdi
lea    0xe7a(%rip),%rdx
mov    %r14,%rsi
mov    %rax,%rcx
mov    %ebp,%r8d
call   1030 <printf@plt>
mov    $0x1,%ebx
jmp    11d9 <set_policy+0x89>
xor    %ebx,%ebx
lea    0xc(%rsp),%rdi
call   1060 <pthread_attr_destroy@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Failed: %s function: %s error: %s (%u)\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [20 x i8] c"pthread_attr_init()\00"
@.str.3 = [30 x i8] c"pthread_attr_setschedpolicy()\00"
define i32 @set_policy(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = call i32 @pthread_attr_init(i32* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* %6
%14 = call i8* @strerror(i32 %13)
%15 = load i32, i32* %6
%16 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 %15)
store i32 2, i32* %3
br label %31
17: ; preds = %2
store i32 0, i32* %7
%18 = load i32, i32* %5
%19 = call i32 @pthread_attr_setschedpolicy(i32* %8, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = load i32, i32* %6
%25 = call i8* @strerror(i32 %24)
%26 = load i32, i32* %6
%27 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %25, i32 %26)
store i32 1, i32* %7
br label %28
28: ; preds = %22, %17
%29 = call i32 @pthread_attr_destroy(i32* %8)
%30 = load i32, i32* %7
store i32 %30, i32* %3
br label %31
31: ; preds = %28, %12
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [40 x i8] c"Failed: %s function: %s error: %s (%u)\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [20 x i8] c"pthread_attr_init()\00"
@.str.3 = [30 x i8] c"pthread_attr_setschedpolicy()\00"
define i32 @set_policy(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @pthread_attr_init(i32* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i8* @strerror(i32 %5)
%9 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %8, i32 %5)
br label %19
10: ; preds = %2
%11 = call i32 @pthread_attr_setschedpolicy(i32* %3, i32 %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = call i8* @strerror(i32 %11)
%15 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %14, i32 %11)
br label %16
16: ; preds = %13, %10
%17 = phi i32 [ 1, %13 ], [ 0, %10 ]
%18 = call i32 @pthread_attr_destroy(i32* %3)
br label %19
19: ; preds = %16, %7
%20 = phi i32 [ 2, %7 ], [ %17, %16 ]
ret i32 %20
}