#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 */

/* Variables and functions */
scalar_t__ EPERM;
scalar_t__ errno;
scalar_t__ getuid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sched_getscheduler(int);
scalar_t__ set_nonroot();
int main(void) {
  int result = -1;
  if (getuid() == 0) {
    if (set_nonroot() != 0) {
      printf("Cannot run this test as non-root user\n");
      return 5;
    }
  }
  result = sched_getscheduler(1);
  if (result == -1 && errno == EPERM) {
    printf("Test PASSED\n");
    return 0;
  }
  if (result == 0) {
    printf("The function sched_getscheduler has successed.\n");
    return 5;
  }
  if (errno != EPERM) {
    perror("errno is not EPERM");
    return 1;
  } 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,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getuid@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   1050 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    1255 <main+0x105>
jmp    11a5 <main+0x55>
mov    $0x1,%edi
call   1030 <sched_getscheduler@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11ee <main+0x9e>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rax
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
jne    11ee <main+0x9e>
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <main+0x105>
cmpl   $0x0,-0x8(%rbp)
jne    1210 <main+0xc0>
lea    0xe35(%rip),%rdi
call   1050 <printf@plt>
movl   $0x5,-0x4(%rbp)
jmp    1255 <main+0x105>
mov    0x2dc9(%rip),%rax
mov    (%rax),%rax
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%rax
je     1242 <main+0xf2>
lea    0xe33(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1255 <main+0x105>
lea    0xe2e(%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 <getuid@plt>
test   %rax,%rax
je     1179 <main+0x29>
mov    $0x1,%edi
call   1030 <sched_getscheduler@plt>
cmp    $0xffffffff,%eax
je     1198 <main+0x48>
test   %eax,%eax
jne    11c1 <main+0x71>
lea    0xeb2(%rip),%rdi
jmp    118c <main+0x3c>
xor    %eax,%eax
call   1060 <set_nonroot@plt>
test   %rax,%rax
je     115d <main+0xd>
lea    0xed8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x5,%eax
pop    %rcx
ret
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    0x2e27(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
jne    11d5 <main+0x85>
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e18(%rip),%rax
mov    (%rax),%rax
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
jne    11ed <main+0x9d>
lea    0xe32(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret
lea    0xe0c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.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 = [13 x i8] c"Test PASSED\0A\00"
@.str.2 = [48 x i8] c"The function sched_getscheduler has successed.\0A\00"
@.str.3 = [19 x i8] c"errno is not EPERM\00"
@.str.4 = [22 x i8] c"Unresolved test error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
%3 = call i64 (...) @getuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = call i64 (...) @set_nonroot()
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 5, i32* %1
br label %34
10: ; preds = %5
br label %11
11: ; preds = %10, %0
%12 = call i32 @sched_getscheduler(i32 1)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i64, i64* @errno
%17 = load i64, i64* @EPERM
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %34
21: ; preds = %15, %11
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
store i32 5, i32* %1
br label %34
26: ; preds = %21
%27 = load i64, i64* @errno
%28 = load i64, i64* @EPERM
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %34
32: ; preds = %26
%33 = 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 %34
34: ; preds = %32, %30, %24, %19, %8
%35 = load i32, i32* %1
ret i32 %35
}

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