#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__ errno;
int nice(int);
int ls_setpriority(int newPriority) {
  int increment;
  if (newPriority > 20 * 2) {
    newPriority = 20 * 2;
  } else if (newPriority < -20 * 2) {
    newPriority = -20 * 2;
  }
  increment = newPriority;
  errno = 0;
  if (-1 == nice(increment) && (0 != errno)) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ls_setpriority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x28,-0x8(%rbp)
jle    1131 <ls_setpriority+0x21>
movl   $0x28,-0x8(%rbp)
jmp    1147 <ls_setpriority+0x37>
cmpl   $0xffffffd8,-0x8(%rbp)
jge    1142 <ls_setpriority+0x32>
movl   $0xffffffd8,-0x8(%rbp)
jmp    1147 <ls_setpriority+0x37>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e8c(%rip),%rax
movq   $0x0,(%rax)
mov    -0xc(%rbp),%edi
call   1030 <nice@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1190 <ls_setpriority+0x80>
xor    %eax,%eax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
je     1190 <ls_setpriority+0x80>
movl   $0x0,-0x4(%rbp)
jmp    1197 <ls_setpriority+0x87>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls_setpriority>:
push   %rbx
cmp    $0xffffffd9,%edi
mov    $0xffffffd8,%eax
cmovl  %eax,%edi
cmp    $0x28,%edi
mov    $0x28,%eax
cmovge %eax,%edi
mov    0x2eb2(%rip),%rbx
movq   $0x0,(%rbx)
call   1030 <nice@plt>
cmp    $0xffffffff,%eax
setne  %al
cmpq   $0x0,(%rbx)
sete   %cl
or     %al,%cl
movzbl %cl,%eax
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
define i32 @ls_setpriority(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp sgt i32 %5, 40
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 40, i32* %3
br label %13
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, -40
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 -40, i32* %3
br label %12
12: ; preds = %11, %8
br label %13
13: ; preds = %12, %7
%14 = load i32, i32* %3
store i32 %14, i32* %4
store i64 0, i64* @errno
%15 = load i32, i32* %4
%16 = call i32 @nice(i32 %15)
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i64, i64* @errno
%20 = icmp ne i64 0, %19
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 0, i32* %2
br label %23
22: ; preds = %18, %13
store i32 1, i32* %2
br label %23
23: ; preds = %22, %21
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @ls_setpriority(i32 %0) {
%2 = icmp sgt i32 %0, -40
%3 = select i1 %2, i32 %0, i32 -40
%4 = icmp slt i32 %3, 40
%5 = select i1 %4, i32 %3, i32 40
store i64 0, i64* @errno
%6 = tail call i32 @nice(i32 %5)
%7 = icmp ne i32 %6, -1
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
%10 = select i1 %7, i1 true, i1 %9
%11 = zext i1 %10 to i32
ret i32 %11
}