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

/* Variables and functions */
int resctrl_alloc_task_write(int /*<<< orphan*/, int /*<<< orphan*/ const);
int resctrl_lock_exclusive();
int /*<<< orphan*/ resctrl_lock_release();
int os_alloc_release_pid(const pid_t *task_array, const unsigned task_num) {
  unsigned i;
  int ret;
  ;
  ;
  ret = resctrl_lock_exclusive();
  if (ret != 0)
    return ret;
  for (i = 0; i < task_num; i++) {
    ret = resctrl_alloc_task_write(0, task_array[i]);
    if (ret != 0)
      goto os_alloc_release_pid_unlock;
  }
os_alloc_release_pid_unlock:
  resctrl_lock_release();
  return ret;
}


x86 assembly (clang, -O0):
<os_alloc_release_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1030 <resctrl_lock_exclusive@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     115e <os_alloc_release_pid+0x2e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <os_alloc_release_pid+0x89>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11a7 <os_alloc_release_pid+0x77>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
xor    %edi,%edi
call   1050 <resctrl_alloc_task_write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1194 <os_alloc_release_pid+0x64>
jmp    11ac <os_alloc_release_pid+0x7c>
jmp    1199 <os_alloc_release_pid+0x69>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <os_alloc_release_pid+0x35>
jmp    11ac <os_alloc_release_pid+0x7c>
mov    $0x0,%al
call   1040 <resctrl_lock_release@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_alloc_release_pid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <resctrl_lock_exclusive@plt>
test   %eax,%eax
jne    1187 <os_alloc_release_pid+0x57>
test   %r14d,%r14d
je     117e <os_alloc_release_pid+0x4e>
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15,%rbx,4),%esi
xor    %edi,%edi
call   1050 <resctrl_alloc_task_write@plt>
test   %eax,%eax
jne    117c <os_alloc_release_pid+0x4c>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <os_alloc_release_pid+0x30>
xor    %ebp,%ebp
jmp    117e <os_alloc_release_pid+0x4e>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <resctrl_lock_release@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @os_alloc_release_pid(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = call i32 (...) @resctrl_lock_exclusive()
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %7
store i32 %12, i32* %3
br label %36
13: ; preds = %2
store i32 0, i32* %6
br label %14
14: ; preds = %29, %13
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = load i32*, i32** %4
%20 = load i32, i32* %6
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @resctrl_alloc_task_write(i32 0, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %18
br label %33
28: ; preds = %18
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add i32 %30, 1
store i32 %31, i32* %6
br label %14
32: ; preds = %14
br label %33
33: ; preds = %32, %27
%34 = call i32 (...) @resctrl_lock_release()
%35 = load i32, i32* %7
store i32 %35, i32* %3
br label %36
36: ; preds = %33, %11
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @os_alloc_release_pid(i32* nocapture %0, i32 %1) {
%3 = tail call i32 (...) @resctrl_lock_exclusive()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %21
5: ; preds = %2
%6 = icmp eq i32 %1, 0
br i1 %6, label %18, label %7
7: ; preds = %5
%8 = zext i32 %1 to i64
br label %11
9: ; preds = %11
%10 = icmp eq i64 %17, %8
br i1 %10, label %18, label %11
11: ; preds = %7, %9
%12 = phi i64 [ 0, %7 ], [ %17, %9 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = tail call i32 @resctrl_alloc_task_write(i32 0, i32 %14)
%16 = icmp eq i32 %15, 0
%17 = add nuw nsw i64 %12, 1
br i1 %16, label %9, label %18
18: ; preds = %11, %9, %5
%19 = phi i32 [ 0, %5 ], [ 0, %9 ], [ %15, %11 ]
%20 = tail call i32 (...) @resctrl_lock_release()
br label %21
21: ; preds = %2, %18
%22 = phi i32 [ %19, %18 ], [ %3, %2 ]
ret i32 %22
}