#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char const *, int /*<<< orphan*/);
size_t read(int, char *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ test_msg(char *, char *, int, char const *,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int get_oom_score_adj(const char *path, int *err) {
  int fd;
  ssize_t num;
  char buf[11];
  *err = 0;
  fd = open(path, O_RDONLY);
  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",
             27, path, errno, strerror(errno));
    goto out;
  }
  num = read(fd, buf, 10);
  close(fd);
  if (num < 0) {
    test_msg("ERR: %s:%d: "
             "Unable to read %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",
             34, path, errno, strerror(errno));
    goto out;
  }
  buf[num] = '\0';
  return strtol(buf, NULL, 10);
out:
  *err = -1;
  return 0;
}


x86 assembly (clang, -O0):
<get_oom_score_adj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e3 <get_oom_score_adj+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%r8d
mov    %eax,%r9d
lea    0xe33(%rip),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x1b,%edx
call   1040 <test_msg@plt>
jmp    1278 <get_oom_score_adj+0x118>
mov    -0x1c(%rbp),%edi
lea    -0x33(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
cmpq   $0x0,-0x28(%rbp)
jae    1255 <get_oom_score_adj+0xf5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x50(%rbp),%rcx
mov    -0x44(%rbp),%r8d
mov    %eax,%r9d
lea    0xe9c(%rip),%rdi
lea    0xdeb(%rip),%rsi
mov    $0x22,%edx
call   1040 <test_msg@plt>
jmp    1278 <get_oom_score_adj+0x118>
mov    -0x28(%rbp),%rax
movb   $0x0,-0x33(%rbp,%rax,1)
lea    -0x33(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x4(%rbp)
jmp    1289 <get_oom_score_adj+0x129>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_oom_score_adj>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,(%rsi)
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11bc <get_oom_score_adj+0x5c>
mov    %eax,%ebp
lea    0x5(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <close@plt>
movb   $0x0,0x5(%rsp,%rbx,1)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
jmp    11f6 <get_oom_score_adj+0x96>
mov    0x2e15(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe2d(%rip),%rdi
lea    0xe57(%rip),%rsi
mov    $0x1b,%edx
mov    %rbx,%rcx
mov    %ebp,%r8d
mov    %eax,%r9d
call   1040 <test_msg@plt>
movl   $0xffffffff,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = 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 = [49 x i8] c"ERR: %s:%d: Unable to read %s (errno = %d (%s))\0A\00"
define i32 @get_oom_score_adj(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i64
%8 = alloca [11 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i32*, i32** %5
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i32, i32* @errno
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call 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 27, i8* %16, i32 %17, i32 %19)
br label %40
21: ; preds = %2
%22 = load i32, i32* %6
%23 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%24 = call i64 @read(i32 %22, i8* %23, i32 10)
store i64 %24, i64* %7
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
%27 = load i64, i64* %7
%28 = icmp ult i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = load i32, i32* @errno
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 @test_msg(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str.1, i64 0, i64 0), i32 34, i8* %30, i32 %31, i32 %33)
br label %40
35: ; preds = %21
%36 = load i64, i64* %7
%37 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 %36
store i8 0, i8* %37
%38 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%39 = call i32 @strtol(i8* %38, i32* null, i32 10)
store i32 %39, i32* %3
br label %42
40: ; preds = %29, %15
%41 = load i32*, i32** %5
store i32 -1, i32* %41
store i32 0, i32* %3
br label %42
42: ; preds = %40, %35
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@O_RDONLY = 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
define i32 @get_oom_score_adj(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [11 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call 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 27, i8* %0, i32 %9, i32 %10)
store i32 -1, i32* %1
br label %17
12: ; preds = %2
%13 = call i64 @read(i32 %6, i8* %4, i32 10)
%14 = tail call i32 @close(i32 %6)
%15 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %15
%16 = call i32 @strtol(i8* nocapture %4, i32* null, i32 10)
br label %17
17: ; preds = %8, %12
%18 = phi i32 [ 0, %8 ], [ %16, %12 ]
ret i32 %18
}