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

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_CORE;
scalar_t__ RLIM_INFINITY;
scalar_t__ geteuid();
int /*<<< orphan*/ getrlimit(int /*<<< orphan*/, struct rlimit *);
scalar_t__ getuid();
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void set_core_unlimited() {
  struct rlimit l;
  getrlimit(RLIMIT_CORE, &l);
  if (l.rlim_cur == RLIM_INFINITY) {
    return;
  }
  if (getuid() == 0 || geteuid() == 0) {
    l.rlim_cur = l.rlim_max = RLIM_INFINITY;
  } else {
    if (l.rlim_cur == l.rlim_max) {
      return;
    }
    l.rlim_cur = l.rlim_max;
  }
  if (setrlimit(RLIMIT_CORE, &l)) {
    write(2, "DBGMEM: Warning: Failed to remove core limit errno \n",
          strlen("DBGMEM: Warning: Failed to remove core limit errno \n"));
    ;
  }
}


x86 assembly (clang, -O0):
<set_core_unlimited>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1080 <getrlimit@plt>
mov    -0x10(%rbp),%rax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%rax
jne    1193 <set_core_unlimited+0x33>
jmp    1222 <set_core_unlimited+0xc2>
mov    $0x0,%al
call   1050 <getuid@plt>
cmp    $0x0,%rax
je     11b5 <set_core_unlimited+0x55>
mov    $0x0,%al
call   1060 <geteuid@plt>
cmp    $0x0,%rax
jne    11cc <set_core_unlimited+0x6c>
mov    0x2e1c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    %rax,-0x10(%rbp)
jmp    11e7 <set_core_unlimited+0x87>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11df <set_core_unlimited+0x7f>
jmp    1222 <set_core_unlimited+0xc2>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1070 <setrlimit@plt>
cmp    $0x0,%rax
je     1222 <set_core_unlimited+0xc2>
lea    0xdf6(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xde3(%rip),%rsi
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_core_unlimited>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e7a(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1080 <getrlimit@plt>
mov    0x8(%rsp),%rax
mov    0x2e51(%rip),%rbx
cmp    (%rbx),%rax
je     11ef <set_core_unlimited+0x8f>
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
je     11b2 <set_core_unlimited+0x52>
xor    %eax,%eax
call   1060 <geteuid@plt>
test   %rax,%rax
je     11b2 <set_core_unlimited+0x52>
mov    0x10(%rsp),%rax
cmp    %rax,0x8(%rsp)
jne    11ba <set_core_unlimited+0x5a>
jmp    11ef <set_core_unlimited+0x8f>
mov    (%rbx),%rax
mov    %rax,0x10(%rsp)
mov    %rax,0x8(%rsp)
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1070 <setrlimit@plt>
test   %rax,%rax
je     11ef <set_core_unlimited+0x8f>
lea    0xe28(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@RLIMIT_CORE = global i32 0
@RLIM_INFINITY = global i64 0
@.str = [53 x i8] c"DBGMEM: Warning: Failed to remove core limit errno \0A\00"
define void @set_core_unlimited() {
%1 = alloca %struct.rlimit
%2 = load i32, i32* @RLIMIT_CORE
%3 = call i32 @getrlimit(i32 %2, %struct.rlimit* %1)
%4 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%5 = load i64, i64* %4
%6 = load i64, i64* @RLIM_INFINITY
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %9
8: ; preds = %0
br label %37
9: ; preds = %0
%10 = call i64 (...) @getuid()
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = call i64 (...) @geteuid()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12, %9
%16 = load i64, i64* @RLIM_INFINITY
%17 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i64 %16, i64* %17
%18 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i64 %16, i64* %18
br label %30
19: ; preds = %12
%20 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%21 = load i64, i64* %20
%22 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
%23 = load i64, i64* %22
%24 = icmp eq i64 %21, %23
br i1 %24, label %25, label %26
25: ; preds = %19
br label %37
26: ; preds = %19
%27 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i64 %28, i64* %29
br label %30
30: ; preds = %26, %15
%31 = load i32, i32* @RLIMIT_CORE
%32 = call i64 @setrlimit(i32 %31, %struct.rlimit* %1)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @strlen(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @write(i32 2, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %8, %25, %34, %30
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@RLIMIT_CORE = global i32 0
@RLIM_INFINITY = global i64 0
@.str = [53 x i8] c"DBGMEM: Warning: Failed to remove core limit errno \0A\00"
define void @set_core_unlimited() {
%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 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @RLIM_INFINITY
%8 = icmp eq i64 %6, %7
br i1 %8, label %31, label %9
9: ; preds = %0
%10 = call i64 (...) @getuid()
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = call i64 (...) @geteuid()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12, %9
%16 = load i64, i64* @RLIM_INFINITY
%17 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
store i64 %16, i64* %17
br label %23
18: ; preds = %12
%19 = load i64, i64* %5
%20 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
%21 = load i64, i64* %20
%22 = icmp eq i64 %19, %21
br i1 %22, label %31, label %23
23: ; preds = %18, %15
%24 = phi i64 [ %16, %15 ], [ %21, %18 ]
store i64 %24, i64* %5
%25 = load i32, i32* @RLIMIT_CORE
%26 = call i64 @setrlimit(i32 %25, %struct.rlimit* %1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %23
%29 = call i32 @strlen(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @write(i32 2, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %23, %28, %18, %0
ret void
}