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

/* Variables and functions */
int /*<<< orphan*/ add_dependencies(struct graph *, struct list *,
                                    struct list *);
int /*<<< orphan*/ destroy_strings_in_list(struct list *);
scalar_t__ expand_macros(struct string const *, struct dict *, struct string *);
size_t find(struct string *, char);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ get_token_list(struct string *, struct list *);
int /*<<< orphan*/ is_blank(char const);
int /*<<< orphan*/ list_destroy(struct list *);
struct list *list_init();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ string_destroy(struct string *);
char *string_get_cstr(struct string *);
size_t string_get_size(struct string *);
struct string *string_init(char *);
struct string *string_init_substring(struct string *, size_t, size_t);
int load_rule(const struct string *line, struct dict *macros,
              struct graph *graph, struct list *targets_list) {
  struct string *expanded = string_init("");
  const char *expanded_cstr;
  size_t expanded_size;
  if (expand_macros(line, macros, expanded)) {
    string_destroy(expanded);
    return (-1);
  }
  expanded_cstr = string_get_cstr(expanded);
  expanded_size = string_get_size(expanded);
  {
    int empty = 1;
    size_t i;
    for (i = 0; i < expanded_size; ++i) {
      if (!is_blank(expanded_cstr[i])) {
        empty = 0;
        break;
      }
    }
    if (empty) {
      string_destroy(expanded);
      return (0);
    }
  }
  {
    struct string *targets;
    struct string *dependencies;
    size_t at = find(expanded, ':');
    struct list *dependencies_list;
    if (expanded_cstr[at] != ':') {
      fprintf(stderr, "Separator not found\n");
      string_destroy(expanded);
      return (-1);
    }
    targets = string_init_substring(expanded, 0, at);
    dependencies =
        string_init_substring(expanded, at + 1, expanded_size - at - 1);
    dependencies_list = list_init();
    get_token_list(targets, targets_list);
    get_token_list(dependencies, dependencies_list);
    add_dependencies(graph, targets_list, dependencies_list);
    destroy_strings_in_list(dependencies_list);
    list_destroy(dependencies_list);
    string_destroy(dependencies);
    string_destroy(targets);
  }
  string_destroy(expanded);
  return (0);
}


x86 assembly (clang, -O0):
<load_rule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    0xe15(%rip),%rdi
call   1040 <string_init@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   10f0 <expand_macros@plt>
cmp    $0x0,%rax
je     1238 <load_rule+0x58>
mov    -0x30(%rbp),%rdi
call   1050 <string_destroy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13bb <load_rule+0x1db>
mov    -0x30(%rbp),%rdi
call   1100 <string_get_cstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <string_get_size@plt>
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    12ab <load_rule+0xcb>
mov    -0x38(%rbp),%rax
mov    -0x50(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   10b0 <is_blank@plt>
cmp    $0x0,%eax
jne    1295 <load_rule+0xb5>
movl   $0x0,-0x44(%rbp)
jmp    12ab <load_rule+0xcb>
jmp    129a <load_rule+0xba>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1261 <load_rule+0x81>
cmpl   $0x0,-0x44(%rbp)
je     12ca <load_rule+0xea>
mov    -0x30(%rbp),%rdi
call   1050 <string_destroy@plt>
movl   $0x0,-0x4(%rbp)
jmp    13bb <load_rule+0x1db>
mov    -0x30(%rbp),%rdi
mov    $0x3a,%esi
call   10a0 <find@plt>
mov    %rax,-0x68(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x68(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
je     131b <load_rule+0x13b>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
lea    0xcff(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <string_destroy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13bb <load_rule+0x1db>
mov    -0x30(%rbp),%rdi
mov    -0x68(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <string_init_substring@plt>
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x68(%rbp),%rsi
add    $0x1,%rsi
mov    -0x40(%rbp),%rdx
sub    -0x68(%rbp),%rdx
sub    $0x1,%rdx
call   10c0 <string_init_substring@plt>
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1080 <list_init@plt>
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10e0 <get_token_list@plt>
mov    -0x60(%rbp),%rdi
mov    -0x70(%rbp),%rsi
call   10e0 <get_token_list@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x70(%rbp),%rdx
call   1030 <add_dependencies@plt>
mov    -0x70(%rbp),%rdi
call   10d0 <destroy_strings_in_list@plt>
mov    -0x70(%rbp),%rdi
call   1060 <list_destroy@plt>
mov    -0x60(%rbp),%rdi
call   1050 <string_destroy@plt>
mov    -0x58(%rbp),%rdi
call   1050 <string_destroy@plt>
mov    -0x30(%rbp),%rdi
call   1050 <string_destroy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_rule>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe13(%rip),%rdi
call   1040 <string_init@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   10f0 <expand_macros@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
jne    132a <load_rule+0x14a>
mov    %r15,0x10(%rsp)
mov    %r13,%rdi
call   1100 <string_get_cstr@plt>
mov    %rax,%rbp
mov    %r13,%rdi
call   1070 <string_get_size@plt>
test   %rax,%rax
je     1267 <load_rule+0x87>
mov    %rax,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%rbp,%rbx,1),%edi
call   10b0 <is_blank@plt>
test   %eax,%eax
je     126f <load_rule+0x8f>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1250 <load_rule+0x70>
xor    %r14d,%r14d
jmp    132a <load_rule+0x14a>
mov    %r12,0x8(%rsp)
mov    %r13,%rdi
mov    $0x3a,%esi
call   10a0 <find@plt>
cmpb   $0x3a,0x0(%rbp,%rax,1)
jne    1315 <load_rule+0x135>
mov    %rax,%r12
xor    %r14d,%r14d
mov    %r13,%rdi
xor    %esi,%esi
mov    %rax,%rdx
call   10c0 <string_init_substring@plt>
mov    %rax,%rbx
lea    0x1(%r12),%rsi
not    %r12
add    %r12,%r15
mov    %r13,%rdi
mov    %r15,%rdx
call   10c0 <string_init_substring@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <list_init@plt>
mov    %rax,%rbp
mov    %rbx,%r12
mov    %rbx,%rdi
mov    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   10e0 <get_token_list@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10e0 <get_token_list@plt>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <add_dependencies@plt>
mov    %rbp,%rdi
call   10d0 <destroy_strings_in_list@plt>
mov    %rbp,%rdi
call   1060 <list_destroy@plt>
mov    %r15,%rdi
call   1050 <string_destroy@plt>
mov    %r12,%rdi
call   1050 <string_destroy@plt>
jmp    132a <load_rule+0x14a>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xcdb(%rip),%rsi
call   1090 <fprintf@plt>
mov    %r13,%rdi
call   1050 <string_destroy@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.string = type { i32 }
%struct.dict = type { i32 }
%struct.graph = type { i32 }
%struct.list = type { i32 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [21 x i8] c"Separator not found\0A\00"
define i32 @load_rule(%struct.string* %0, %struct.dict* %1, %struct.graph* %2, %struct.list* %3) {
%5 = alloca i32
%6 = alloca %struct.string*
%7 = alloca %struct.dict*
%8 = alloca %struct.graph*
%9 = alloca %struct.list*
%10 = alloca %struct.string*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i64
%15 = alloca %struct.string*
%16 = alloca %struct.string*
%17 = alloca i64
%18 = alloca %struct.list*
store %struct.string* %0, %struct.string** %6
store %struct.dict* %1, %struct.dict** %7
store %struct.graph* %2, %struct.graph** %8
store %struct.list* %3, %struct.list** %9
%19 = call %struct.string* @string_init(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store %struct.string* %19, %struct.string** %10
%20 = load %struct.string*, %struct.string** %6
%21 = load %struct.dict*, %struct.dict** %7
%22 = load %struct.string*, %struct.string** %10
%23 = call i64 @expand_macros(%struct.string* %20, %struct.dict* %21, %struct.string* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %4
%26 = load %struct.string*, %struct.string** %10
%27 = call i32 @string_destroy(%struct.string* %26)
store i32 -1, i32* %5
br label %102
28: ; preds = %4
%29 = load %struct.string*, %struct.string** %10
%30 = call i8* @string_get_cstr(%struct.string* %29)
store i8* %30, i8** %11
%31 = load %struct.string*, %struct.string** %10
%32 = call i64 @string_get_size(%struct.string* %31)
store i64 %32, i64* %12
store i32 1, i32* %13
store i64 0, i64* %14
br label %33
33: ; preds = %46, %28
%34 = load i64, i64* %14
%35 = load i64, i64* %12
%36 = icmp ult i64 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = load i8*, i8** %11
%39 = load i64, i64* %14
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @is_blank(i8 signext %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %37
store i32 0, i32* %13
br label %49
45: ; preds = %37
br label %46
46: ; preds = %45
%47 = load i64, i64* %14
%48 = add i64 %47, 1
store i64 %48, i64* %14
br label %33
49: ; preds = %44, %33
%50 = load i32, i32* %13
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load %struct.string*, %struct.string** %10
%54 = call i32 @string_destroy(%struct.string* %53)
store i32 0, i32* %5
br label %102
55: ; preds = %49
%56 = load %struct.string*, %struct.string** %10
%57 = call i64 @find(%struct.string* %56, i8 signext 58)
store i64 %57, i64* %17
%58 = load i8*, i8** %11
%59 = load i64, i64* %17
%60 = getelementptr inbounds i8, i8* %58, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 58
br i1 %63, label %64, label %69
64: ; preds = %55
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%67 = load %struct.string*, %struct.string** %10
%68 = call i32 @string_destroy(%struct.string* %67)
store i32 -1, i32* %5
br label %102
69: ; preds = %55
%70 = load %struct.string*, %struct.string** %10
%71 = load i64, i64* %17
%72 = call %struct.string* @string_init_substring(%struct.string* %70, i64 0, i64 %71)
store %struct.string* %72, %struct.string** %15
%73 = load %struct.string*, %struct.string** %10
%74 = load i64, i64* %17
%75 = add i64 %74, 1
%76 = load i64, i64* %12
%77 = load i64, i64* %17
%78 = sub i64 %76, %77
%79 = sub i64 %78, 1
%80 = call %struct.string* @string_init_substring(%struct.string* %73, i64 %75, i64 %79)
store %struct.string* %80, %struct.string** %16
%81 = call %struct.list* (...) @list_init()
store %struct.list* %81, %struct.list** %18
%82 = load %struct.string*, %struct.string** %15
%83 = load %struct.list*, %struct.list** %9
%84 = call i32 @get_token_list(%struct.string* %82, %struct.list* %83)
%85 = load %struct.string*, %struct.string** %16
%86 = load %struct.list*, %struct.list** %18
%87 = call i32 @get_token_list(%struct.string* %85, %struct.list* %86)
%88 = load %struct.graph*, %struct.graph** %8
%89 = load %struct.list*, %struct.list** %9
%90 = load %struct.list*, %struct.list** %18
%91 = call i32 @add_dependencies(%struct.graph* %88, %struct.list* %89, %struct.list* %90)
%92 = load %struct.list*, %struct.list** %18
%93 = call i32 @destroy_strings_in_list(%struct.list* %92)
%94 = load %struct.list*, %struct.list** %18
%95 = call i32 @list_destroy(%struct.list* %94)
%96 = load %struct.string*, %struct.string** %16
%97 = call i32 @string_destroy(%struct.string* %96)
%98 = load %struct.string*, %struct.string** %15
%99 = call i32 @string_destroy(%struct.string* %98)
%100 = load %struct.string*, %struct.string** %10
%101 = call i32 @string_destroy(%struct.string* %100)
store i32 0, i32* %5
br label %102
102: ; preds = %69, %64, %52, %25
%103 = load i32, i32* %5
ret i32 %103
}

LLVM IR (-O2):
%struct.string = type { i32 }
%struct.dict = type { i32 }
%struct.graph = type { i32 }
%struct.list = type { i32 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [21 x i8] c"Separator not found\0A\00"
define i32 @load_rule(%struct.string* %0, %struct.dict* %1, %struct.graph* %2, %struct.list* %3) {
%5 = tail call %struct.string* @string_init(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @expand_macros(%struct.string* %0, %struct.dict* %1, %struct.string* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %43
8: ; preds = %4
%9 = tail call i8* @string_get_cstr(%struct.string* %5)
%10 = tail call i64 @string_get_size(%struct.string* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %43, label %14
12: ; preds = %14
%13 = icmp eq i64 %20, %10
br i1 %13, label %43, label %14
14: ; preds = %8, %12
%15 = phi i64 [ %20, %12 ], [ 0, %8 ]
%16 = getelementptr inbounds i8, i8* %9, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @is_blank(i8 signext %17)
%19 = icmp eq i32 %18, 0
%20 = add nuw i64 %15, 1
br i1 %19, label %21, label %12
21: ; preds = %14
%22 = tail call i64 @find(%struct.string* %5, i8 signext 58)
%23 = getelementptr inbounds i8, i8* %9, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 58
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %43
29: ; preds = %21
%30 = tail call %struct.string* @string_init_substring(%struct.string* %5, i64 0, i64 %22)
%31 = add i64 %22, 1
%32 = xor i64 %22, -1
%33 = add i64 %10, %32
%34 = tail call %struct.string* @string_init_substring(%struct.string* %5, i64 %31, i64 %33)
%35 = tail call %struct.list* (...) @list_init()
%36 = tail call i32 @get_token_list(%struct.string* %30, %struct.list* %3)
%37 = tail call i32 @get_token_list(%struct.string* %34, %struct.list* %35)
%38 = tail call i32 @add_dependencies(%struct.graph* %2, %struct.list* %3, %struct.list* %35)
%39 = tail call i32 @destroy_strings_in_list(%struct.list* %35)
%40 = tail call i32 @list_destroy(%struct.list* %35)
%41 = tail call i32 @string_destroy(%struct.string* %34)
%42 = tail call i32 @string_destroy(%struct.string* %30)
br label %43
43: ; preds = %12, %8, %4, %26, %29
%44 = phi i32 [ 0, %29 ], [ -1, %26 ], [ -1, %4 ], [ 0, %8 ], [ 0, %12 ]
%45 = tail call i32 @string_destroy(%struct.string* %5)
ret i32 %44
}