#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 mdea_parser {
  int dummy;
};
struct mdea_output {
  int dummy;
};
struct mdea_node {
  int dummy;
};
struct mdea_emitter {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ mdea_emitter_destroy(struct mdea_emitter *);
struct mdea_emitter *mdea_json_emitter(struct mdea_output *);
struct mdea_parser *mdea_node_parser(struct mdea_node *);
int /*<<< orphan*/ mdea_output_destroy(struct mdea_output *);
int mdea_parse(struct mdea_parser *, struct mdea_emitter *, char **);
int /*<<< orphan*/ mdea_parser_destroy(struct mdea_parser *);
struct mdea_output *mdea_string_output(char **, size_t *);
int mdea_node_to_string(struct mdea_node *node, char **str, size_t *len,
                        char **error) {
  struct mdea_parser *p = mdea_node_parser(node);
  struct mdea_output *o = mdea_string_output(str, len);
  struct mdea_emitter *e = mdea_json_emitter(o);
  int ret = mdea_parse(p, e, error);
  mdea_parser_destroy(p);
  mdea_emitter_destroy(e);
  mdea_output_destroy(o);
  return ret;
}


x86 assembly (clang, -O0):
<mdea_node_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <mdea_node_parser@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <mdea_string_output@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <mdea_json_emitter@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <mdea_parse@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <mdea_parser_destroy@plt>
mov    -0x38(%rbp),%rdi
call   1090 <mdea_emitter_destroy@plt>
mov    -0x30(%rbp),%rdi
call   1050 <mdea_output_destroy@plt>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdea_node_to_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
call   1070 <mdea_node_parser@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %r15,%rsi
call   1080 <mdea_string_output@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <mdea_json_emitter@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <mdea_parse@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1040 <mdea_parser_destroy@plt>
mov    %rbx,%rdi
call   1090 <mdea_emitter_destroy@plt>
mov    %r15,%rdi
call   1050 <mdea_output_destroy@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mdea_node = type { i32 }
%struct.mdea_parser = type { i32 }
%struct.mdea_output = type { i32 }
%struct.mdea_emitter = type { i32 }
define i32 @mdea_node_to_string(%struct.mdea_node* %0, i8** %1, i64* %2, i8** %3) {
%5 = alloca %struct.mdea_node*
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i8**
%9 = alloca %struct.mdea_parser*
%10 = alloca %struct.mdea_output*
%11 = alloca %struct.mdea_emitter*
%12 = alloca i32
store %struct.mdea_node* %0, %struct.mdea_node** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
store i8** %3, i8*** %8
%13 = load %struct.mdea_node*, %struct.mdea_node** %5
%14 = call %struct.mdea_parser* @mdea_node_parser(%struct.mdea_node* %13)
store %struct.mdea_parser* %14, %struct.mdea_parser** %9
%15 = load i8**, i8*** %6
%16 = load i64*, i64** %7
%17 = call %struct.mdea_output* @mdea_string_output(i8** %15, i64* %16)
store %struct.mdea_output* %17, %struct.mdea_output** %10
%18 = load %struct.mdea_output*, %struct.mdea_output** %10
%19 = call %struct.mdea_emitter* @mdea_json_emitter(%struct.mdea_output* %18)
store %struct.mdea_emitter* %19, %struct.mdea_emitter** %11
%20 = load %struct.mdea_parser*, %struct.mdea_parser** %9
%21 = load %struct.mdea_emitter*, %struct.mdea_emitter** %11
%22 = load i8**, i8*** %8
%23 = call i32 @mdea_parse(%struct.mdea_parser* %20, %struct.mdea_emitter* %21, i8** %22)
store i32 %23, i32* %12
%24 = load %struct.mdea_parser*, %struct.mdea_parser** %9
%25 = call i32 @mdea_parser_destroy(%struct.mdea_parser* %24)
%26 = load %struct.mdea_emitter*, %struct.mdea_emitter** %11
%27 = call i32 @mdea_emitter_destroy(%struct.mdea_emitter* %26)
%28 = load %struct.mdea_output*, %struct.mdea_output** %10
%29 = call i32 @mdea_output_destroy(%struct.mdea_output* %28)
%30 = load i32, i32* %12
ret i32 %30
}

LLVM IR (-O2):
%struct.mdea_node = type { i32 }
%struct.mdea_parser = type { i32 }
%struct.mdea_output = type { i32 }
%struct.mdea_emitter = type { i32 }
define i32 @mdea_node_to_string(%struct.mdea_node* %0, i8** %1, i64* %2, i8** %3) {
%5 = tail call %struct.mdea_parser* @mdea_node_parser(%struct.mdea_node* %0)
%6 = tail call %struct.mdea_output* @mdea_string_output(i8** %1, i64* %2)
%7 = tail call %struct.mdea_emitter* @mdea_json_emitter(%struct.mdea_output* %6)
%8 = tail call i32 @mdea_parse(%struct.mdea_parser* %5, %struct.mdea_emitter* %7, i8** %3)
%9 = tail call i32 @mdea_parser_destroy(%struct.mdea_parser* %5)
%10 = tail call i32 @mdea_emitter_destroy(%struct.mdea_emitter* %7)
%11 = tail call i32 @mdea_output_destroy(%struct.mdea_output* %6)
ret i32 %8
}