#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 rlim_cur;
  int rlim_max;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_STACK;
int getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int ret;
  struct rlimit slim;
  ret = getrlimit(RLIMIT_STACK, &slim);
  if (ret)
    perror("getrlimit ");
  printf(" %u MB \n", slim.rlim_cur / (1024 * 1024));
  printf(" %u MB \n", slim.rlim_max / (1024 * 1024));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1050 <getrlimit@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     116a <main+0x3a>
lea    0xe9b(%rip),%rdi
call   1040 <perror@plt>
mov    -0x10(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <getrlimit@plt>
test   %eax,%eax
jne    118f <main+0x5f>
mov    0x8(%rsp),%eax
lea    0xfffff(%rax),%esi
test   %eax,%eax
cmovns %eax,%esi
sar    $0x14,%esi
lea    0xea6(%rip),%rbx
mov    %rbx,%rdi
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
lea    0xfffff(%rax),%esi
test   %eax,%eax
cmovns %eax,%esi
sar    $0x14,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe6a(%rip),%rdi
call   1040 <perror@plt>
jmp    114c <main+0x1c>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIMIT_STACK = global i32 0
@.str = [11 x i8] c"getrlimit \00"
@.str.1 = [9 x i8] c" %u MB \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.rlimit
store i32 0, i32* %1
%4 = load i32, i32* @RLIMIT_STACK
%5 = call i32 @getrlimit(i32 %4, %struct.rlimit* %3)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1048576
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 1
%16 = load i32, i32* %15
%17 = sdiv i32 %16, 1048576
%18 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIMIT_STACK = global i32 0
@.str = [11 x i8] c"getrlimit \00"
@.str.1 = [9 x i8] c" %u MB \0A\00"
define i32 @main() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = load i32, i32* @RLIMIT_STACK
%4 = call i32 @getrlimit(i32 %3, %struct.rlimit* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 1048576
%12 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 1048576
%16 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %15)
ret i32 0
}