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

/* Variables and functions */
int /*<<< orphan*/ cJSON_Delete(struct cJSON *);
char *cJSON_GetErrorPtr();
struct cJSON *cJSON_Parse(char *);
char *cJSON_Print(struct cJSON *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
void doit(char *text) {
  char *out;
  struct cJSON *json;
  json = cJSON_Parse(text);
  if (!json) {
    printf("Error before: [%s]\n", cJSON_GetErrorPtr());
  } else {
    out = cJSON_Print(json);
    cJSON_Delete(json);
    printf("%s\n", out);
    free(out);
  }
}


x86 assembly (clang, -O0):
<doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <cJSON_Parse@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119f <doit+0x3f>
mov    $0x0,%al
call   1080 <cJSON_GetErrorPtr@plt>
mov    %rax,%rsi
lea    0xe6b(%rip),%rdi
call   1060 <printf@plt>
jmp    11ce <doit+0x6e>
mov    -0x18(%rbp),%rdi
call   1040 <cJSON_Print@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <cJSON_Delete@plt>
mov    -0x10(%rbp),%rsi
lea    0xe54(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doit>:
push   %r14
push   %rbx
push   %rax
call   1070 <cJSON_Parse@plt>
test   %rax,%rax
je     11a2 <doit+0x42>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <cJSON_Print@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <cJSON_Delete@plt>
lea    0xe89(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
xor    %eax,%eax
call   1080 <cJSON_GetErrorPtr@plt>
lea    0xe50(%rip),%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <printf@plt>

LLVM IR (-O0):
%struct.cJSON = type { i32 }
@.str = [20 x i8] c"Error before: [%s]\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @doit(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.cJSON*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call %struct.cJSON* @cJSON_Parse(i8* %5)
store %struct.cJSON* %6, %struct.cJSON** %4
%7 = load %struct.cJSON*, %struct.cJSON** %4
%8 = icmp ne %struct.cJSON* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i8* (...) @cJSON_GetErrorPtr()
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %21
12: ; preds = %1
%13 = load %struct.cJSON*, %struct.cJSON** %4
%14 = call i8* @cJSON_Print(%struct.cJSON* %13)
store i8* %14, i8** %3
%15 = load %struct.cJSON*, %struct.cJSON** %4
%16 = call i32 @cJSON_Delete(%struct.cJSON* %15)
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
br label %21
21: ; preds = %12, %9
ret void
}

LLVM IR (-O2):
%struct.cJSON = type { i32 }
@.str = [20 x i8] c"Error before: [%s]\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @doit(i8* %0) {
%2 = tail call %struct.cJSON* @cJSON_Parse(i8* %0)
%3 = icmp eq %struct.cJSON* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i8* (...) @cJSON_GetErrorPtr()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %12
7: ; preds = %1
%8 = tail call i8* @cJSON_Print(%struct.cJSON* %2)
%9 = tail call i32 @cJSON_Delete(%struct.cJSON* %2)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%11 = tail call i32 @free(i8* %8)
br label %12
12: ; preds = %7, %4
ret void
}