#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 /*<<< orphan*/ rlim_max;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_CORE;
int /*<<< orphan*/ RLIM_INFINITY;
int getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/);
int setrlimit(int /*<<< orphan*/, struct rlimit *);
int main() {
  struct rlimit rlim;
  int ret;
  ret = getrlimit(RLIMIT_CORE, &rlim);
  if (ret == -1) {
    perror("getrlimit");
    return 1;
  }
  printf("RLIMIT_CORE limits: soft=%ld hard=%ld\n", rlim.rlim_cur,
         rlim.rlim_max);
  rlim.rlim_cur = 16 * 1024 * 1024;
  rlim.rlim_max = RLIM_INFINITY;
  ret = setrlimit(RLIMIT_CORE, &rlim);
  if (ret == -1) {
    perror("setrlimit");
    return 1;
  }
  printf("RLIMIT_CORE limits: soft=%ld hard=%ld\n", rlim.rlim_cur,
         rlim.rlim_max);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <getrlimit@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1186 <main+0x46>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <main+0xb4>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1000000,-0x10(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <setrlimit@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e2 <main+0xa2>
lea    0xe60(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <main+0xb4>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1060 <getrlimit@plt>
cmp    $0xffffffff,%eax
je     11b3 <main+0x73>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1000000,0x8(%rsp)
01
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1040 <setrlimit@plt>
cmp    $0xffffffff,%eax
je     11bc <main+0x7c>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe46(%rip),%rdi
jmp    11c3 <main+0x83>
lea    0xe6e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
jmp    11ad <main+0x6d>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIMIT_CORE = global i32 0
@.str = [10 x i8] c"getrlimit\00"
@.str.1 = [39 x i8] c"RLIMIT_CORE limits: soft=%ld hard=%ld\0A\00"
@RLIM_INFINITY = global i32 0
@.str.2 = [10 x i8] c"setrlimit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.rlimit
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @RLIMIT_CORE
%5 = call i32 @getrlimit(i32 %4, %struct.rlimit* %2)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %31
10: ; preds = %0
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %14)
%16 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
store i32 16777216, i32* %16
%17 = load i32, i32* @RLIM_INFINITY
%18 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @RLIMIT_CORE
%20 = call i32 @setrlimit(i32 %19, %struct.rlimit* %2)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %10
%24 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %31
25: ; preds = %10
%26 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %29)
br label %31
31: ; preds = %25, %23, %8
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIMIT_CORE = global i32 0
@.str = [10 x i8] c"getrlimit\00"
@.str.1 = [39 x i8] c"RLIMIT_CORE limits: soft=%ld hard=%ld\0A\00"
@RLIM_INFINITY = global i32 0
@.str.2 = [10 x i8] c"setrlimit\00"
define i32 @main() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = load i32, i32* @RLIMIT_CORE
%4 = call i32 @getrlimit(i32 %3, %struct.rlimit* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %24
8: ; preds = %0
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
%12 = load i32, i32* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %12)
store i32 16777216, i32* %9
%14 = load i32, i32* @RLIM_INFINITY
store i32 %14, i32* %11
%15 = load i32, i32* @RLIMIT_CORE
%16 = call i32 @setrlimit(i32 %15, %struct.rlimit* %1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %24
20: ; preds = %8
%21 = load i32, i32* %9
%22 = load i32, i32* %11
%23 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
br label %24
24: ; preds = %20, %18, %6
%25 = phi i32 [ 1, %6 ], [ 1, %18 ], [ 0, %20 ]
ret i32 %25
}