#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_cur;
  void *rlim_max;
};

/* Variables and functions */
void *atoi(char *);
int /*<<< orphan*/ die(char *, char *, void *);
scalar_t__ setrlimit(int, struct rlimit *);
char *strsep(char **, char *);
void setlimit(int key, char *lim) {
  char *hard;
  char *soft;
  struct rlimit rl;
  char *q = lim;
  soft = strsep(&q, "/");
  hard = q;
  rl.rlim_cur = atoi(soft);
  rl.rlim_max = hard ? atoi(hard) : rl.rlim_cur;
  if (setrlimit(key, &rl))
    die("Can't set ulimit ", lim, ((void *)-1));
}


x86 assembly (clang, -O0):
<setlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x38(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <strsep@plt>
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119d <setlimit+0x5d>
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x40(%rbp)
jmp    11a5 <setlimit+0x65>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
je     11da <setlimit+0x9a>
mov    -0x10(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0xffffffffffffffff,%rdx
call   1050 <die@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setlimit>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,0x8(%rsp)
lea    0xea6(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1030 <strsep@plt>
mov    0x8(%rsp),%rbp
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %rax,0x10(%rsp)
test   %rbp,%rbp
je     1183 <setlimit+0x43>
mov    %rbp,%rdi
call   1060 <atoi@plt>
mov    %rax,0x18(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
call   1040 <setrlimit@plt>
test   %rax,%rax
je     11b0 <setlimit+0x70>
lea    0xe61(%rip),%rdi
mov    %rbx,%rsi
mov    $0xffffffffffffffff,%rdx
call   1050 <die@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i8*, i8* }
@.str = [2 x i8] c"/\00"
@.str.1 = [18 x i8] c"Can't set ulimit \00"
define void @setlimit(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.rlimit
%8 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
store i8* %9, i8** %8
%10 = call i8* @strsep(i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %6
%11 = load i8*, i8** %8
store i8* %11, i8** %5
%12 = load i8*, i8** %6
%13 = call i8* @atoi(i8* %12)
%14 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 0
store i8* %13, i8** %14
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i8* @atoi(i8* %18)
br label %23
20: ; preds = %2
%21 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 0
%22 = load i8*, i8** %21
br label %23
23: ; preds = %20, %17
%24 = phi i8* [ %19, %17 ], [ %22, %20 ]
%25 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 1
store i8* %24, i8** %25
%26 = load i32, i32* %3
%27 = call i64 @setrlimit(i32 %26, %struct.rlimit* %7)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i8*, i8** %4
%31 = call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* inttoptr (i64 -1 to i8*))
br label %32
32: ; preds = %29, %23
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i8*, i8* }
@.str = [2 x i8] c"/\00"
@.str.1 = [18 x i8] c"Can't set ulimit \00"
define void @setlimit(i32 %0, i8* %1) {
%3 = alloca %struct.rlimit
%4 = alloca i8*
%5 = bitcast %struct.rlimit* %3 to i8*
%6 = bitcast i8** %4 to i8*
store i8* %1, i8** %4
%7 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %4
%9 = call i8* @atoi(i8* %7)
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i8* %9, i8** %10
%11 = icmp eq i8* %8, null
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i8* @atoi(i8* %8)
br label %14
14: ; preds = %2, %12
%15 = phi i8* [ %13, %12 ], [ %9, %2 ]
%16 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
store i8* %15, i8** %16
%17 = call i64 @setrlimit(i32 %0, %struct.rlimit* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* inttoptr (i64 -1 to i8*))
br label %21
21: ; preds = %19, %14
ret void
}