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

/* Variables and functions */
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ SCHED_OTHER;
int /*<<< orphan*/ printf(char *);
int sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                       struct sched_param *);
void gpio_setrealtimesched(int enable) {
  if (enable) {
    struct sched_param sp = {32};
    int err = sched_setscheduler(0, SCHED_FIFO, &sp);
    if (err != 0) {
      printf("could not switch to realtime prio: %m\n");
    }
  } else {
    struct sched_param sp = {0};
    int err = sched_setscheduler(0, SCHED_OTHER, &sp);
    if (err != 0) {
      printf("could not switch back to normal prio: %m\n");
    }
  }
}


x86 assembly (clang, -O0):
<gpio_setrealtimesched>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1180 <gpio_setrealtimesched+0x50>
mov    0xeb5(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117b <gpio_setrealtimesched+0x4b>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
jmp    11c2 <gpio_setrealtimesched+0x92>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11bd <gpio_setrealtimesched+0x8d>
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
jmp    11c2 <gpio_setrealtimesched+0x92>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_setrealtimesched>:
sub    $0x18,%rsp
test   %edi,%edi
je     1152 <gpio_setrealtimesched+0x32>
movl   $0x20,0x10(%rsp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
xor    %edi,%edi
call   1040 <sched_setscheduler@plt>
test   %eax,%eax
je     117f <gpio_setrealtimesched+0x5f>
lea    0xeb0(%rip),%rdi
jmp    117a <gpio_setrealtimesched+0x5a>
movl   $0x0,0x8(%rsp)
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1040 <sched_setscheduler@plt>
test   %eax,%eax
je     117f <gpio_setrealtimesched+0x5f>
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@__const.gpio_setrealtimesched.sp = %struct.sched_param { i32 32 }
@SCHED_FIFO = global i32 0
@.str = [39 x i8] c"could not switch to realtime prio: %m\0A\00"
@SCHED_OTHER = global i32 0
@.str.1 = [42 x i8] c"could not switch back to normal prio: %m\0A\00"
define void @gpio_setrealtimesched(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sched_param
%4 = alloca i32
%5 = alloca %struct.sched_param
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = bitcast %struct.sched_param* %3 to i8*
%11 = load i32, i32* @SCHED_FIFO
%12 = call i32 @sched_setscheduler(i32 0, i32 %11, %struct.sched_param* %3)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
br label %27
18: ; preds = %1
%19 = bitcast %struct.sched_param* %5 to i8*
%20 = load i32, i32* @SCHED_OTHER
%21 = call i32 @sched_setscheduler(i32 0, i32 %20, %struct.sched_param* %5)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %18
br label %27
27: ; preds = %26, %17
ret void
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@SCHED_FIFO = global i32 0
@.str = [39 x i8] c"could not switch to realtime prio: %m\0A\00"
@SCHED_OTHER = global i32 0
@.str.1 = [42 x i8] c"could not switch back to normal prio: %m\0A\00"
define void @gpio_setrealtimesched(i32 %0) {
%2 = alloca %struct.sched_param
%3 = alloca %struct.sched_param
%4 = icmp eq i32 %0, 0
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = bitcast %struct.sched_param* %2 to i8*
%7 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i64 0, i32 0
store i32 32, i32* %7
%8 = load i32, i32* @SCHED_FIFO
%9 = call i32 @sched_setscheduler(i32 0, i32 %8, %struct.sched_param* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %5
br label %23
14: ; preds = %1
%15 = bitcast %struct.sched_param* %3 to i8*
%16 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
store i32 0, i32* %16
%17 = load i32, i32* @SCHED_OTHER
%18 = call i32 @sched_setscheduler(i32 0, i32 %17, %struct.sched_param* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %14
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
br label %23
23: ; preds = %22, %13
ret void
}