#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*/ 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(0, &param);
  if (result == 0 && param.sched_priority != -1 && errno == 0) {
    printf("Test PASSED\n");
    return 0;
  }
  if (errno != 0) {
    perror("Unexpected error");
    return 1;
  }
  if (result != 0) {
    printf("returned code is not zero.\n");
    return 1;
  } else {
    perror("Unresolved test error");
    return 2;
  }
  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)
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1040 <sched_getparam@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1198 <main+0x68>
cmpl   $0xffffffff,-0x8(%rbp)
je     1198 <main+0x68>
mov    0x2e6a(%rip),%rax
cmpq   $0x0,(%rax)
jne    1198 <main+0x68>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <main+0xc6>
mov    0x2e41(%rip),%rax
cmpq   $0x0,(%rax)
je     11c1 <main+0x91>
lea    0xe5d(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f6 <main+0xc6>
cmpl   $0x0,-0xc(%rbp)
je     11e3 <main+0xb3>
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f6 <main+0xc6>
lea    0xe50(%rip),%rdi
call   1050 <perror@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)
mov    %rsp,%rsi
xor    %edi,%edi
call   1040 <sched_getparam@plt>
mov    0x2e97(%rip),%rcx
mov    (%rcx),%rcx
test   %eax,%eax
jne    116b <main+0x3b>
cmpl   $0xffffffff,(%rsp)
je     116b <main+0x3b>
test   %rcx,%rcx
jne    116b <main+0x3b>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
test   %rcx,%rcx
jne    1187 <main+0x57>
test   %eax,%eax
je     1195 <main+0x65>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xe72(%rip),%rdi
call   1050 <perror@plt>
jmp    1180 <main+0x50>
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@errno = global i64 0
@.str = [13 x i8] c"Test PASSED\0A\00"
@.str.1 = [17 x i8] c"Unexpected error\00"
@.str.2 = [28 x i8] c"returned code is not zero.\0A\00"
@.str.3 = [22 x i8] c"Unresolved test error\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 @sched_getparam(i32 0, %struct.sched_param* %2)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %0
%9 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i64, i64* @errno
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %29
17: ; preds = %12, %8, %0
%18 = load i64, i64* @errno
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %29
22: ; preds = %17
%23 = load i32, i32* %3
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %29
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %1
br label %29
29: ; preds = %27, %25, %20, %15
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@errno = global i64 0
@.str.1 = [17 x i8] c"Unexpected error\00"
@.str.3 = [22 x i8] c"Unresolved test error\00"
@str = [27 x i8] c"returned code is not zero.\00"
@str.4 = [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 = call i32 @sched_getparam(i32 0, %struct.sched_param* %1)
%5 = icmp eq i32 %4, 0
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, -1
%8 = select i1 %5, i1 %7, i1 false
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
br label %22
14: ; preds = %0
br i1 %10, label %17, label %15
15: ; preds = %14
%16 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %22
17: ; preds = %14
br i1 %5, label %20, label %18
18: ; preds = %17
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %22
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %18, %15, %12
%23 = phi i32 [ 0, %12 ], [ 1, %15 ], [ 1, %18 ], [ 2, %20 ]
ret i32 %23
}