#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;
};

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sched_getparam(int /*<<< orphan*/, struct sched_param *);
int main(void) {
  struct sched_param param;
  int result = -1;
  param.sched_priority = -1;
  result = sched_getparam(getpid(), &param);
  if (result == 0 && param.sched_priority != -1 && errno == 0) {
    printf("Test PASSED\n");
    return 0;
  }
  if (result != 0) {
    printf("Return code is not zero.\n");
    return 1;
  }
  if (errno != 0) {
    perror("Unexpected error");
    return 1;
  }
  if (param.sched_priority == -1) {
    printf("The 'sched_priority' member does not change.\n");
    return 1;
  }
  printf("This code should not be executed.\n");
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0xffffffff,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
call   1050 <sched_getparam@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11af <main+0x6f>
cmpl   $0xffffffff,-0x8(%rbp)
je     11af <main+0x6f>
mov    0x2e53(%rip),%rax
cmpq   $0x0,(%rax)
jne    11af <main+0x6f>
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    122f <main+0xef>
cmpl   $0x0,-0xc(%rbp)
je     11d1 <main+0x91>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xef>
mov    0x2e08(%rip),%rax
cmpq   $0x0,(%rax)
je     11fa <main+0xba>
lea    0xe3e(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xef>
cmpl   $0xffffffff,-0x8(%rbp)
jne    121c <main+0xdc>
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122f <main+0xef>
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0xffffffff,(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <sched_getparam@plt>
mov    (%rsp),%ecx
mov    0x2e7d(%rip),%rdx
mov    (%rdx),%rdx
test   %eax,%eax
jne    1184 <main+0x44>
cmp    $0xffffffff,%ecx
je     1184 <main+0x44>
test   %rdx,%rdx
jne    1184 <main+0x44>
lea    0xefe(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
test   %eax,%eax
je     119b <main+0x5b>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
test   %rdx,%rdx
jne    11c1 <main+0x81>
cmp    $0xffffffff,%ecx
je     11b8 <main+0x78>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
pop    %rcx
ret
lea    0xe74(%rip),%rdi
jmp    118f <main+0x4f>
lea    0xe38(%rip),%rdi
call   1060 <perror@plt>
jmp    1194 <main+0x54>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@errno = global i64 0
@.str = [13 x i8] c"Test PASSED\0A\00"
@.str.1 = [26 x i8] c"Return code is not zero.\0A\00"
@.str.2 = [17 x i8] c"Unexpected error\00"
@.str.3 = [46 x i8] c"The 'sched_priority' member does not change.\0A\00"
@.str.4 = [35 x i8] c"This code should not be executed.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %3
%4 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
store i32 -1, i32* %4
%5 = call i32 (...) @getpid()
%6 = call i32 @sched_getparam(i32 %5, %struct.sched_param* %2)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %0
%10 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
%11 = load i32, i32* %10
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i64, i64* @errno
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %36
18: ; preds = %13, %9, %0
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %36
23: ; preds = %18
%24 = load i64, i64* @errno
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %36
28: ; preds = %23
%29 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %36
34: ; preds = %28
%35 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %1
br label %36
36: ; preds = %34, %32, %26, %21, %16
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@errno = global i64 0
@.str.2 = [17 x i8] c"Unexpected error\00"
@str = [34 x i8] c"This code should not be executed.\00"
@str.5 = [45 x i8] c"The 'sched_priority' member does not change.\00"
@str.6 = [25 x i8] c"Return code is not zero.\00"
@str.7 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i32 -1, i32* %3
%4 = tail call i32 (...) @getpid()
%5 = call i32 @sched_getparam(i32 %4, %struct.sched_param* %1)
%6 = icmp eq i32 %5, 0
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, -1
%9 = select i1 %6, i1 %8, i1 false
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
br label %27
15: ; preds = %0
br i1 %6, label %18, label %16
16: ; preds = %15
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
br label %27
18: ; preds = %15
br i1 %11, label %21, label %19
19: ; preds = %18
%20 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %27
21: ; preds = %18
%22 = icmp eq i32 %7, -1
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.5, i64 0, i64 0))
br label %27
25: ; preds = %21
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %25, %23, %19, %16, %13
%28 = phi i32 [ 0, %13 ], [ 1, %16 ], [ 1, %19 ], [ 1, %23 ], [ 2, %25 ]
ret i32 %28
}