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

/* Variables and functions */
int /*<<< orphan*/ dict_set(struct dict *, struct string *, struct string *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t nonblank_begin(char const *, size_t, size_t);
size_t nonblank_end(char const *, size_t, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ string_destroy(struct string *);
char *string_get_cstr(struct string const *);
size_t string_get_size(struct string const *);
struct string *string_init_substring(struct string const *, size_t, size_t);
int load_macro(const struct string *line, size_t at, struct dict *macros) {
  struct string *name;
  struct string *value;
  size_t name_begin = 0;
  size_t name_end = at;
  size_t value_begin = at + 1;
  size_t value_end = string_get_size(line);
  const char *line_cstr = string_get_cstr(line);
  name_begin = nonblank_begin(line_cstr, name_begin, name_end);
  name_end = nonblank_end(line_cstr, name_begin, name_end);
  if (name_begin == name_end) {
    fprintf(stderr, "Empty macro name\n");
    return (-1);
  }
  name = string_init_substring(line, name_begin, name_end - name_begin);
  value_begin = nonblank_begin(line_cstr, value_begin, value_end);
  value_end = nonblank_end(line_cstr, value_begin, value_end);
  value = string_init_substring(line, value_begin, value_end - value_begin);
  dict_set(macros, name, value);
  string_destroy(value);
  string_destroy(name);
  return (0);
}


x86 assembly (clang, -O0):
<load_macro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <string_get_size@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <string_get_cstr@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1030 <nonblank_begin@plt>
mov    %rax,-0x38(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1040 <nonblank_end@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jne    1223 <load_macro+0xa3>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a9 <load_macro+0x129>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
sub    -0x38(%rbp),%rdx
call   1090 <string_init_substring@plt>
mov    %rax,-0x28(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1030 <nonblank_begin@plt>
mov    %rax,-0x48(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1040 <nonblank_end@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
sub    -0x48(%rbp),%rdx
call   1090 <string_init_substring@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1080 <dict_set@plt>
mov    -0x30(%rbp),%rdi
call   1050 <string_destroy@plt>
mov    -0x28(%rbp),%rdi
call   1050 <string_destroy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_macro>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r13
call   1060 <string_get_size@plt>
mov    %rax,%r12
mov    %r13,%rdi
call   10a0 <string_get_cstr@plt>
mov    %rax,%r14
xor    %r15d,%r15d
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <nonblank_begin@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <nonblank_end@plt>
sub    %rbp,%rax
jne    11eb <load_macro+0x6b>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%r15d
jmp    1252 <load_macro+0xd2>
add    $0x1,%rbx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1090 <string_init_substring@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <nonblank_begin@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
call   1040 <nonblank_end@plt>
sub    %rbx,%rax
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1090 <string_init_substring@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1080 <dict_set@plt>
mov    %rbx,%rdi
call   1050 <string_destroy@plt>
mov    %rbp,%rdi
call   1050 <string_destroy@plt>
mov    %r15d,%eax
add    $0x8,%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 }
@stderr = global i32 0
@.str = [18 x i8] c"Empty macro name\0A\00"
define i32 @load_macro(%struct.string* %0, i64 %1, %struct.dict* %2) {
%4 = alloca i32
%5 = alloca %struct.string*
%6 = alloca i64
%7 = alloca %struct.dict*
%8 = alloca %struct.string*
%9 = alloca %struct.string*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
store %struct.string* %0, %struct.string** %5
store i64 %1, i64* %6
store %struct.dict* %2, %struct.dict** %7
store i64 0, i64* %10
%15 = load i64, i64* %6
store i64 %15, i64* %11
%16 = load i64, i64* %6
%17 = add i64 %16, 1
store i64 %17, i64* %12
%18 = load %struct.string*, %struct.string** %5
%19 = call i64 @string_get_size(%struct.string* %18)
store i64 %19, i64* %13
%20 = load %struct.string*, %struct.string** %5
%21 = call i8* @string_get_cstr(%struct.string* %20)
store i8* %21, i8** %14
%22 = load i8*, i8** %14
%23 = load i64, i64* %10
%24 = load i64, i64* %11
%25 = call i64 @nonblank_begin(i8* %22, i64 %23, i64 %24)
store i64 %25, i64* %10
%26 = load i8*, i8** %14
%27 = load i64, i64* %10
%28 = load i64, i64* %11
%29 = call i64 @nonblank_end(i8* %26, i64 %27, i64 %28)
store i64 %29, i64* %11
%30 = load i64, i64* %10
%31 = load i64, i64* %11
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %3
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %65
36: ; preds = %3
%37 = load %struct.string*, %struct.string** %5
%38 = load i64, i64* %10
%39 = load i64, i64* %11
%40 = load i64, i64* %10
%41 = sub i64 %39, %40
%42 = call %struct.string* @string_init_substring(%struct.string* %37, i64 %38, i64 %41)
store %struct.string* %42, %struct.string** %8
%43 = load i8*, i8** %14
%44 = load i64, i64* %12
%45 = load i64, i64* %13
%46 = call i64 @nonblank_begin(i8* %43, i64 %44, i64 %45)
store i64 %46, i64* %12
%47 = load i8*, i8** %14
%48 = load i64, i64* %12
%49 = load i64, i64* %13
%50 = call i64 @nonblank_end(i8* %47, i64 %48, i64 %49)
store i64 %50, i64* %13
%51 = load %struct.string*, %struct.string** %5
%52 = load i64, i64* %12
%53 = load i64, i64* %13
%54 = load i64, i64* %12
%55 = sub i64 %53, %54
%56 = call %struct.string* @string_init_substring(%struct.string* %51, i64 %52, i64 %55)
store %struct.string* %56, %struct.string** %9
%57 = load %struct.dict*, %struct.dict** %7
%58 = load %struct.string*, %struct.string** %8
%59 = load %struct.string*, %struct.string** %9
%60 = call i32 @dict_set(%struct.dict* %57, %struct.string* %58, %struct.string* %59)
%61 = load %struct.string*, %struct.string** %9
%62 = call i32 @string_destroy(%struct.string* %61)
%63 = load %struct.string*, %struct.string** %8
%64 = call i32 @string_destroy(%struct.string* %63)
store i32 0, i32* %4
br label %65
65: ; preds = %36, %33
%66 = load i32, i32* %4
ret i32 %66
}

LLVM IR (-O2):
%struct.string = type { i32 }
%struct.dict = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Empty macro name\0A\00"
define i32 @load_macro(%struct.string* %0, i64 %1, %struct.dict* %2) {
%4 = tail call i64 @string_get_size(%struct.string* %0)
%5 = tail call i8* @string_get_cstr(%struct.string* %0)
%6 = tail call i64 @nonblank_begin(i8* %5, i64 0, i64 %1)
%7 = tail call i64 @nonblank_end(i8* %5, i64 %6, i64 %1)
%8 = icmp eq i64 %7, %6
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %23
12: ; preds = %3
%13 = add i64 %1, 1
%14 = sub i64 %7, %6
%15 = tail call %struct.string* @string_init_substring(%struct.string* %0, i64 %6, i64 %14)
%16 = tail call i64 @nonblank_begin(i8* %5, i64 %13, i64 %4)
%17 = tail call i64 @nonblank_end(i8* %5, i64 %16, i64 %4)
%18 = sub i64 %17, %16
%19 = tail call %struct.string* @string_init_substring(%struct.string* %0, i64 %16, i64 %18)
%20 = tail call i32 @dict_set(%struct.dict* %2, %struct.string* %15, %struct.string* %19)
%21 = tail call i32 @string_destroy(%struct.string* %19)
%22 = tail call i32 @string_destroy(%struct.string* %15)
br label %23
23: ; preds = %12, %9
%24 = phi i32 [ -1, %9 ], [ 0, %12 ]
ret i32 %24
}