#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 int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int open_oom_adj();
int snprintf(char *, int, char *, int);
int write(int, char *, int);
int set_oom_adj(int oom_adj) {
  int fd = open_oom_adj();
  int len = 0;
  if (fd >= 0) {
    char buf[64];
    len = snprintf(buf, sizeof(buf), "%d", oom_adj);
    len = write(fd, buf, len);
    close(fd);
  }
  return (len > 0);
}


x86 assembly (clang, -O0):
<set_oom_adj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1060 <open_oom_adj@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     119b <set_oom_adj+0x5b>
lea    -0x50(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x40,%esi
lea    0xe87(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x0,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_oom_adj>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %edi,%r14d
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <open_oom_adj@plt>
test   %eax,%eax
js     1193 <set_oom_adj+0x53>
mov    %eax,%ebx
lea    0xe9f(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %r14d,%ecx
call   1040 <snprintf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1050 <close@plt>
xor    %ebp,%ebp
test   %r14d,%r14d
setg   %bpl
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @set_oom_adj(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [64 x i8]
store i32 %0, i32* %2
%6 = call i32 (...) @open_oom_adj()
store i32 %6, i32* %3
store i32 0, i32* %4
%7 = load i32, i32* %3
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* %2
%12 = call i32 @snprintf(i8* %10, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %3
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* %4
%16 = call i32 @write(i32 %13, i8* %14, i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %3
%18 = call i32 @close(i32 %17)
br label %19
19: ; preds = %9, %1
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 0
%22 = zext i1 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @set_oom_adj(i32 %0) {
%2 = alloca [64 x i8]
%3 = tail call i32 (...) @open_oom_adj()
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i32 @write(i32 %3, i8* %6, i32 %7)
%9 = call i32 @close(i32 %3)
%10 = icmp sgt i32 %8, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %5, %1
%13 = phi i32 [ %11, %5 ], [ 0, %1 ]
ret i32 %13
}