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

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_CORE;
int getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ perror(char *);
int setrlimit(int /*<<< orphan*/, struct rlimit *);
int set_core_size(unsigned int size) {
  struct rlimit rl;
  if (getrlimit(RLIMIT_CORE, &rl) == -1) {
    perror("getrlimit");
    return -1;
  }
  rl.rlim_cur = (size > rl.rlim_max) ? rl.rlim_max : size;
  if (setrlimit(RLIMIT_CORE, &rl) == -1) {
    perror("setrlimit");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_core_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1050 <getrlimit@plt>
cmp    $0xffffffff,%eax
jne    116e <set_core_size+0x3e>
lea    0xea3(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <set_core_size+0x9b>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jbe    1185 <set_core_size+0x55>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    118b <set_core_size+0x5b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <setrlimit@plt>
cmp    $0xffffffff,%eax
jne    11c4 <set_core_size+0x94>
lea    0xe57(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <set_core_size+0x9b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_core_size>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eab(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rsi
call   1050 <getrlimit@plt>
cmp    $0xffffffff,%eax
je     1175 <set_core_size+0x45>
mov    0x4(%rsp),%eax
cmp    %ebx,%eax
cmovb  %eax,%ebx
mov    %ebx,(%rsp)
mov    (%r14),%edi
mov    %rsp,%rsi
call   1030 <setrlimit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     117e <set_core_size+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe84(%rip),%rdi
jmp    1185 <set_core_size+0x55>
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    116d <set_core_size+0x3d>

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

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