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

/* Variables and functions */
scalar_t__ EPERM;
scalar_t__ errno;
scalar_t__ geteuid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sched_getparam(int, struct sched_param *);
scalar_t__ set_nonroot();
int main(void) {
  struct sched_param param;
  int result = -1;
  if (geteuid() == 0) {
    if (set_nonroot() != 0) {
      printf("Cannot run this test as non-root user\n");
      return 5;
    }
  }
  result = sched_getparam(1, &param);
  if (result == -1 && errno == EPERM) {
    printf("Test PASS\n");
    return 0;
  }
  if (result == 0) {
    printf("The function sched_getparam has successed.\n");
    return 5;
  }
  if (errno != EPERM) {
    perror("errno is not EPERM: The system allows a non-root"
           "user to use sched_getparam()");
    return 2;
  } else {
    perror("Unresolved test error");
    return 2;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
cmp    $0x0,%rax
jne    11a5 <main+0x55>
mov    $0x0,%al
call   1060 <set_nonroot@plt>
cmp    $0x0,%rax
je     11a0 <main+0x50>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    1259 <main+0x109>
jmp    11a5 <main+0x55>
mov    $0x1,%edi
lea    -0x8(%rbp),%rsi
call   1040 <sched_getparam@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11f2 <main+0xa2>
mov    0x2e19(%rip),%rax
mov    (%rax),%rax
mov    0x2dff(%rip),%rcx
cmp    (%rcx),%rax
jne    11f2 <main+0xa2>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1259 <main+0x109>
cmpl   $0x0,-0xc(%rbp)
jne    1214 <main+0xc4>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    1259 <main+0x109>
mov    0x2dc5(%rip),%rax
mov    (%rax),%rax
mov    0x2dab(%rip),%rcx
cmp    (%rcx),%rax
je     1246 <main+0xf6>
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1259 <main+0x109>
lea    0xe5e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <geteuid@plt>
test   %rax,%rax
je     117c <main+0x2c>
mov    %rsp,%rsi
mov    $0x1,%edi
call   1040 <sched_getparam@plt>
cmp    $0xffffffff,%eax
je     119b <main+0x4b>
test   %eax,%eax
jne    11c4 <main+0x74>
lea    0xee9(%rip),%rdi
jmp    118f <main+0x3f>
xor    %eax,%eax
call   1060 <set_nonroot@plt>
test   %rax,%rax
je     115d <main+0xd>
lea    0xf09(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%eax
pop    %rcx
ret
mov    0x2e3e(%rip),%rax
mov    (%rax),%rax
mov    0x2e24(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
jne    11d8 <main+0x88>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e15(%rip),%rax
mov    (%rax),%rax
mov    0x2dfb(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
jne    11e6 <main+0x96>
lea    0xe69(%rip),%rdi
jmp    11ed <main+0x9d>
lea    0xe13(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [39 x i8] c"Cannot run this test as non-root user\0A\00"
@errno = global i64 0
@EPERM = global i64 0
@.str.1 = [11 x i8] c"Test PASS\0A\00"
@.str.2 = [44 x i8] c"The function sched_getparam has successed.\0A\00"
@.str.3 = [77 x i8] c"errno is not EPERM: The system allows a non-rootuser to use sched_getparam()\00"
@.str.4 = [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 = call i64 (...) @geteuid()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = call i64 (...) @set_nonroot()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 5, i32* %1
br label %35
11: ; preds = %6
br label %12
12: ; preds = %11, %0
%13 = call i32 @sched_getparam(i32 1, %struct.sched_param* %2)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i64, i64* @errno
%18 = load i64, i64* @EPERM
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %35
22: ; preds = %16, %12
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 5, i32* %1
br label %35
27: ; preds = %22
%28 = load i64, i64* @errno
%29 = load i64, i64* @EPERM
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %1
br label %35
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %1
br label %35
35: ; preds = %33, %31, %25, %20, %9
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@errno = global i64 0
@EPERM = global i64 0
@.str.3 = [77 x i8] c"errno is not EPERM: The system allows a non-rootuser to use sched_getparam()\00"
@.str.4 = [22 x i8] c"Unresolved test error\00"
@str = [43 x i8] c"The function sched_getparam has successed.\00"
@str.5 = [10 x i8] c"Test PASS\00"
@str.6 = [38 x i8] c"Cannot run this test as non-root user\00"
define i32 @main() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = tail call i64 (...) @geteuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = tail call i64 (...) @set_nonroot()
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.6, i64 0, i64 0))
br label %31
10: ; preds = %5, %0
%11 = call i32 @sched_getparam(i32 1, %struct.sched_param* %1)
switch i32 %11, label %12 [
i32 -1, label %15
i32 0, label %21
]
12: ; preds = %10
%13 = load i64, i64* @errno
%14 = load i64, i64* @EPERM
br label %23
15: ; preds = %10
%16 = load i64, i64* @errno
%17 = load i64, i64* @EPERM
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0))
br label %31
21: ; preds = %10
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %31
23: ; preds = %12, %15
%24 = phi i64 [ %14, %12 ], [ %17, %15 ]
%25 = phi i64 [ %13, %12 ], [ %16, %15 ]
%26 = icmp eq i64 %25, %24
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.3, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %27, %21, %19, %8
%32 = phi i32 [ 5, %8 ], [ 0, %19 ], [ 5, %21 ], [ 2, %27 ], [ 2, %29 ]
ret i32 %32
}