#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 /*<<< orphan*/ rlim_max;
  int /*<<< orphan*/ rlim_cur;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_STACK;
int /*<<< orphan*/ RLIM_INFINITY;
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ perror(char *);
int setrlimit(int /*<<< orphan*/, struct rlimit *);
void remove_stack_limit_(void) {
  struct rlimit rlim = {RLIM_INFINITY, RLIM_INFINITY};
  if (setrlimit(RLIMIT_STACK, &rlim) == -1) {
    if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
      rlim.rlim_cur = rlim.rlim_max;
      if (setrlimit(RLIMIT_STACK, &rlim) == 0) {
        getrlimit(RLIMIT_STACK, &rlim);
      } else {
        perror("  Cannot set stack size to new value");
      }
    }
  }
}


x86 assembly (clang, -O0):
<remove_stack_limit_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <setrlimit@plt>
cmp    $0xffffffff,%eax
jne    11e3 <remove_stack_limit_+0xb3>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1050 <getrlimit@plt>
cmp    $0x0,%rax
jne    11de <remove_stack_limit_+0xae>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <setrlimit@plt>
cmp    $0x0,%eax
jne    11cd <remove_stack_limit_+0x9d>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1050 <getrlimit@plt>
jmp    11d9 <remove_stack_limit_+0xa9>
lea    0xe2c(%rip),%rdi
call   1040 <perror@plt>
jmp    11de <remove_stack_limit_+0xae>
jmp    11e3 <remove_stack_limit_+0xb3>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_stack_limit_>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %eax,0x4(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e8b(%rip),%rbx
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1030 <setrlimit@plt>
cmp    $0xffffffff,%eax
jne    1192 <remove_stack_limit_+0x62>
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1050 <getrlimit@plt>
test   %rax,%rax
jne    1192 <remove_stack_limit_+0x62>
mov    (%rsp),%eax
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1030 <setrlimit@plt>
test   %eax,%eax
jne    1198 <remove_stack_limit_+0x68>
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1050 <getrlimit@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe61(%rip),%rdi
call   1040 <perror@plt>
jmp    1192 <remove_stack_limit_+0x62>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32, i32, i32 }
@RLIM_INFINITY = global i32 0
@RLIMIT_STACK = global i32 0
@.str = [37 x i8] c" Cannot set stack size to new value\00"
define void @remove_stack_limit_() {
%1 = alloca %struct.rlimit
%2 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%3 = load i32, i32* @RLIM_INFINITY
store i32 %3, i32* %2
%4 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
%5 = load i32, i32* @RLIM_INFINITY
store i32 %5, i32* %4
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 2
store i32 0, i32* %6
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 3
store i32 0, i32* %7
%8 = load i32, i32* @RLIMIT_STACK
%9 = call i32 @setrlimit(i32 %8, %struct.rlimit* %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %29
11: ; preds = %0
%12 = load i32, i32* @RLIMIT_STACK
%13 = call i64 @getrlimit(i32 %12, %struct.rlimit* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @RLIMIT_STACK
%20 = call i32 @setrlimit(i32 %19, %struct.rlimit* %1)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @RLIMIT_STACK
%24 = call i64 @getrlimit(i32 %23, %struct.rlimit* %1)
br label %27
25: ; preds = %15
%26 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
br label %28
28: ; preds = %27, %11
br label %29
29: ; preds = %28, %0
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32, i32, i32 }
@RLIM_INFINITY = global i32 0
@RLIMIT_STACK = global i32 0
@.str = [37 x i8] c" Cannot set stack size to new value\00"
define void @remove_stack_limit_() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%4 = load i32, i32* @RLIM_INFINITY
store i32 %4, i32* %3
%5 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
store i32 %4, i32* %5
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 2
store i32 0, i32* %6
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 3
store i32 0, i32* %7
%8 = load i32, i32* @RLIMIT_STACK
%9 = call i32 @setrlimit(i32 %8, %struct.rlimit* %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %25
11: ; preds = %0
%12 = load i32, i32* @RLIMIT_STACK
%13 = call i64 @getrlimit(i32 %12, %struct.rlimit* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32, i32* %3
store i32 %16, i32* %5
%17 = load i32, i32* @RLIMIT_STACK
%18 = call i32 @setrlimit(i32 %17, %struct.rlimit* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* @RLIMIT_STACK
%22 = call i64 @getrlimit(i32 %21, %struct.rlimit* %1)
br label %25
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %11, %23, %20, %0
ret void
}