#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 {
  scalar_t__ rlim_cur;
  scalar_t__ rlim_max;
};
typedef scalar_t__ rlim_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ setrlimit(int, struct rlimit *);
int increase_limit(int resource, rlim_t increase) {
  struct rlimit rlim;
  int save_errno = errno;
  if (!getrlimit(resource, &rlim)) {
    rlim.rlim_cur += increase;
    if (rlim.rlim_cur >= rlim.rlim_max)
      rlim.rlim_max = rlim.rlim_cur + increase;
    if (!setrlimit(resource, &rlim))
      return 1;
  }
  errno = save_errno;
  return 0;
}


x86 assembly (clang, -O0):
<increase_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1040 <getrlimit@plt>
cmp    $0x0,%eax
jne    119c <increase_limit+0x7c>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jl     1176 <increase_limit+0x56>
mov    -0x20(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1030 <setrlimit@plt>
cmp    $0x0,%eax
jne    1197 <increase_limit+0x77>
movl   $0x1,-0x4(%rbp)
jmp    11af <increase_limit+0x8f>
jmp    119c <increase_limit+0x7c>
mov    -0x24(%rbp),%ecx
mov    0x2e3a(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<increase_limit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2eaa(%rip),%r15
mov    (%r15),%ebp
lea    0x8(%rsp),%rsi
call   1040 <getrlimit@plt>
test   %eax,%eax
jne    1173 <increase_limit+0x53>
mov    0x8(%rsp),%rax
add    %r14,%rax
mov    %rax,0x8(%rsp)
cmp    0x10(%rsp),%rax
jl     1163 <increase_limit+0x43>
add    %r14,%rax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1030 <setrlimit@plt>
test   %eax,%eax
je     1183 <increase_limit+0x63>
mov    %ebp,(%r15)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%eax
jmp    1178 <increase_limit+0x58>

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@errno = global i32 0
define i32 @increase_limit(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca %struct.rlimit
%7 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %5
%8 = load i32, i32* @errno
store i32 %8, i32* %7
%9 = load i32, i32* %4
%10 = call i32 @getrlimit(i32 %9, %struct.rlimit* %6)
%11 = icmp ne i32 %10, 0
br i1 %11, label %34, label %12
12: ; preds = %2
%13 = load i64, i64* %5
%14 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
%15 = load i64, i64* %14
%16 = add nsw i64 %15, %13
store i64 %16, i64* %14
%17 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
%20 = load i64, i64* %19
%21 = icmp sge i64 %18, %20
br i1 %21, label %22, label %28
22: ; preds = %12
%23 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
%24 = load i64, i64* %23
%25 = load i64, i64* %5
%26 = add nsw i64 %24, %25
%27 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
store i64 %26, i64* %27
br label %28
28: ; preds = %22, %12
%29 = load i32, i32* %4
%30 = call i32 @setrlimit(i32 %29, %struct.rlimit* %6)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %28
store i32 1, i32* %3
br label %36
33: ; preds = %28
br label %34
34: ; preds = %33, %2
%35 = load i32, i32* %7
store i32 %35, i32* @errno
store i32 0, i32* %3
br label %36
36: ; preds = %34, %32
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@errno = global i32 0
define i32 @increase_limit(i32 %0, i64 %1) {
%3 = alloca %struct.rlimit
%4 = bitcast %struct.rlimit* %3 to i8*
%5 = load i32, i32* @errno
%6 = call i32 @getrlimit(i32 %0, %struct.rlimit* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
%10 = load i64, i64* %9
%11 = add nsw i64 %10, %1
store i64 %11, i64* %9
%12 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
%13 = load i64, i64* %12
%14 = icmp slt i64 %11, %13
br i1 %14, label %17, label %15
15: ; preds = %8
%16 = add nsw i64 %11, %1
store i64 %16, i64* %12
br label %17
17: ; preds = %15, %8
%18 = call i32 @setrlimit(i32 %0, %struct.rlimit* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %17, %2
store i32 %5, i32* @errno
br label %21
21: ; preds = %17, %20
%22 = phi i32 [ 0, %20 ], [ 1, %17 ]
ret i32 %22
}