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

/* Variables and functions */
int /*<<< orphan*/ graph_add_node(struct graph *, struct graph_node *);
struct graph_node *graph_get_node_by_name(struct graph *,
                                          struct string const *);
struct graph_node *graph_node_init(struct string const *);
struct graph_node *get_or_add_node(struct graph *graph,
                                   const struct string *name) {
  struct graph_node *node;
  node = graph_get_node_by_name(graph, name);
  if (node == NULL) {
    node = graph_node_init(name);
    graph_add_node(graph, node);
  }
  return (node);
}


x86 assembly (clang, -O0):
<get_or_add_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <graph_get_node_by_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1176 <get_or_add_node+0x46>
mov    -0x10(%rbp),%rdi
call   1040 <graph_node_init@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <graph_add_node@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_or_add_node>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <graph_get_node_by_name@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115e <get_or_add_node+0x2e>
mov    %r15,%rdi
call   1040 <graph_node_init@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <graph_add_node@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.graph_node = type { i32 }
%struct.graph = type { i32 }
%struct.string = type { i32 }
define %struct.graph_node* @get_or_add_node(%struct.graph* %0, %struct.string* %1) {
%3 = alloca %struct.graph*
%4 = alloca %struct.string*
%5 = alloca %struct.graph_node*
store %struct.graph* %0, %struct.graph** %3
store %struct.string* %1, %struct.string** %4
%6 = load %struct.graph*, %struct.graph** %3
%7 = load %struct.string*, %struct.string** %4
%8 = call %struct.graph_node* @graph_get_node_by_name(%struct.graph* %6, %struct.string* %7)
store %struct.graph_node* %8, %struct.graph_node** %5
%9 = load %struct.graph_node*, %struct.graph_node** %5
%10 = icmp eq %struct.graph_node* %9, null
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load %struct.string*, %struct.string** %4
%13 = call %struct.graph_node* @graph_node_init(%struct.string* %12)
store %struct.graph_node* %13, %struct.graph_node** %5
%14 = load %struct.graph*, %struct.graph** %3
%15 = load %struct.graph_node*, %struct.graph_node** %5
%16 = call i32 @graph_add_node(%struct.graph* %14, %struct.graph_node* %15)
br label %17
17: ; preds = %11, %2
%18 = load %struct.graph_node*, %struct.graph_node** %5
ret %struct.graph_node* %18
}

LLVM IR (-O2):
%struct.graph_node = type { i32 }
%struct.graph = type { i32 }
%struct.string = type { i32 }
define %struct.graph_node* @get_or_add_node(%struct.graph* %0, %struct.string* %1) {
%3 = tail call %struct.graph_node* @graph_get_node_by_name(%struct.graph* %0, %struct.string* %1)
%4 = icmp eq %struct.graph_node* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call %struct.graph_node* @graph_node_init(%struct.string* %1)
%7 = tail call i32 @graph_add_node(%struct.graph* %0, %struct.graph_node* %6)
br label %8
8: ; preds = %5, %2
%9 = phi %struct.graph_node* [ %6, %5 ], [ %3, %2 ]
ret %struct.graph_node* %9
}