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

/* Variables and functions */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fwrite(char const *, int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char const *);
int write_to_oom_adj_file(const char *oom_adj_file, const char *oom_score) {
  FILE *oom_adj = NULL;
  size_t n;
  int ret = -1;
  if (!oom_adj_file || !oom_score)
    goto out;
  oom_adj = fopen(oom_adj_file, "a+");
  if (!oom_adj)
    goto out;
  n = fwrite(oom_score, strlen(oom_score), 1, oom_adj);
  if (n != 1)
    goto out;
  ret = 0;
out:
  if (oom_adj && fclose(oom_adj))
    ret = -1;
  return ret;
}


x86 assembly (clang, -O0):
<write_to_oom_adj_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x24(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1175 <write_to_oom_adj_file+0x35>
cmpq   $0x0,-0x10(%rbp)
jne    117a <write_to_oom_adj_file+0x3a>
jmp    11de <write_to_oom_adj_file+0x9e>
mov    -0x8(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119e <write_to_oom_adj_file+0x5e>
jmp    11de <write_to_oom_adj_file+0x9e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x1,-0x20(%rbp)
je     11d7 <write_to_oom_adj_file+0x97>
jmp    11de <write_to_oom_adj_file+0x9e>
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1203 <write_to_oom_adj_file+0xc3>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1203 <write_to_oom_adj_file+0xc3>
movl   $0xffffffff,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_oom_adj_file>:
push   %r15
push   %r14
push   %rbx
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     119e <write_to_oom_adj_file+0x5e>
mov    %rsi,%r14
test   %rsi,%rsi
je     119e <write_to_oom_adj_file+0x5e>
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     119e <write_to_oom_adj_file+0x5e>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
mov    %rax,%r14
xor    $0x1,%r14
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
or     %r14,%rax
setne  %bl
neg    %ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"a+\00"
define i32 @write_to_oom_adj_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32* null, i32** %5
store i32 -1, i32* %7
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
br label %30
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %5
%17 = load i32*, i32** %5
%18 = icmp ne i32* %17, null
br i1 %18, label %20, label %19
19: ; preds = %14
br label %30
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
%24 = load i32*, i32** %5
%25 = call i64 @fwrite(i8* %21, i32 %23, i32 1, i32* %24)
store i64 %25, i64* %6
%26 = load i64, i64* %6
%27 = icmp ne i64 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %20
br label %30
29: ; preds = %20
store i32 0, i32* %7
br label %30
30: ; preds = %29, %28, %19, %13
%31 = load i32*, i32** %5
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i32*, i32** %5
%35 = call i64 @fclose(i32* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 -1, i32* %7
br label %38
38: ; preds = %37, %33, %30
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
@.str = [3 x i8] c"a+\00"
define i32 @write_to_oom_adj_file(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i64 @fwrite(i8* %1, i32 %10, i32 1, i32* %7)
%12 = icmp ne i64 %11, 1
%13 = tail call i64 @fclose(i32* %7)
%14 = icmp ne i64 %13, 0
%15 = or i1 %12, %14
%16 = sext i1 %15 to i32
br label %17
17: ; preds = %2, %6, %9
%18 = phi i32 [ %16, %9 ], [ -1, %6 ], [ -1, %2 ]
ret i32 %18
}