#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 graph_node {
  int dummy;
};
struct graph {
  int dummy;
};

/* Variables and functions */
struct graph_node *graph_get_ready_node(struct graph *);
int /*<<< orphan*/ graph_node_get_commands(struct graph_node *);
int /*<<< orphan*/ graph_node_mark_resolved(struct graph *,
                                            struct graph_node *);
int /*<<< orphan*/ graph_node_needs_update(struct graph_node *);
scalar_t__ list_empty(int /*<<< orphan*/);
struct graph_node *next_node_needing_update(struct graph *graph) {
  struct graph_node *node = graph_get_ready_node(graph);
  while (node != NULL && (!graph_node_needs_update(node) ||
                          list_empty(graph_node_get_commands(node)))) {
    graph_node_mark_resolved(graph, node);
    node = graph_get_ready_node(graph);
  }
  return (node);
}


x86 assembly (clang, -O0):
<next_node_needing_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <graph_get_ready_node@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     11b2 <next_node_needing_update+0x62>
mov    -0x10(%rbp),%rdi
call   1060 <graph_node_needs_update@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x12(%rbp)
je     11ac <next_node_needing_update+0x5c>
mov    -0x10(%rbp),%rdi
call   1030 <graph_node_get_commands@plt>
mov    %eax,%edi
call   1070 <list_empty@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11c2 <next_node_needing_update+0x72>
jmp    11e1 <next_node_needing_update+0x91>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <graph_node_mark_resolved@plt>
mov    -0x8(%rbp),%rdi
call   1050 <graph_get_ready_node@plt>
mov    %rax,-0x10(%rbp)
jmp    1169 <next_node_needing_update+0x19>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_node_needing_update>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <graph_get_ready_node@plt>
test   %rax,%rax
je     11ad <next_node_needing_update+0x5d>
mov    %rax,%rbx
jmp    118b <next_node_needing_update+0x3b>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <graph_node_mark_resolved@plt>
mov    %r14,%rdi
call   1050 <graph_get_ready_node@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ad <next_node_needing_update+0x5d>
mov    %rbx,%rdi
call   1060 <graph_node_needs_update@plt>
test   %eax,%eax
je     1170 <next_node_needing_update+0x20>
mov    %rbx,%rdi
call   1030 <graph_node_get_commands@plt>
mov    %eax,%edi
call   1070 <list_empty@plt>
test   %rax,%rax
jne    1170 <next_node_needing_update+0x20>
jmp    11af <next_node_needing_update+0x5f>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.graph_node = type { i32 }
%struct.graph = type { i32 }
define %struct.graph_node* @next_node_needing_update(%struct.graph* %0) {
%2 = alloca %struct.graph*
%3 = alloca %struct.graph_node*
store %struct.graph* %0, %struct.graph** %2
%4 = load %struct.graph*, %struct.graph** %2
%5 = call %struct.graph_node* @graph_get_ready_node(%struct.graph* %4)
store %struct.graph_node* %5, %struct.graph_node** %3
br label %6
6: ; preds = %22, %1
%7 = load %struct.graph_node*, %struct.graph_node** %3
%8 = icmp ne %struct.graph_node* %7, null
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = load %struct.graph_node*, %struct.graph_node** %3
%11 = call i32 @graph_node_needs_update(%struct.graph_node* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load %struct.graph_node*, %struct.graph_node** %3
%15 = call i32 @graph_node_get_commands(%struct.graph_node* %14)
%16 = call i64 @list_empty(i32 %15)
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %13, %9
%19 = phi i1 [ true, %9 ], [ %17, %13 ]
br label %20
20: ; preds = %18, %6
%21 = phi i1 [ false, %6 ], [ %19, %18 ]
br i1 %21, label %22, label %28
22: ; preds = %20
%23 = load %struct.graph*, %struct.graph** %2
%24 = load %struct.graph_node*, %struct.graph_node** %3
%25 = call i32 @graph_node_mark_resolved(%struct.graph* %23, %struct.graph_node* %24)
%26 = load %struct.graph*, %struct.graph** %2
%27 = call %struct.graph_node* @graph_get_ready_node(%struct.graph* %26)
store %struct.graph_node* %27, %struct.graph_node** %3
br label %6
28: ; preds = %20
%29 = load %struct.graph_node*, %struct.graph_node** %3
ret %struct.graph_node* %29
}

LLVM IR (-O2):
%struct.graph_node = type { i32 }
%struct.graph = type { i32 }
define %struct.graph_node* @next_node_needing_update(%struct.graph* %0) {
%2 = tail call %struct.graph_node* @graph_get_ready_node(%struct.graph* %0)
%3 = icmp eq %struct.graph_node* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1, %12
%5 = phi %struct.graph_node* [ %14, %12 ], [ %2, %1 ]
%6 = tail call i32 @graph_node_needs_update(%struct.graph_node* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i32 @graph_node_get_commands(%struct.graph_node* %5)
%10 = tail call i64 @list_empty(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %4, %8
%13 = tail call i32 @graph_node_mark_resolved(%struct.graph* %0, %struct.graph_node* %5)
%14 = tail call %struct.graph_node* @graph_get_ready_node(%struct.graph* %0)
%15 = icmp eq %struct.graph_node* %14, null
br i1 %15, label %16, label %4
16: ; preds = %8, %12, %1
%17 = phi %struct.graph_node* [ null, %1 ], [ null, %12 ], [ %5, %8 ]
ret %struct.graph_node* %17
}