#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 EPERM;
int /*<<< orphan*/ PTHREAD_EXPLICIT_SCHED;
int /*<<< orphan*/ SCHED_RR;
int errno;
int /*<<< orphan*/ printf(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 /*<<< orphan*/);
int run_threads(int /*<<< orphan*/ *);
char *strerror(int);
int do_sched_test(void) {
  pthread_attr_t attr;
  ({
    int ret = pthread_attr_init(&attr);
    if (ret != 0) {
      printf("%s:%d: %s returned %d (errno = %d)\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/"
             "fbtl/tst-default-attr.c",
             242, "pthread_attr_init", ret, errno);
      return ret;
    }
  });
  ({
    int ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
    if (ret != 0) {
      printf("%s:%d: %s returned %d (errno = %d)\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/"
             "fbtl/tst-default-attr.c",
             247, "pthread_attr_setinheritsched", ret, errno);
      return ret;
    }
  });
  ({
    int ret = pthread_attr_setschedpolicy(&attr, SCHED_RR);
    if (ret != 0) {
      printf("%s:%d: %s returned %d (errno = %d)\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/"
             "fbtl/tst-default-attr.c",
             248, "pthread_attr_setschedpolicy", ret, errno);
      return ret;
    }
  });
  struct sched_param param;
  param.sched_priority = 42;
  ({
    int ret = pthread_attr_setschedparam(&attr, &param);
    if (ret != 0) {
      printf("%s:%d: %s returned %d (errno = %d)\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/"
             "fbtl/tst-default-attr.c",
             252, "pthread_attr_setschedparam", ret, errno);
      return ret;
    }
  });
  int ret = run_threads(&attr);
  if (ret == EPERM) {
    printf("Skipping Scheduler Attributes test: %s\n", strerror(ret));
    return 0;
  } else if (ret != 0)
    return ret;
  return 0;
}


x86 assembly (clang, -O0):
<do_sched_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1060 <pthread_attr_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11c8 <do_sched_test+0x58>
mov    -0xc(%rbp),%r8d
mov    0x2e3f(%rip),%rax
mov    (%rax),%r9d
lea    0xe5d(%rip),%rdi
lea    0xe7a(%rip),%rsi
mov    $0xf2,%edx
lea    0xf03(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <do_sched_test+0x1c9>
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1030 <pthread_attr_setinheritsched@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1221 <do_sched_test+0xb1>
mov    -0x10(%rbp),%r8d
mov    0x2de6(%rip),%rax
mov    (%rax),%r9d
lea    0xe04(%rip),%rdi
lea    0xe21(%rip),%rsi
mov    $0xf7,%edx
lea    0xebc(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <do_sched_test+0x1c9>
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1050 <pthread_attr_setschedpolicy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     127a <do_sched_test+0x10a>
mov    -0x14(%rbp),%r8d
mov    0x2d8d(%rip),%rax
mov    (%rax),%r9d
lea    0xdab(%rip),%rdi
lea    0xdc8(%rip),%rsi
mov    $0xf8,%edx
lea    0xe80(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <do_sched_test+0x1c9>
movl   $0x2a,-0x18(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12d5 <do_sched_test+0x165>
mov    -0x1c(%rbp),%r8d
mov    0x2d32(%rip),%rax
mov    (%rax),%r9d
lea    0xd50(%rip),%rdi
lea    0xd6d(%rip),%rsi
mov    $0xfc,%edx
lea    0xe41(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <do_sched_test+0x1c9>
lea    -0x8(%rbp),%rdi
call   1070 <run_threads@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2cd5(%rip),%rcx
cmp    (%rcx),%eax
jne    1318 <do_sched_test+0x1a8>
mov    -0x20(%rbp),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1339 <do_sched_test+0x1c9>
cmpl   $0x0,-0x20(%rbp)
je     132d <do_sched_test+0x1bd>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <do_sched_test+0x1c9>
jmp    1332 <do_sched_test+0x1c2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_sched_test>:
push   %rbx
sub    $0x10,%rsp
lea    0x4(%rsp),%rdi
call   1060 <pthread_attr_init@plt>
test   %eax,%eax
je     11ae <do_sched_test+0x3e>
mov    %eax,%ebx
mov    0x2e4c(%rip),%rax
mov    (%rax),%r9d
lea    0xe6a(%rip),%rdi
lea    0xe87(%rip),%rsi
lea    0xf15(%rip),%rcx
mov    $0xf2,%edx
jmp    1270 <do_sched_test+0x100>
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1030 <pthread_attr_setinheritsched@plt>
test   %eax,%eax
je     11f0 <do_sched_test+0x80>
mov    %eax,%ebx
mov    0x2e0a(%rip),%rax
mov    (%rax),%r9d
lea    0xe28(%rip),%rdi
lea    0xe45(%rip),%rsi
lea    0xee5(%rip),%rcx
mov    $0xf7,%edx
jmp    1270 <do_sched_test+0x100>
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdi
call   1050 <pthread_attr_setschedpolicy@plt>
test   %eax,%eax
je     122f <do_sched_test+0xbf>
mov    %eax,%ebx
mov    0x2dc8(%rip),%rax
mov    (%rax),%r9d
lea    0xde6(%rip),%rdi
lea    0xe03(%rip),%rsi
lea    0xec0(%rip),%rcx
mov    $0xf8,%edx
jmp    1270 <do_sched_test+0x100>
movl   $0x2a,0x8(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1080 <pthread_attr_setschedparam@plt>
test   %eax,%eax
je     1282 <do_sched_test+0x112>
mov    %eax,%ebx
mov    0x2d85(%rip),%rax
mov    (%rax),%r9d
lea    0xda3(%rip),%rdi
lea    0xdc0(%rip),%rsi
lea    0xe99(%rip),%rcx
mov    $0xfc,%edx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0x4(%rsp),%rdi
call   1070 <run_threads@plt>
mov    %eax,%ebx
mov    0x2d2b(%rip),%rax
cmp    (%rax),%ebx
jne    127a <do_sched_test+0x10a>
mov    %ebx,%edi
call   1090 <strerror@plt>
lea    0xe78(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    127a <do_sched_test+0x10a>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [36 x i8] c"%s:%d: %s returned %d (errno = %d)\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/fbtl/tst-default-attr.c\00"
@.str.2 = [18 x i8] c"pthread_attr_init\00"
@errno = global i32 0
@PTHREAD_EXPLICIT_SCHED = global i32 0
@.str.3 = [29 x i8] c"pthread_attr_setinheritsched\00"
@SCHED_RR = global i32 0
@.str.4 = [28 x i8] c"pthread_attr_setschedpolicy\00"
@.str.5 = [27 x i8] c"pthread_attr_setschedparam\00"
@EPERM = global i32 0
@.str.6 = [40 x i8] c"Skipping Scheduler Attributes test: %s\0A\00"
define i32 @do_sched_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sched_param
%7 = alloca i32
%8 = alloca i32
%9 = call i32 @pthread_attr_init(i32* %2)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = load i32, i32* %3
%14 = load i32, i32* @errno
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 242, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* %3
store i32 %16, i32* %1
br label %63
17: ; preds = %0
%18 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%19 = call i32 @pthread_attr_setinheritsched(i32* %2, i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* %4
%24 = load i32, i32* @errno
%25 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 247, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32, i32* %4
store i32 %26, i32* %1
br label %63
27: ; preds = %17
%28 = load i32, i32* @SCHED_RR
%29 = call i32 @pthread_attr_setschedpolicy(i32* %2, i32 %28)
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* %5
%34 = load i32, i32* @errno
%35 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 248, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %33, i32 %34)
%36 = load i32, i32* %5
store i32 %36, i32* %1
br label %63
37: ; preds = %27
%38 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %6, i32 0, i32 0
store i32 42, i32* %38
%39 = call i32 @pthread_attr_setschedparam(i32* %2, %struct.sched_param* %6)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i32, i32* %7
%44 = load i32, i32* @errno
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 252, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %43, i32 %44)
%46 = load i32, i32* %7
store i32 %46, i32* %1
br label %63
47: ; preds = %37
%48 = call i32 @run_threads(i32* %2)
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = load i32, i32* @EPERM
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32, i32* %8
%54 = call i8* @strerror(i32 %53)
%55 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %54)
store i32 0, i32* %1
br label %63
56: ; preds = %47
%57 = load i32, i32* %8
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = load i32, i32* %8
store i32 %60, i32* %1
br label %63
61: ; preds = %56
br label %62
62: ; preds = %61
store i32 0, i32* %1
br label %63
63: ; preds = %62, %59, %52, %42, %32, %22, %12
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [36 x i8] c"%s:%d: %s returned %d (errno = %d)\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Boshin/workspace/refs/heads/master/fbtl/tst-default-attr.c\00"
@.str.2 = [18 x i8] c"pthread_attr_init\00"
@errno = global i32 0
@PTHREAD_EXPLICIT_SCHED = global i32 0
@.str.3 = [29 x i8] c"pthread_attr_setinheritsched\00"
@SCHED_RR = global i32 0
@.str.4 = [28 x i8] c"pthread_attr_setschedpolicy\00"
@.str.5 = [27 x i8] c"pthread_attr_setschedparam\00"
@EPERM = global i32 0
@.str.6 = [40 x i8] c"Skipping Scheduler Attributes test: %s\0A\00"
define i32 @do_sched_test() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = bitcast i32* %1 to i8*
%4 = call i32 @pthread_attr_init(i32* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 242, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %7)
br label %40
9: ; preds = %0
%10 = load i32, i32* @PTHREAD_EXPLICIT_SCHED
%11 = call i32 @pthread_attr_setinheritsched(i32* %1, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i32, i32* @errno
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 247, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %14)
br label %40
16: ; preds = %9
%17 = load i32, i32* @SCHED_RR
%18 = call i32 @pthread_attr_setschedpolicy(i32* %1, i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i32, i32* @errno
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 248, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %18, i32 %21)
br label %40
23: ; preds = %16
%24 = bitcast %struct.sched_param* %2 to i8*
%25 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 42, i32* %25
%26 = call i32 @pthread_attr_setschedparam(i32* %1, %struct.sched_param* %2)
%27 = icmp eq i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = load i32, i32* @errno
%30 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 252, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %26, i32 %29)
br label %38
31: ; preds = %23
%32 = call i32 @run_threads(i32* %1)
%33 = load i32, i32* @EPERM
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i8* @strerror(i32 %32)
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %31, %28, %35
%39 = phi i32 [ %26, %28 ], [ 0, %35 ], [ %32, %31 ]
br label %40
40: ; preds = %20, %13, %6, %38
%41 = phi i32 [ %39, %38 ], [ %18, %20 ], [ %11, %13 ], [ %4, %6 ]
ret i32 %41
}