#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 {
  size_t rlim_cur;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_STACK;
int /*<<< orphan*/ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ print_stack_limit(char *);
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
void set_stack_limit(size_t size) {
  struct rlimit limit;
  getrlimit(RLIMIT_STACK, &limit);
  limit.rlim_cur = size;
  print_stack_limit("before");
  setrlimit(RLIMIT_STACK, &limit);
  print_stack_limit("after");
}


x86 assembly (clang, -O0):
<set_stack_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <getrlimit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1050 <print_stack_limit@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <setrlimit@plt>
lea    0xe8c(%rip),%rdi
call   1050 <print_stack_limit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_stack_limit>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e9d(%rip),%r15
mov    (%r15),%edi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1040 <getrlimit@plt>
mov    %rbx,0x8(%rsp)
lea    0xea1(%rip),%rdi
call   1050 <print_stack_limit@plt>
mov    (%r15),%edi
mov    %r14,%rsi
call   1030 <setrlimit@plt>
lea    0xe91(%rip),%rdi
call   1050 <print_stack_limit@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rlimit = type { i64 }
@RLIMIT_STACK = global i32 0
@.str = [7 x i8] c"before\00"
@.str.1 = [6 x i8] c"after\00"
define void @set_stack_limit(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.rlimit
store i64 %0, i64* %2
%4 = load i32, i32* @RLIMIT_STACK
%5 = call i32 @getrlimit(i32 %4, %struct.rlimit* %3)
%6 = load i64, i64* %2
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 0
store i64 %6, i64* %7
%8 = call i32 @print_stack_limit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @RLIMIT_STACK
%10 = call i32 @setrlimit(i32 %9, %struct.rlimit* %3)
%11 = call i32 @print_stack_limit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i64 }
@RLIMIT_STACK = global i32 0
@.str = [7 x i8] c"before\00"
@.str.1 = [6 x i8] c"after\00"
define void @set_stack_limit(i64 %0) {
%2 = alloca %struct.rlimit
%3 = bitcast %struct.rlimit* %2 to i8*
%4 = load i32, i32* @RLIMIT_STACK
%5 = call i32 @getrlimit(i32 %4, %struct.rlimit* %2)
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
store i64 %0, i64* %6
%7 = call i32 @print_stack_limit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @RLIMIT_STACK
%9 = call i32 @setrlimit(i32 %8, %struct.rlimit* %2)
%10 = call i32 @print_stack_limit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
ret void
}