#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_msg(char *, char *, int, char const *, char const *,
                            int /*<<< orphan*/, ...);
scalar_t__ write(int, char *, int);
int set_oom_score_adj(const char *path, int value) {
  int fd, ret = 0;
  char buf[11];
  fd = open(path, O_RDWR);
  if (fd < 0) {
    test_msg("ERR: %s:%d: "
             "Failed to open %s"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/oom_score_adj.c",
             53, path, errno, strerror(errno));
    return -1;
  }
  snprintf(buf, 11, "%d", value);
  if (write(fd, buf, 11) < 0) {
    test_msg("ERR: %s:%d: "
             "Write %s to %s failed"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/oom_score_adj.c",
             60, buf, path, errno, strerror(errno));
    ret = -1;
  }
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<set_oom_score_adj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ea <set_oom_score_adj+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e34(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    %eax,%r9d
lea    0xe35(%rip),%rdi
lea    0xe5f(%rip),%rsi
mov    $0x35,%edx
mov    $0x0,%al
call   1060 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1285 <set_oom_score_adj+0x125>
lea    -0x27(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0xb,%esi
lea    0xede(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x18(%rbp),%edi
lea    -0x27(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1277 <set_oom_score_adj+0x117>
lea    -0x27(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x3c(%rbp),%r9d
lea    0xe84(%rip),%rdi
lea    0xdd0(%rip),%rsi
mov    $0x3c,%edx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1060 <test_msg@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_oom_score_adj>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11fa <set_oom_score_adj+0x9a>
mov    %eax,%ebp
lea    0xf51(%rip),%rdx
lea    0xd(%rsp),%r15
mov    %r15,%rdi
mov    $0xb,%esi
mov    %ebx,%ecx
call   1040 <snprintf@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xb,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
test   %rax,%rax
jns    11f1 <set_oom_score_adj+0x91>
mov    0x2e1d(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <strerror@plt>
mov    %eax,(%rsp)
lea    0xf10(%rip),%rdi
lea    0xe5c(%rip),%rsi
lea    0xd(%rsp),%rcx
mov    $0x3c,%edx
mov    %r14,%r8
mov    %ebx,%r9d
xor    %eax,%eax
call   1060 <test_msg@plt>
mov    $0xffffffff,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
jmp    1235 <set_oom_score_adj+0xd5>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
movslq %eax,%rbx
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xdec(%rip),%rdi
lea    0xe16(%rip),%rsi
mov    $0x35,%edx
mov    %r14,%rcx
mov    %rbx,%r8
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <test_msg@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [49 x i8] c"ERR: %s:%d: Failed to open %s (errno = %d (%s))\0A\00"
@.str.1 = [170 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/oom_score_adj.c\00"
@errno = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [53 x i8] c"ERR: %s:%d: Write %s to %s failed (errno = %d (%s))\0A\00"
define i32 @set_oom_score_adj(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [11 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %7
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load i32, i32* @errno
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 (i8*, i8*, i32, i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 53, i8* %15, i8* %18, i32 %20)
store i32 -1, i32* %3
br label %41
22: ; preds = %2
%23 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%24 = load i32, i32* %5
%25 = call i32 @snprintf(i8* %23, i32 11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %6
%27 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%28 = call i64 @write(i32 %26, i8* %27, i32 11)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %22
%31 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%32 = load i8*, i8** %4
%33 = load i32, i32* @errno
%34 = load i32, i32* @errno
%35 = call i32 @strerror(i32 %34)
%36 = call i32 (i8*, i8*, i32, i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 60, i8* %31, i8* %32, i32 %33, i32 %35)
store i32 -1, i32* %7
br label %37
37: ; preds = %30, %22
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = load i32, i32* %7
store i32 %40, i32* %3
br label %41
41: ; preds = %37, %14
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [49 x i8] c"ERR: %s:%d: Failed to open %s (errno = %d (%s))\0A\00"
@.str.1 = [170 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/oom_score_adj.c\00"
@errno = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [53 x i8] c"ERR: %s:%d: Write %s to %s failed (errno = %d (%s))\0A\00"
define i32 @set_oom_score_adj(i8* %0, i32 %1) {
%3 = alloca [11 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @strerror(i32 %9)
%13 = tail call i32 (i8*, i8*, i32, i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 53, i8* %0, i8* %11, i32 %12)
br label %25
14: ; preds = %2
%15 = call i32 @snprintf(i8* %4, i32 11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%16 = call i64 @write(i32 %6, i8* %4, i32 11)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 (i8*, i8*, i32, i8*, i8*, i32, ...) @test_msg(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 60, i8* %4, i8* %0, i32 %19, i32 %20)
br label %22
22: ; preds = %18, %14
%23 = phi i32 [ -1, %18 ], [ 0, %14 ]
%24 = call i32 @close(i32 %6)
br label %25
25: ; preds = %22, %8
%26 = phi i32 [ -1, %8 ], [ %23, %22 ]
ret i32 %26
}