#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__ EINVAL;
int SCHED_FIFO;
int SCHED_OTHER;
int SCHED_RR;
scalar_t__ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int test_min_max(int (*func)(int), const char *func_name) {
  int prio;
  printf("Test %s() (SCHED_OTHER)...", func_name);
  prio = func(SCHED_OTHER);
  if (prio >= 0) {
    printf("passed\n");
  } else {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  printf("Test %s() (SCHED_FIFO)...", func_name);
  prio = func(SCHED_FIFO);
  if (prio >= 0) {
    printf("%d...passed\n", prio);
  } else {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  printf("Test %s() (SCHED_RR)...", func_name);
  prio = func(SCHED_RR);
  if (prio >= 0) {
    printf("%d...passed\n", prio);
  } else {
    fflush(stdout);
    perror("failed");
    return -1;
  }
  printf("Test %s() (EINVAL)...", func_name);
  prio = func(100);
  if (prio >= 0) {
    printf("failed (should have returned -1 not %d)\n", prio);
  } else {
    if (errno == EINVAL) {
      errno = 0;
      printf("passed\n");
    } else {
      fflush(stdout);
      perror("Should have faile with EINVAL");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_min_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x2e7b(%rip),%rcx
mov    (%rcx),%edi
call   *%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1181 <test_min_max+0x51>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a7 <test_min_max+0x77>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xe85(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <test_min_max+0x1f5>
mov    -0x18(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x2e24(%rip),%rcx
mov    (%rcx),%edi
call   *%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11eb <test_min_max+0xbb>
mov    -0x1c(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1211 <test_min_max+0xe1>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xe1b(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <test_min_max+0x1f5>
mov    -0x18(%rbp),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x2d82(%rip),%rcx
mov    (%rcx),%edi
call   *%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1255 <test_min_max+0x125>
mov    -0x1c(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127b <test_min_max+0x14b>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xdb1(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <test_min_max+0x1f5>
mov    -0x18(%rbp),%rsi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x64,%edi
call   *-0x10(%rbp)
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     12b8 <test_min_max+0x188>
mov    -0x1c(%rbp),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131e <test_min_max+0x1ee>
mov    0x2d11(%rip),%rax
mov    (%rax),%rax
mov    0x2cff(%rip),%rcx
cmp    (%rcx),%rax
jne    12f3 <test_min_max+0x1c3>
mov    0x2cf7(%rip),%rax
movq   $0x0,(%rax)
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1319 <test_min_max+0x1e9>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xd98(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1325 <test_min_max+0x1f5>
jmp    131e <test_min_max+0x1ee>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_min_max>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   *%r14
test   %eax,%eax
js     123c <test_min_max+0xfc>
lea    0xf4b(%rip),%rdi
call   1030 <puts@plt>
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   *%r14
test   %eax,%eax
js     123c <test_min_max+0xfc>
lea    0xe98(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   *%r14
test   %eax,%eax
js     123c <test_min_max+0xfc>
lea    0xe67(%rip),%rdi
xor    %ebp,%ebp
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x64,%edi
call   *%r14
test   %eax,%eax
js     120f <test_min_max+0xcf>
lea    0xe73(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    125b <test_min_max+0x11b>
mov    0x2dba(%rip),%rax
mov    (%rax),%rcx
mov    0x2da8(%rip),%rdx
cmp    (%rdx),%rcx
jne    1262 <test_min_max+0x122>
movq   $0x0,(%rax)
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    125b <test_min_max+0x11b>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xdca(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xe29(%rip),%rdi
jmp    1251 <test_min_max+0x111>

LLVM IR (-O0):
@.str = [27 x i8] c"Test %s() (SCHED_OTHER)...\00"
@SCHED_OTHER = global i32 0
@.str.1 = [8 x i8] c"passed\0A\00"
@stdout = global i32 0
@.str.2 = [7 x i8] c"failed\00"
@.str.3 = [26 x i8] c"Test %s() (SCHED_FIFO)...\00"
@SCHED_FIFO = global i32 0
@.str.4 = [13 x i8] c"%d...passed\0A\00"
@.str.5 = [24 x i8] c"Test %s() (SCHED_RR)...\00"
@SCHED_RR = global i32 0
@.str.6 = [22 x i8] c"Test %s() (EINVAL)...\00"
@.str.7 = [41 x i8] c"failed (should have returned -1 not %d)\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.8 = [30 x i8] c"Should have faile with EINVAL\00"
define i32 @test_min_max(i32 (i32)* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32 (i32)*
%5 = alloca i8*
%6 = alloca i32
store i32 (i32)* %0, i32 (i32)** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32 (i32)*, i32 (i32)** %4
%10 = load i32, i32* @SCHED_OTHER
%11 = call i32 %9(i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %20
16: ; preds = %2
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %72
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i32 (i32)*, i32 (i32)** %4
%24 = load i32, i32* @SCHED_FIFO
%25 = call i32 %23(i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i32, i32* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %35
31: ; preds = %20
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %72
35: ; preds = %28
%36 = load i8*, i8** %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %36)
%38 = load i32 (i32)*, i32 (i32)** %4
%39 = load i32, i32* @SCHED_RR
%40 = call i32 %38(i32 %39)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = load i32, i32* %6
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %50
46: ; preds = %35
%47 = load i32, i32* @stdout
%48 = call i32 @fflush(i32 %47)
%49 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %72
50: ; preds = %43
%51 = load i8*, i8** %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %51)
%53 = load i32 (i32)*, i32 (i32)** %4
%54 = call i32 %53(i32 100)
store i32 %54, i32* %6
%55 = load i32, i32* %6
%56 = icmp sge i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = load i32, i32* %6
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %58)
br label %71
60: ; preds = %50
%61 = load i64, i64* @errno
%62 = load i64, i64* @EINVAL
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %66
64: ; preds = %60
store i64 0, i64* @errno
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %70
66: ; preds = %60
%67 = load i32, i32* @stdout
%68 = call i32 @fflush(i32 %67)
%69 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %72
70: ; preds = %64
br label %71
71: ; preds = %70, %57
store i32 0, i32* %3
br label %72
72: ; preds = %71, %66, %46, %31, %16
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [27 x i8] c"Test %s() (SCHED_OTHER)...\00"
@SCHED_OTHER = global i32 0
@stdout = global i32 0
@.str.2 = [7 x i8] c"failed\00"
@.str.3 = [26 x i8] c"Test %s() (SCHED_FIFO)...\00"
@SCHED_FIFO = global i32 0
@.str.4 = [13 x i8] c"%d...passed\0A\00"
@.str.5 = [24 x i8] c"Test %s() (SCHED_RR)...\00"
@SCHED_RR = global i32 0
@.str.6 = [22 x i8] c"Test %s() (EINVAL)...\00"
@.str.7 = [41 x i8] c"failed (should have returned -1 not %d)\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.8 = [30 x i8] c"Should have faile with EINVAL\00"
@str.9 = [7 x i8] c"passed\00"
define i32 @test_min_max(i32 (i32)* nocapture %0, i8* %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %1)
%4 = load i32, i32* @SCHED_OTHER
%5 = tail call i32 %0(i32 %4)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.9, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%10 = load i32, i32* @SCHED_FIFO
%11 = tail call i32 %0(i32 %10)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %17, label %23
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = tail call i32 @fflush(i32 %14)
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %48
17: ; preds = %7
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %1)
%20 = load i32, i32* @SCHED_RR
%21 = tail call i32 %0(i32 %20)
%22 = icmp sgt i32 %21, -1
br i1 %22, label %27, label %32
23: ; preds = %7
%24 = load i32, i32* @stdout
%25 = tail call i32 @fflush(i32 %24)
%26 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %48
27: ; preds = %17
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %1)
%30 = tail call i32 %0(i32 100)
%31 = icmp sgt i32 %30, -1
br i1 %31, label %36, label %38
32: ; preds = %17
%33 = load i32, i32* @stdout
%34 = tail call i32 @fflush(i32 %33)
%35 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %48
36: ; preds = %27
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %30)
br label %48
38: ; preds = %27
%39 = load i64, i64* @errno
%40 = load i64, i64* @EINVAL
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38
store i64 0, i64* @errno
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.9, i64 0, i64 0))
br label %48
44: ; preds = %38
%45 = load i32, i32* @stdout
%46 = tail call i32 @fflush(i32 %45)
%47 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
br label %48
48: ; preds = %36, %42, %44, %32, %23, %13
%49 = phi i32 [ -1, %44 ], [ -1, %32 ], [ -1, %23 ], [ -1, %13 ], [ 0, %42 ], [ 0, %36 ]
ret i32 %49
}