#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 */
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
scalar_t__ asprintf(char **, char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
scalar_t__ strlen(char const *);
scalar_t__ write(int, char const *, scalar_t__);
int /*<<< orphan*/ xclose(int);
int /*<<< orphan*/ xerror(char *);
void xoom_score_adj(pid_t pid) {
  const char *value = "1000";
  char *path;
  if (asprintf(&path, "/proc/%d/oom_score_adj", pid) < 0)
    xerror("asprintf");
  int fd = open(path, O_WRONLY);
  if (fd < 0)
    xerror(path);
  if (write(fd, value, strlen(value)) != (ssize_t)strlen(value))
    xerror(path);
  xclose(fd);
  free(path);
}


x86 assembly (clang, -O0):
<xoom_score_adj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe7e(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1080 <asprintf@plt>
cmp    $0x0,%rax
jge    11af <xoom_score_adj+0x3f>
lea    0xe72(%rip),%rdi
call   1070 <xerror@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d7 <xoom_score_adj+0x67>
mov    -0x18(%rbp),%rdi
call   1070 <xerror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     1223 <xoom_score_adj+0xb3>
mov    -0x18(%rbp),%rdi
call   1070 <xerror@plt>
mov    -0x1c(%rbp),%edi
call   1050 <xclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xoom_score_adj>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%edx
lea    0xe97(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1070 <asprintf@plt>
test   %rax,%rax
jns    1189 <xoom_score_adj+0x29>
lea    0xe98(%rip),%rdi
call   1060 <xerror@plt>
mov    0x8(%rsp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11ac <xoom_score_adj+0x4c>
mov    0x8(%rsp),%rdi
call   1060 <xerror@plt>
lea    0xe4d(%rip),%rsi
mov    $0x4,%edx
mov    %ebx,%edi
call   1040 <write@plt>
cmp    $0x4,%rax
je     11cf <xoom_score_adj+0x6f>
mov    0x8(%rsp),%rdi
call   1060 <xerror@plt>
mov    %ebx,%edi
call   1050 <xclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"1000\00"
@.str.1 = [23 x i8] c"/proc/%d/oom_score_adj\00"
@.str.2 = [9 x i8] c"asprintf\00"
@O_WRONLY = global i32 0
define void @xoom_score_adj(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = load i32, i32* %2
%7 = call i64 @asprintf(i8** %4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @xerror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i8*, i8** %4
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i32 @xerror(i8* %18)
br label %20
20: ; preds = %17, %11
%21 = load i32, i32* %5
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i64 @strlen(i8* %23)
%25 = call i64 @write(i32 %21, i8* %22, i64 %24)
%26 = load i8*, i8** %3
%27 = call i64 @strlen(i8* %26)
%28 = icmp ne i64 %25, %27
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i8*, i8** %4
%31 = call i32 @xerror(i8* %30)
br label %32
32: ; preds = %29, %20
%33 = load i32, i32* %5
%34 = call i32 @xclose(i32 %33)
%35 = load i8*, i8** %4
%36 = call i32 @free(i8* %35)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"1000\00"
@.str.1 = [23 x i8] c"/proc/%d/oom_score_adj\00"
@.str.2 = [9 x i8] c"asprintf\00"
@O_WRONLY = global i32 0
define void @xoom_score_adj(i32 %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @xerror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i8*, i8** %2
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i32 @xerror(i8* %14)
br label %16
16: ; preds = %13, %8
%17 = call i64 @write(i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%18 = icmp eq i64 %17, 4
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = call i32 @xerror(i8* %20)
br label %22
22: ; preds = %19, %16
%23 = call i32 @xclose(i32 %11)
%24 = load i8*, i8** %2
%25 = call i32 @free(i8* %24)
ret void
}