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

/* Variables and functions */
int /*<<< orphan*/ escape_command(struct string const *, struct string *);
struct graph_node *get_or_add_node(struct graph *, struct string *);
int /*<<< orphan*/ graph_node_add_command(struct graph_node *, struct string *);
struct string *list_get_data(struct list_item *);
struct list_item *list_head(struct list *);
struct list_item *list_next(struct list_item *);
int /*<<< orphan*/ string_destroy(struct string *);
struct string *string_init(char *);
void add_command(struct graph *graph, struct list *targets,
                 const struct string *command) {
  struct list_item *item = list_head(targets);
  struct string *escaped = string_init("");
  escape_command(command, escaped);
  while (item != NULL) {
    struct string *node_name = list_get_data(item);
    struct graph_node *node = get_or_add_node(graph, node_name);
    graph_node_add_command(node, escaped);
    item = list_next(item);
  }
  string_destroy(escaped);
}


x86 assembly (clang, -O0):
<add_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <list_head@plt>
mov    %rax,-0x20(%rbp)
lea    0xe58(%rip),%rdi
call   1040 <string_init@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <escape_command@plt>
cmpq   $0x0,-0x20(%rbp)
je     1206 <add_command+0x86>
mov    -0x20(%rbp),%rdi
call   1060 <list_get_data@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <get_or_add_node@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <graph_node_add_command@plt>
mov    -0x20(%rbp),%rdi
call   1070 <list_next@plt>
mov    %rax,-0x20(%rbp)
jmp    11be <add_command+0x3e>
mov    -0x28(%rbp),%rdi
call   1050 <string_destroy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_command>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1080 <list_head@plt>
mov    %rax,%rbx
lea    0xe60(%rip),%rdi
call   1040 <string_init@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <escape_command@plt>
test   %rbx,%rbx
je     11ee <add_command+0x6e>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <list_get_data@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   10a0 <get_or_add_node@plt>
mov    %rax,%rdi
mov    %r15,%rsi
call   1090 <graph_node_add_command@plt>
mov    %rbx,%rdi
call   1070 <list_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <add_command+0x40>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <string_destroy@plt>

LLVM IR (-O0):
%struct.graph = type { i32 }
%struct.list = type { i32 }
%struct.string = type { i32 }
%struct.list_item = type { i32 }
%struct.graph_node = type { i32 }
@.str = [1 x i8] zeroinitializer
define void @add_command(%struct.graph* %0, %struct.list* %1, %struct.string* %2) {
%4 = alloca %struct.graph*
%5 = alloca %struct.list*
%6 = alloca %struct.string*
%7 = alloca %struct.list_item*
%8 = alloca %struct.string*
%9 = alloca %struct.string*
%10 = alloca %struct.graph_node*
store %struct.graph* %0, %struct.graph** %4
store %struct.list* %1, %struct.list** %5
store %struct.string* %2, %struct.string** %6
%11 = load %struct.list*, %struct.list** %5
%12 = call %struct.list_item* @list_head(%struct.list* %11)
store %struct.list_item* %12, %struct.list_item** %7
%13 = call %struct.string* @string_init(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store %struct.string* %13, %struct.string** %8
%14 = load %struct.string*, %struct.string** %6
%15 = load %struct.string*, %struct.string** %8
%16 = call i32 @escape_command(%struct.string* %14, %struct.string* %15)
br label %17
17: ; preds = %20, %3
%18 = load %struct.list_item*, %struct.list_item** %7
%19 = icmp ne %struct.list_item* %18, null
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = load %struct.list_item*, %struct.list_item** %7
%22 = call %struct.string* @list_get_data(%struct.list_item* %21)
store %struct.string* %22, %struct.string** %9
%23 = load %struct.graph*, %struct.graph** %4
%24 = load %struct.string*, %struct.string** %9
%25 = call %struct.graph_node* @get_or_add_node(%struct.graph* %23, %struct.string* %24)
store %struct.graph_node* %25, %struct.graph_node** %10
%26 = load %struct.graph_node*, %struct.graph_node** %10
%27 = load %struct.string*, %struct.string** %8
%28 = call i32 @graph_node_add_command(%struct.graph_node* %26, %struct.string* %27)
%29 = load %struct.list_item*, %struct.list_item** %7
%30 = call %struct.list_item* @list_next(%struct.list_item* %29)
store %struct.list_item* %30, %struct.list_item** %7
br label %17
31: ; preds = %17
%32 = load %struct.string*, %struct.string** %8
%33 = call i32 @string_destroy(%struct.string* %32)
ret void
}

LLVM IR (-O2):
%struct.graph = type { i32 }
%struct.list = type { i32 }
%struct.string = type { i32 }
%struct.list_item = type { i32 }
%struct.graph_node = type { i32 }
@.str = [1 x i8] zeroinitializer
define void @add_command(%struct.graph* %0, %struct.list* %1, %struct.string* %2) {
%4 = tail call %struct.list_item* @list_head(%struct.list* %1)
%5 = tail call %struct.string* @string_init(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @escape_command(%struct.string* %2, %struct.string* %5)
%7 = icmp eq %struct.list_item* %4, null
br i1 %7, label %15, label %8
8: ; preds = %3, %8
%9 = phi %struct.list_item* [ %13, %8 ], [ %4, %3 ]
%10 = tail call %struct.string* @list_get_data(%struct.list_item* %9)
%11 = tail call %struct.graph_node* @get_or_add_node(%struct.graph* %0, %struct.string* %10)
%12 = tail call i32 @graph_node_add_command(%struct.graph_node* %11, %struct.string* %5)
%13 = tail call %struct.list_item* @list_next(%struct.list_item* %9)
%14 = icmp eq %struct.list_item* %13, null
br i1 %14, label %15, label %8
15: ; preds = %8, %3
%16 = tail call i32 @string_destroy(%struct.string* %5)
ret void
}