#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*/ RLIMIT_AS;
int /*<<< orphan*/ RLIMIT_CPU;
int /*<<< orphan*/ RLIMIT_FSIZE;
int /*<<< orphan*/ RLIMIT_NPROC;
int /*<<< orphan*/ RLIMIT_STACK;
int atoi(char *);
char *getenv(char *);
int /*<<< orphan*/ set_limit(int /*<<< orphan*/, int);
char *strdup(char *);
char *strtok_r(char *, char *, char **);
void set_resource_limits(void) {
  char *limits = getenv("CC_PROCESS_RESOURCE_LIMITS");
  if (limits != NULL) {
    char *save;
    limits = strdup(limits);
    char *limit = strtok_r(limits, " ", &save);
    while (limit != NULL) {
      if (*limit++ != '-') {
        continue;
      }
      char type = *limit++;
      int value = atoi(limit);
      switch (type) {
      case 'f':
        set_limit(RLIMIT_FSIZE, value * 1024);
        break;
      case 's':
        set_limit(RLIMIT_STACK, value * 1024);
        break;
      case 't':
        set_limit(RLIMIT_CPU, value);
        break;
      case 'u':
        set_limit(RLIMIT_NPROC, value);
        break;
      case 'v':
        set_limit(RLIMIT_AS, value * 1024);
        break;
      }
      limit = strtok_r(NULL, " ", &save);
    }
  }
}


x86 assembly (clang, -O0):
<set_resource_limits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xee5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     12a1 <set_resource_limits+0x151>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed4(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     129c <set_resource_limits+0x14c>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11c3 <set_resource_limits+0x73>
jmp    1198 <set_resource_limits+0x48>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
movsbl -0x19(%rbp),%eax
add    $0xffffff9a,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x10,%eax
ja     127f <set_resource_limits+0x12f>
mov    -0x28(%rbp),%rax
lea    0xdfc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
shl    $0xa,%esi
call   1050 <set_limit@plt>
jmp    127f <set_resource_limits+0x12f>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
shl    $0xa,%esi
call   1050 <set_limit@plt>
jmp    127f <set_resource_limits+0x12f>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
call   1050 <set_limit@plt>
jmp    127f <set_resource_limits+0x12f>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
call   1050 <set_limit@plt>
jmp    127f <set_resource_limits+0x12f>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%esi
shl    $0xa,%esi
call   1050 <set_limit@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd5(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
jmp    1198 <set_resource_limits+0x48>
jmp    12a1 <set_resource_limits+0x151>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_resource_limits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xee2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1236 <set_resource_limits+0xe6>
mov    %rax,%rdi
call   1070 <strdup@plt>
lea    0xee0(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1040 <strtok_r@plt>
test   %rax,%rax
je     1236 <set_resource_limits+0xe6>
lea    0xec5(%rip),%r14
mov    %rsp,%r15
lea    0xe5c(%rip),%rbx
mov    0x2e3d(%rip),%r12
mov    0x2e1e(%rip),%r13
jmp    11c9 <set_resource_limits+0x79>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rax
test   %rax,%rax
je     1236 <set_resource_limits+0xe6>
cmpb   $0x2d,(%rax)
jne    11c0 <set_resource_limits+0x70>
movsbl 0x1(%rax),%ebp
add    $0x2,%rax
mov    %rax,%rdi
call   1060 <atoi@plt>
add    $0xffffff9a,%ebp
cmp    $0x10,%ebp
ja     1224 <set_resource_limits+0xd4>
movslq (%rbx,%rbp,4),%rcx
add    %rbx,%rcx
jmp    *%rcx
mov    0x2dca(%rip),%rcx
mov    (%rcx),%edi
jmp    121a <set_resource_limits+0xca>
mov    0x2dd7(%rip),%rcx
mov    (%rcx),%edi
jmp    121a <set_resource_limits+0xca>
mov    0x2dac(%rip),%rcx
mov    (%rcx),%edi
jmp    121d <set_resource_limits+0xcd>
mov    (%r12),%edi
jmp    121d <set_resource_limits+0xcd>
mov    0x0(%r13),%edi
shl    $0xa,%eax
mov    %eax,%esi
call   1050 <set_limit@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
jne    11c9 <set_resource_limits+0x79>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"CC_PROCESS_RESOURCE_LIMITS\00"
@.str.1 = [2 x i8] c" \00"
@RLIMIT_FSIZE = global i32 0
@RLIMIT_STACK = global i32 0
@RLIMIT_CPU = global i32 0
@RLIMIT_NPROC = global i32 0
@RLIMIT_AS = global i32 0
define void @set_resource_limits() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = call i8* @getenv(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %1
%7 = load i8*, i8** %1
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %58
9: ; preds = %0
%10 = load i8*, i8** %1
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %1
%12 = load i8*, i8** %1
%13 = call i8* @strtok_r(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2)
store i8* %13, i8** %3
br label %14
14: ; preds = %55, %23, %9
%15 = load i8*, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %57
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
%20 = load i8, i8* %18
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 45
br i1 %22, label %23, label %24
23: ; preds = %17
br label %14
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
%27 = load i8, i8* %25
store i8 %27, i8* %4
%28 = load i8*, i8** %3
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %5
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
switch i32 %31, label %55 [
i32 102, label %32
i32 115, label %37
i32 116, label %42
i32 117, label %46
i32 118, label %50
]
32: ; preds = %24
%33 = load i32, i32* @RLIMIT_FSIZE
%34 = load i32, i32* %5
%35 = mul nsw i32 %34, 1024
%36 = call i32 @set_limit(i32 %33, i32 %35)
br label %55
37: ; preds = %24
%38 = load i32, i32* @RLIMIT_STACK
%39 = load i32, i32* %5
%40 = mul nsw i32 %39, 1024
%41 = call i32 @set_limit(i32 %38, i32 %40)
br label %55
42: ; preds = %24
%43 = load i32, i32* @RLIMIT_CPU
%44 = load i32, i32* %5
%45 = call i32 @set_limit(i32 %43, i32 %44)
br label %55
46: ; preds = %24
%47 = load i32, i32* @RLIMIT_NPROC
%48 = load i32, i32* %5
%49 = call i32 @set_limit(i32 %47, i32 %48)
br label %55
50: ; preds = %24
%51 = load i32, i32* @RLIMIT_AS
%52 = load i32, i32* %5
%53 = mul nsw i32 %52, 1024
%54 = call i32 @set_limit(i32 %51, i32 %53)
br label %55
55: ; preds = %24, %50, %46, %42, %37, %32
%56 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2)
store i8* %56, i8** %3
br label %14
57: ; preds = %14
br label %58
58: ; preds = %57, %0
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"CC_PROCESS_RESOURCE_LIMITS\00"
@.str.1 = [2 x i8] c" \00"
@RLIMIT_FSIZE = global i32 0
@RLIMIT_STACK = global i32 0
@RLIMIT_CPU = global i32 0
@RLIMIT_NPROC = global i32 0
@RLIMIT_AS = global i32 0
define void @set_resource_limits() {
%1 = alloca i8*
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %43, label %4
4: ; preds = %0
%5 = bitcast i8** %1 to i8*
%6 = tail call i8* @strdup(i8* %2)
%7 = call i8* @strtok_r(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %42, label %9
9: ; preds = %4, %39
%10 = phi i8* [ %40, %39 ], [ %7, %4 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 45
br i1 %13, label %14, label %39
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %10, i64 2
%16 = load i8, i8* %11
%17 = call i32 @atoi(i8* %15)
%18 = sext i8 %16 to i32
switch i32 %18, label %37 [
i32 102, label %19
i32 115, label %23
i32 116, label %27
i32 117, label %30
i32 118, label %33
]
19: ; preds = %14
%20 = load i32, i32* @RLIMIT_FSIZE
%21 = shl nsw i32 %17, 10
%22 = call i32 @set_limit(i32 %20, i32 %21)
br label %37
23: ; preds = %14
%24 = load i32, i32* @RLIMIT_STACK
%25 = shl nsw i32 %17, 10
%26 = call i32 @set_limit(i32 %24, i32 %25)
br label %37
27: ; preds = %14
%28 = load i32, i32* @RLIMIT_CPU
%29 = call i32 @set_limit(i32 %28, i32 %17)
br label %37
30: ; preds = %14
%31 = load i32, i32* @RLIMIT_NPROC
%32 = call i32 @set_limit(i32 %31, i32 %17)
br label %37
33: ; preds = %14
%34 = load i32, i32* @RLIMIT_AS
%35 = shl nsw i32 %17, 10
%36 = call i32 @set_limit(i32 %34, i32 %35)
br label %37
37: ; preds = %14, %33, %30, %27, %23, %19
%38 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %1)
br label %39
39: ; preds = %37, %9
%40 = phi i8* [ %11, %9 ], [ %38, %37 ]
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %9
42: ; preds = %39, %4
br label %43
43: ; preds = %42, %0
ret void
}