#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;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ RLIMIT_RTPRIO;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long long, long long);
int prlimit(int /*<<< orphan*/, int /*<<< orphan*/, struct rlimit *,
            struct rlimit *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct rlimit old, new;
  struct rlimit *newp;
  pid_t pid;
  if (!(argc == 2)) {
    fprintf(stderr, "Usage: %s <pid>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  pid = atoi(argv[1]);
  new.rlim_cur = 2;
  new.rlim_max = 2;
  newp = &new;
  if (prlimit(pid, RLIMIT_RTPRIO, newp, &old) == -1)
    do {
      perror("prlimit-rtprio-1");
      exit(EXIT_FAILURE);
    } while (0);
  printf("Previous limits: soft=%lld; hard=%lld\n", (long long)old.rlim_cur,
         (long long)old.rlim_max);
  if (prlimit(pid, RLIMIT_RTPRIO, NULL, &old) == -1)
    do {
      perror("prlimit-rtprio-2");
      exit(EXIT_FAILURE);
    } while (0);
  printf("New limits: soft=%lld; hard=%lld\n", (long long)old.rlim_cur,
         (long long)old.rlim_max);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11aa <main+0x4a>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x2,-0x20(%rbp)
movl   $0x2,-0x1c(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    1211 <main+0xb1>
jmp    11f7 <main+0x97>
lea    0xe13(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movslq -0x18(%rbp),%rsi
movslq -0x14(%rbp),%rdx
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    1266 <main+0x106>
jmp    124c <main+0xec>
lea    0xdf6(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movslq -0x18(%rbp),%rsi
movslq -0x14(%rbp),%rdx
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11af <main+0x4f>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
movabs $0x200000002,%rax
mov    %rax,0x10(%rsp)
mov    0x2e4b(%rip),%r14
mov    (%r14),%esi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    11c9 <main+0x69>
lea    0xe64(%rip),%rdi
jmp    11fc <main+0x9c>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1201 <main+0xa1>
movslq 0x8(%rsp),%rsi
movslq 0xc(%rsp),%rdx
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
mov    (%r14),%esi
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
xor    %edx,%edx
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    120f <main+0xaf>
lea    0xe4d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movslq 0x8(%rsp),%rsi
movslq 0xc(%rsp),%rdx
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@stderr = global i32 0
@.str = [17 x i8] c"Usage: %s <pid>\0A\00"
@EXIT_FAILURE = global i32 0
@RLIMIT_RTPRIO = global i32 0
@.str.1 = [17 x i8] c"prlimit-rtprio-1\00"
@.str.2 = [39 x i8] c"Previous limits: soft=%lld; hard=%lld\0A\00"
@.str.3 = [17 x i8] c"prlimit-rtprio-2\00"
@.str.4 = [34 x i8] c"New limits: soft=%lld; hard=%lld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.rlimit
%7 = alloca %struct.rlimit
%8 = alloca %struct.rlimit*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %9
%25 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 0
store i32 2, i32* %25
%26 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 1
store i32 2, i32* %26
store %struct.rlimit* %7, %struct.rlimit** %8
%27 = load i32, i32* %9
%28 = load i32, i32* @RLIMIT_RTPRIO
%29 = load %struct.rlimit*, %struct.rlimit** %8
%30 = call i32 @prlimit(i32 %27, i32 %28, %struct.rlimit* %29, %struct.rlimit* %6)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %38
32: ; preds = %20
br label %33
33: ; preds = %32
%34 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; No predecessors!
br label %38
38: ; preds = %37, %20
%39 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
%40 = load i32, i32* %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
%43 = load i32, i32* %42
%44 = sext i32 %43 to i64
%45 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i64 %41, i64 %44)
%46 = load i32, i32* %9
%47 = load i32, i32* @RLIMIT_RTPRIO
%48 = call i32 @prlimit(i32 %46, i32 %47, %struct.rlimit* null, %struct.rlimit* %6)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %56
50: ; preds = %38
br label %51
51: ; preds = %50
%52 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; No predecessors!
br label %56
56: ; preds = %55, %38
%57 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
%58 = load i32, i32* %57
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
%61 = load i32, i32* %60
%62 = sext i32 %61 to i64
%63 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i64 %59, i64 %62)
%64 = load i32, i32* @EXIT_SUCCESS
%65 = call i32 @exit(i32 %64)
unreachable
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@stderr = global i32 0
@.str = [17 x i8] c"Usage: %s <pid>\0A\00"
@EXIT_FAILURE = global i32 0
@RLIMIT_RTPRIO = global i32 0
@.str.1 = [17 x i8] c"prlimit-rtprio-1\00"
@.str.2 = [39 x i8] c"Previous limits: soft=%lld; hard=%lld\0A\00"
@.str.3 = [17 x i8] c"prlimit-rtprio-2\00"
@.str.4 = [34 x i8] c"New limits: soft=%lld; hard=%lld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.rlimit
%4 = alloca %struct.rlimit
%5 = bitcast %struct.rlimit* %3 to i8*
%6 = bitcast %struct.rlimit* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 0
store i32 2, i32* %18
%19 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 1
store i32 2, i32* %19
%20 = load i32, i32* @RLIMIT_RTPRIO
%21 = call i32 @prlimit(i32 %17, i32 %20, %struct.rlimit* %4, %struct.rlimit* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %14
%24 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %14
%28 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i64 %30, i64 %33)
%35 = load i32, i32* @RLIMIT_RTPRIO
%36 = call i32 @prlimit(i32 %17, i32 %35, %struct.rlimit* null, %struct.rlimit* %3)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %27
%39 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %27
%43 = load i32, i32* %28
%44 = sext i32 %43 to i64
%45 = load i32, i32* %31
%46 = sext i32 %45 to i64
%47 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i64 %44, i64 %46)
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
}