#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*/ PR_SET_DUMPABLE;
int /*<<< orphan*/ RLIMIT_CORE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
scalar_t__ prctl(int /*<<< orphan*/, int, int /*<<< orphan*/,
                 int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void enableCoredumps(void) {
  if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) != 0)
    fprintf(stderr, "prctl: %s\n", strerror(errno));
  struct rlimit rlim;
  if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
    rlim.rlim_cur = rlim.rlim_max;
    if (setrlimit(RLIMIT_CORE, &rlim) == 0) {
      fprintf(stderr, "Enable Core Dumps OK!\n");
      return;
    }
  }
  fprintf(stderr, "Enable Core Dump failed: %s\n", strerror(errno));
}


x86 assembly (clang, -O0):
<enableCoredumps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1040 <prctl@plt>
cmp    $0x0,%rax
je     11ac <enableCoredumps+0x5c>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rdx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <getrlimit@plt>
cmp    $0x0,%rax
jne    120b <enableCoredumps+0xbb>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1050 <setrlimit@plt>
cmp    $0x0,%rax
jne    1206 <enableCoredumps+0xb6>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1239 <enableCoredumps+0xe9>
jmp    120b <enableCoredumps+0xbb>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enableCoredumps>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <prctl@plt>
test   %rax,%rax
je     119e <enableCoredumps+0x4e>
mov    0x2e5d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe6e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e43(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1060 <getrlimit@plt>
test   %rax,%rax
jne    11cf <enableCoredumps+0x7f>
mov    0x8(%rsp),%eax
mov    %eax,0xc(%rsp)
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1050 <setrlimit@plt>
test   %rax,%rax
je     11ff <enableCoredumps+0xaf>
mov    0x2e02(%rip),%rax
mov    (%rax),%ebx
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe35(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11f9 <enableCoredumps+0xa9>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@PR_SET_DUMPABLE = global i32 0
@stderr = global i32 0
@.str = [11 x i8] c"prctl: %s\0A\00"
@errno = global i32 0
@RLIMIT_CORE = global i32 0
@.str.1 = [23 x i8] c"Enable Core Dumps OK!\0A\00"
@.str.2 = [29 x i8] c"Enable Core Dump failed: %s\0A\00"
define void @enableCoredumps() {
%1 = alloca %struct.rlimit
%2 = load i32, i32* @PR_SET_DUMPABLE
%3 = call i64 @prctl(i32 %2, i32 1, i32 0, i32 0, i32 0)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = call i8* @strerror(i32 %7)
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %5, %0
%11 = load i32, i32* @RLIMIT_CORE
%12 = call i64 @getrlimit(i32 %11, %struct.rlimit* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @RLIMIT_CORE
%19 = call i64 @setrlimit(i32 %18, %struct.rlimit* %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %30
24: ; preds = %14
br label %25
25: ; preds = %24, %10
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %25, %21
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@PR_SET_DUMPABLE = global i32 0
@stderr = global i32 0
@.str = [11 x i8] c"prctl: %s\0A\00"
@errno = global i32 0
@RLIMIT_CORE = global i32 0
@.str.1 = [23 x i8] c"Enable Core Dumps OK!\0A\00"
@.str.2 = [29 x i8] c"Enable Core Dump failed: %s\0A\00"
define void @enableCoredumps() {
%1 = alloca %struct.rlimit
%2 = load i32, i32* @PR_SET_DUMPABLE
%3 = tail call i64 @prctl(i32 %2, i32 1, i32 0, i32 0, i32 0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %5, %0
%11 = bitcast %struct.rlimit* %1 to i8*
%12 = load i32, i32* @RLIMIT_CORE
%13 = call i64 @getrlimit(i32 %12, %struct.rlimit* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %10
%16 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @RLIMIT_CORE
%20 = call i64 @setrlimit(i32 %19, %struct.rlimit* %1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %30
25: ; preds = %15, %10
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %25, %22
ret void
}