#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 */
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ PRIO_PROCESS;
int /*<<< orphan*/ __NR_gettid;
int setpriority(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ syscall(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, char *);
int cras_set_nice_level(int nice) {
  int rc;
  rc = setpriority(PRIO_PROCESS, syscall(__NR_gettid), nice);
  syslog(LOG_DEBUG, "Set nice to %d %s.", nice, rc ? "Fail" : "Success");
  return rc;
}


x86 assembly (clang, -O0):
<cras_set_nice_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
call   1040 <syscall@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%esi
mov    -0x4(%rbp),%edx
call   1030 <setpriority@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%esi
lea    0xe9d(%rip),%rcx
lea    0xe91(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xe70(%rip),%rsi
call   1050 <syslog@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cras_set_nice_level>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e9c(%rip),%rax
mov    (%rax),%ebp
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
call   1040 <syscall@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %ebx,%edx
call   1030 <setpriority@plt>
mov    %eax,%ebp
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
test   %ebp,%ebp
lea    0xead(%rip),%rax
lea    0xea1(%rip),%rcx
cmove  %rax,%rcx
lea    0xe83(%rip),%rsi
mov    %ebx,%edx
call   1050 <syslog@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PRIO_PROCESS = global i32 0
@__NR_gettid = global i32 0
@LOG_DEBUG = global i32 0
@.str = [19 x i8] c"Set nice to %d %s.\00"
@.str.1 = [5 x i8] c"Fail\00"
@.str.2 = [8 x i8] c"Success\00"
define i32 @cras_set_nice_level(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @PRIO_PROCESS
%5 = load i32, i32* @__NR_gettid
%6 = call i32 @syscall(i32 %5)
%7 = load i32, i32* %2
%8 = call i32 @setpriority(i32 %4, i32 %6, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* @LOG_DEBUG
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%15 = call i32 @syslog(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %14)
%16 = load i32, i32* %3
ret i32 %16
}

LLVM IR (-O2):
@PRIO_PROCESS = global i32 0
@__NR_gettid = global i32 0
@LOG_DEBUG = global i32 0
@.str = [19 x i8] c"Set nice to %d %s.\00"
@.str.1 = [5 x i8] c"Fail\00"
@.str.2 = [8 x i8] c"Success\00"
define i32 @cras_set_nice_level(i32 %0) {
%2 = load i32, i32* @PRIO_PROCESS
%3 = load i32, i32* @__NR_gettid
%4 = tail call i32 @syscall(i32 %3)
%5 = tail call i32 @setpriority(i32 %2, i32 %4, i32 %0)
%6 = load i32, i32* @LOG_DEBUG
%7 = icmp eq i32 %5, 0
%8 = select i1 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%9 = tail call i32 @syslog(i32 %6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %8)
ret i32 %5
}