#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 */
struct task_struct {
  int dummy;
};
struct rq_heap_node {
  int dummy;
};
struct rq {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ add_task_rq(struct rq *, struct task_struct *);
struct rq *find_lock_earlier_rq(struct rq *);
int /*<<< orphan*/ free(struct rq_heap_node *);
struct task_struct *rq_heap_node_value(struct rq_heap_node *);
struct rq_heap_node *rq_take_next(struct rq *);
int /*<<< orphan*/ rq_unlock(struct rq *);
int rq_pull_tasks(struct rq *this_rq) {
  struct rq_heap_node *node;
  struct task_struct *task;
  struct rq *src_rq;
  src_rq = find_lock_earlier_rq(this_rq);
  if (src_rq) {
    node = rq_take_next(src_rq);
    task = rq_heap_node_value(node);
    add_task_rq(this_rq, task);
    rq_unlock(src_rq);
    free(node);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rq_pull_tasks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <find_lock_earlier_rq@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c9 <rq_pull_tasks+0x69>
mov    -0x28(%rbp),%rdi
call   1050 <rq_take_next@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <rq_heap_node_value@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <add_task_rq@plt>
mov    -0x28(%rbp),%rdi
call   1040 <rq_unlock@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <rq_pull_tasks+0x70>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pull_tasks>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1080 <find_lock_earlier_rq@plt>
test   %rax,%rax
je     11aa <rq_pull_tasks+0x4a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <rq_take_next@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <rq_heap_node_value@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <add_task_rq@plt>
mov    %rbx,%rdi
call   1040 <rq_unlock@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    11ac <rq_pull_tasks+0x4c>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rq = type { i32 }
%struct.rq_heap_node = type { i32 }
%struct.task_struct = type { i32 }
define i32 @rq_pull_tasks(%struct.rq* %0) {
%2 = alloca i32
%3 = alloca %struct.rq*
%4 = alloca %struct.rq_heap_node*
%5 = alloca %struct.task_struct*
%6 = alloca %struct.rq*
store %struct.rq* %0, %struct.rq** %3
%7 = load %struct.rq*, %struct.rq** %3
%8 = call %struct.rq* @find_lock_earlier_rq(%struct.rq* %7)
store %struct.rq* %8, %struct.rq** %6
%9 = load %struct.rq*, %struct.rq** %6
%10 = icmp ne %struct.rq* %9, null
br i1 %10, label %11, label %23
11: ; preds = %1
%12 = load %struct.rq*, %struct.rq** %6
%13 = call %struct.rq_heap_node* @rq_take_next(%struct.rq* %12)
store %struct.rq_heap_node* %13, %struct.rq_heap_node** %4
%14 = load %struct.rq_heap_node*, %struct.rq_heap_node** %4
%15 = call %struct.task_struct* @rq_heap_node_value(%struct.rq_heap_node* %14)
store %struct.task_struct* %15, %struct.task_struct** %5
%16 = load %struct.rq*, %struct.rq** %3
%17 = load %struct.task_struct*, %struct.task_struct** %5
%18 = call i32 @add_task_rq(%struct.rq* %16, %struct.task_struct* %17)
%19 = load %struct.rq*, %struct.rq** %6
%20 = call i32 @rq_unlock(%struct.rq* %19)
%21 = load %struct.rq_heap_node*, %struct.rq_heap_node** %4
%22 = call i32 @free(%struct.rq_heap_node* %21)
store i32 1, i32* %2
br label %24
23: ; preds = %1
store i32 0, i32* %2
br label %24
24: ; preds = %23, %11
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
%struct.rq = type { i32 }
%struct.rq_heap_node = type { i32 }
%struct.task_struct = type { i32 }
define i32 @rq_pull_tasks(%struct.rq* %0) {
%2 = tail call %struct.rq* @find_lock_earlier_rq(%struct.rq* %0)
%3 = icmp eq %struct.rq* %2, null
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call %struct.rq_heap_node* @rq_take_next(%struct.rq* %2)
%6 = tail call %struct.task_struct* @rq_heap_node_value(%struct.rq_heap_node* %5)
%7 = tail call i32 @add_task_rq(%struct.rq* %0, %struct.task_struct* %6)
%8 = tail call i32 @rq_unlock(%struct.rq* %2)
%9 = tail call i32 @free(%struct.rq_heap_node* %5)
br label %10
10: ; preds = %1, %4
%11 = phi i32 [ 1, %4 ], [ 0, %1 ]
ret i32 %11
}