#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 {
  void *rlim_max;
  void *rlim_cur;
};
typedef void *pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ RLIMIT_CPU;
void *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(void *, 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 || argc == 4)) {
    fprintf(stderr,
            "Usage: %s <pid> [<new-soft-limit> "
            "<new-hard-limit>]\n",
            argv[0]);
    exit(EXIT_FAILURE);
  }
  pid = atoi(argv[1]);
  newp = NULL;
  if (argc == 4) {
    new.rlim_cur = atoi(argv[2]);
    new.rlim_max = atoi(argv[3]);
    newp = &new;
  }
  if (prlimit(pid, RLIMIT_CPU, newp, &old) == -1)
    do {
      perror("prlimit-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_CPU, NULL, &old) == -1)
    do {
      perror("prlimit-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    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b4 <main+0x54>
cmpl   $0x4,-0x8(%rbp)
je     11b4 <main+0x54>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1201 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    1243 <main+0xe3>
jmp    1229 <main+0xc9>
lea    0xe05(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xded(%rip),%rdi
call   1030 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    1299 <main+0x139>
jmp    127f <main+0x11f>
lea    0xde0(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdc8(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x2,%edi
je     1177 <main+0x17>
cmp    $0x4,%ebp
jne    11ab <main+0x4b>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
mov    %rax,%r14
cmp    $0x4,%ebp
jne    11c5 <main+0x65>
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
mov    %rax,0x18(%rsp)
mov    0x18(%rbx),%rdi
call   1060 <atoi@plt>
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rdx
jmp    11c7 <main+0x67>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe42(%rip),%rsi
call   1040 <fprintf@plt>
jmp    121e <main+0xbe>
xor    %edx,%edx
mov    0x2df2(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%rcx
mov    %r14,%rdi
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    11e9 <main+0x89>
lea    0xe4e(%rip),%rdi
jmp    1219 <main+0xb9>
mov    (%rsp),%rdx
mov    0x8(%rsp),%rsi
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
mov    %rsp,%rcx
mov    %r14,%rdi
xor    %edx,%edx
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    122c <main+0xcc>
lea    0xe4d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    (%rsp),%rdx
mov    0x8(%rsp),%rsi
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
%struct.rlimit = type { i8*, i8* }
@stderr = global i32 0
@.str = [53 x i8] c"Usage: %s <pid> [<new-soft-limit> <new-hard-limit>]\0A\00"
@EXIT_FAILURE = global i32 0
@RLIMIT_CPU = global i32 0
@.str.1 = [10 x i8] c"prlimit-1\00"
@.str.2 = [39 x i8] c"Previous limits: soft=%lld; hard=%lld\0A\00"
@.str.3 = [10 x i8] c"prlimit-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*
switch i32 %0, label %7 [
i32 4, label %13
i32 2, label %13
]
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2, %2
%14 = icmp eq i32 %0, 4
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i8* @atoi(i8* %16)
br i1 %14, label %18, label %27
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i8* @atoi(i8* %20)
%22 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 1
store i8* %21, i8** %22
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i8* @atoi(i8* %24)
%26 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 0
store i8* %25, i8** %26
br label %27
27: ; preds = %18, %13
%28 = phi %struct.rlimit* [ %4, %18 ], [ null, %13 ]
%29 = load i32, i32* @RLIMIT_CPU
%30 = call i32 @prlimit(i8* %17, i32 %29, %struct.rlimit* %28, %struct.rlimit* %3)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %27
%37 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
%38 = load i8*, i8** %37
%39 = ptrtoint i8* %38 to i64
%40 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
%41 = load i8*, i8** %40
%42 = ptrtoint i8* %41 to i64
%43 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i64 %39, i64 %42)
%44 = load i32, i32* @RLIMIT_CPU
%45 = call i32 @prlimit(i8* %17, i32 %44, %struct.rlimit* null, %struct.rlimit* %3)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %36
%48 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %36
%52 = load i8*, i8** %37
%53 = ptrtoint i8* %52 to i64
%54 = load i8*, i8** %40
%55 = ptrtoint i8* %54 to i64
%56 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i64 %53, i64 %55)
%57 = load i32, i32* @EXIT_SUCCESS
%58 = call i32 @exit(i32 %57)
unreachable
}