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

/* Variables and functions */
char *json_parse_value(struct rte_json *, int /*<<< orphan*/);
int /*<<< orphan*/ json_skip(char const *);
struct rte_json *new_json_item();
int /*<<< orphan*/ rte_destroy_json(struct rte_json *);
struct rte_json *rte_parse_json(const char *str) {
  const char *end = NULL;
  struct rte_json *json = NULL;
  json = new_json_item();
  if (NULL == json) {
    return NULL;
  }
  end = json_parse_value(json, json_skip(str));
  if (NULL == end) {
    rte_destroy_json(json);
    return NULL;
  }
  return json;
}


x86 assembly (clang, -O0):
<rte_parse_json>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <new_json_item@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1180 <rte_parse_json+0x40>
movq   $0x0,-0x8(%rbp)
jmp    11ca <rte_parse_json+0x8a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <json_skip@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1060 <json_parse_value@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11c2 <rte_parse_json+0x82>
mov    -0x20(%rbp),%rdi
call   1050 <rte_destroy_json@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ca <rte_parse_json+0x8a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rte_parse_json>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <new_json_item@plt>
test   %rax,%rax
je     1175 <rte_parse_json+0x35>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <json_skip@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <json_parse_value@plt>
test   %rax,%rax
jne    1177 <rte_parse_json+0x37>
mov    %rbx,%rdi
call   1050 <rte_destroy_json@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rte_json = type { i32 }
define %struct.rte_json* @rte_parse_json(i8* %0) {
%2 = alloca %struct.rte_json*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.rte_json*
store i8* %0, i8** %3
store i8* null, i8** %4
store %struct.rte_json* null, %struct.rte_json** %5
%6 = call %struct.rte_json* (...) @new_json_item()
store %struct.rte_json* %6, %struct.rte_json** %5
%7 = load %struct.rte_json*, %struct.rte_json** %5
%8 = icmp eq %struct.rte_json* null, %7
br i1 %8, label %9, label %10
9: ; preds = %1
store %struct.rte_json* null, %struct.rte_json** %2
br label %22
10: ; preds = %1
%11 = load %struct.rte_json*, %struct.rte_json** %5
%12 = load i8*, i8** %3
%13 = call i32 @json_skip(i8* %12)
%14 = call i8* @json_parse_value(%struct.rte_json* %11, i32 %13)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp eq i8* null, %15
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load %struct.rte_json*, %struct.rte_json** %5
%19 = call i32 @rte_destroy_json(%struct.rte_json* %18)
store %struct.rte_json* null, %struct.rte_json** %2
br label %22
20: ; preds = %10
%21 = load %struct.rte_json*, %struct.rte_json** %5
store %struct.rte_json* %21, %struct.rte_json** %2
br label %22
22: ; preds = %20, %17, %9
%23 = load %struct.rte_json*, %struct.rte_json** %2
ret %struct.rte_json* %23
}

LLVM IR (-O2):
%struct.rte_json = type { i32 }
define %struct.rte_json* @rte_parse_json(i8* %0) {
%2 = tail call %struct.rte_json* (...) @new_json_item()
%3 = icmp eq %struct.rte_json* %2, null
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i32 @json_skip(i8* %0)
%6 = tail call i8* @json_parse_value(%struct.rte_json* %2, i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @rte_destroy_json(%struct.rte_json* %2)
br label %10
10: ; preds = %4, %1, %8
%11 = phi %struct.rte_json* [ null, %8 ], [ null, %1 ], [ %2, %4 ]
ret %struct.rte_json* %11
}