#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 */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int getpid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int write(int, char *, int);
int oom_adjust(void) {
  int fd, ret;
  char path[64];
  sprintf(path, "/proc/%d/oom_adj", getpid());
  fd = open(path, O_WRONLY);
  if (fd < 0) {

    ;
    return 0;
  }
  ret = write(fd, "-17\n", 4);
  if (ret < 0) {

    ;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<oom_adjust>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%edx
lea    0xe8c(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a4 <oom_adjust+0x54>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <oom_adjust+0x89>
mov    -0x8(%rbp),%edi
lea    0xe63(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ca <oom_adjust+0x7a>
jmp    11ca <oom_adjust+0x7a>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oom_adjust>:
push   %rbx
sub    $0x40,%rsp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe9d(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1070 <sprintf@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a1 <oom_adjust+0x51>
mov    %eax,%ebx
lea    0xe83(%rip),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/%d/oom_adj\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"-17\0A\00"
define i32 @oom_adjust() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%6 = call i32 (...) @getpid()
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %0
store i32 0, i32* %1
br label %23
14: ; preds = %0
%15 = load i32, i32* %2
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
br label %20
20: ; preds = %19, %14
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
store i32 0, i32* %1
br label %23
23: ; preds = %20, %13
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/%d/oom_adj\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"-17\0A\00"
define i32 @oom_adjust() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getpid()
%4 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* %2, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%10 = tail call i32 @close(i32 %6)
br label %11
11: ; preds = %0, %8
ret i32 0
}