#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;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_STACK;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ human_size(int /*<<< orphan*/, char **);
int /*<<< orphan*/ printf(char *, char *, char *, char *);
void print_stack_limit(char *msg) {
  struct rlimit limit;
  char *cur, *max;
  getrlimit(RLIMIT_STACK, &limit);
  human_size(limit.rlim_cur, &cur);
  human_size(limit.rlim_max, &max);
  printf("stack limit %-10s soft=%-10s hard=%-10s\n", msg, cur, max);
  free(cur);
  free(max);
}


x86 assembly (clang, -O0):
<print_stack_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1050 <getrlimit@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1060 <human_size@plt>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <human_size@plt>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_stack_limit>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
call   1050 <getrlimit@plt>
mov    0x1c(%rsp),%edi
lea    0x10(%rsp),%rsi
call   1060 <human_size@plt>
mov    0x18(%rsp),%edi
lea    0x8(%rsp),%rsi
call   1060 <human_size@plt>
mov    0x10(%rsp),%rdx
mov    0x8(%rsp),%rcx
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIMIT_STACK = global i32 0
@.str = [41 x i8] c"stack limit %-10s soft=%-10s hard=%-10s\0A\00"
define void @print_stack_limit(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.rlimit
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i32, i32* @RLIMIT_STACK
%7 = call i32 @getrlimit(i32 %6, %struct.rlimit* %3)
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 1
%9 = load i32, i32* %8
%10 = call i32 @human_size(i32 %9, i8** %4)
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @human_size(i32 %12, i8** %5)
%14 = load i8*, i8** %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15, i8* %16)
%18 = load i8*, i8** %4
%19 = call i32 @free(i8* %18)
%20 = load i8*, i8** %5
%21 = call i32 @free(i8* %20)
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIMIT_STACK = global i32 0
@.str = [41 x i8] c"stack limit %-10s soft=%-10s hard=%-10s\0A\00"
define void @print_stack_limit(i8* %0) {
%2 = alloca %struct.rlimit
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast %struct.rlimit* %2 to i8*
%6 = bitcast i8** %3 to i8*
%7 = bitcast i8** %4 to i8*
%8 = load i32, i32* @RLIMIT_STACK
%9 = call i32 @getrlimit(i32 %8, %struct.rlimit* %2)
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 1
%11 = load i32, i32* %10
%12 = call i32 @human_size(i32 %11, i8** %3)
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @human_size(i32 %14, i8** %4)
%16 = load i8*, i8** %3
%17 = load i8*, i8** %4
%18 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %16, i8* %17)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
ret void
}