#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 rlimit {
  int rlim_cur;
  int rlim_max;
};

/* Variables and functions */
int EACCES;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ RLIMIT_RTPRIO;
int /*<<< orphan*/ errno;
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int cras_set_rt_scheduling(int rt_lim) {
  struct rlimit rl;
  rl.rlim_cur = rl.rlim_max = rt_lim;
  if (setrlimit(RLIMIT_RTPRIO, &rl) < 0) {
    syslog(LOG_WARNING, "setrlimit %u failed: %d\n", (unsigned)rt_lim, errno);
    return -EACCES;
  }
  syslog(LOG_INFO, "set rlimit success\n");
  return 0;
}


x86 assembly (clang, -O0):
<cras_set_rt_scheduling>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
jge    1186 <cras_set_rt_scheduling+0x66>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    0x2e65(%rip),%rax
mov    (%rax),%ecx
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1030 <syslog@plt>
xor    %eax,%eax
mov    0x2e64(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <cras_set_rt_scheduling+0x84>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1030 <syslog@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cras_set_rt_scheduling>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %edi,0x4(%rsp)
mov    %edi,(%rsp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
js     115d <cras_set_rt_scheduling+0x3d>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xec7(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <syslog@plt>
jmp    118a <cras_set_rt_scheduling+0x6a>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%ecx
lea    0xe8a(%rip),%rsi
xor    %ebp,%ebp
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <syslog@plt>
mov    0x2e58(%rip),%rax
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIMIT_RTPRIO = global i32 0
@LOG_WARNING = global i32 0
@.str = [25 x i8] c"setrlimit %u failed: %d\0A\00"
@errno = global i32 0
@EACCES = global i32 0
@LOG_INFO = global i32 0
@.str.1 = [20 x i8] c"set rlimit success\0A\00"
define i32 @cras_set_rt_scheduling(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.rlimit
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i32 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i32 0, i32 0
store i32 %5, i32* %7
%8 = load i32, i32* @RLIMIT_RTPRIO
%9 = call i64 @setrlimit(i32 %8, %struct.rlimit* %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %1
%12 = load i32, i32* @LOG_WARNING
%13 = load i32, i32* %3
%14 = load i32, i32* @errno
%15 = call i32 (i32, i8*, ...) @syslog(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* @EACCES
%17 = sub nsw i32 0, %16
store i32 %17, i32* %2
br label %21
18: ; preds = %1
%19 = load i32, i32* @LOG_INFO
%20 = call i32 (i32, i8*, ...) @syslog(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %21
21: ; preds = %18, %11
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIMIT_RTPRIO = global i32 0
@LOG_WARNING = global i32 0
@.str = [25 x i8] c"setrlimit %u failed: %d\0A\00"
@errno = global i32 0
@EACCES = global i32 0
@LOG_INFO = global i32 0
@.str.1 = [20 x i8] c"set rlimit success\0A\00"
define i32 @cras_set_rt_scheduling(i32 %0) {
%2 = alloca %struct.rlimit
%3 = bitcast %struct.rlimit* %2 to i8*
%4 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 1
store i32 %0, i32* %4
%5 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
store i32 %0, i32* %5
%6 = load i32, i32* @RLIMIT_RTPRIO
%7 = call i64 @setrlimit(i32 %6, %struct.rlimit* %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @LOG_WARNING
%11 = load i32, i32* @errno
%12 = call i32 (i32, i8*, ...) @syslog(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %11)
%13 = load i32, i32* @EACCES
%14 = sub nsw i32 0, %13
br label %18
15: ; preds = %1
%16 = load i32, i32* @LOG_INFO
%17 = call i32 (i32, i8*, ...) @syslog(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %15, %9
%19 = phi i32 [ %14, %9 ], [ 0, %15 ]
ret i32 %19
}