#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 */

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ O_WRONLY;
scalar_t__ close(int);
int /*<<< orphan*/ die(char *);
scalar_t__ errno;
int open(char *, int /*<<< orphan*/);
int write(int, char *, int);
void dontkillme(void) {
  int fd;
  fd = open("/proc/self/oom_score_adj", O_WRONLY);
  if (fd < 0 && errno == ENOENT)
    return;
  if (fd < 0 || write(fd, "-1000\n", 6) != 6 || close(fd) != 0)
    die("cannot disable the out-of-memory killer for this process\n");
}


x86 assembly (clang, -O0):
<dontkillme>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1189 <dontkillme+0x49>
mov    0x2e6f(%rip),%rax
mov    (%rax),%rax
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%rax
jne    1189 <dontkillme+0x49>
jmp    11ce <dontkillme+0x8e>
cmpl   $0x0,-0x4(%rbp)
jl     11c2 <dontkillme+0x82>
mov    -0x4(%rbp),%edi
lea    0xe7c(%rip),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
cmp    $0x6,%eax
jne    11c2 <dontkillme+0x82>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     11ce <dontkillme+0x8e>
lea    0xe57(%rip),%rdi
call   1060 <die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dontkillme>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     118d <dontkillme+0x4d>
mov    %eax,%ebx
lea    0xeb6(%rip),%rsi
mov    %eax,%edi
mov    $0x6,%edx
call   1030 <write@plt>
cmp    $0x6,%eax
jne    1180 <dontkillme+0x40>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
je     11a3 <dontkillme+0x63>
lea    0xe99(%rip),%rdi
pop    %rbx
jmp    1060 <die@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
jne    1180 <dontkillme+0x40>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/proc/self/oom_score_adj\00"
@O_WRONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [7 x i8] c"-1000\0A\00"
@.str.2 = [58 x i8] c"cannot disable the out-of-memory killer for this process\0A\00"
define void @dontkillme() {
%1 = alloca i32
%2 = load i32, i32* @O_WRONLY
%3 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %2)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOENT
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %11
10: ; preds = %6
br label %24
11: ; preds = %6, %0
%12 = load i32, i32* %1
%13 = icmp slt i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = load i32, i32* %1
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%17 = icmp ne i32 %16, 6
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* %1
%20 = call i64 @close(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18, %14, %11
%23 = call i32 @die(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %10, %22, %18
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"/proc/self/oom_score_adj\00"
@O_WRONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [7 x i8] c"-1000\0A\00"
@.str.2 = [58 x i8] c"cannot disable the out-of-memory killer for this process\0A\00"
define void @dontkillme() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i64, i64* @errno
%6 = load i64, i64* @ENOENT
%7 = icmp eq i64 %5, %6
br i1 %7, label %16, label %14
8: ; preds = %0
%9 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%10 = icmp eq i32 %9, 6
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i64 @close(i32 %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %4, %11, %8
%15 = tail call i32 @die(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %11, %14, %4
ret void
}