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

/* Variables and functions */
int /*<<< orphan*/ SkipWhitespace(char const *, int);
int /*<<< orphan*/ *Turbo_Array(struct Turbo_Value *, char const *,
                                char const *);
int /*<<< orphan*/ Turbo_Error(struct Turbo_Value *, char const *, char *);
int /*<<< orphan*/ *Turbo_Object(struct Turbo_Value *, char const *,
                                 char const *);
int strlen(char const *);
int TurboJSON(struct Turbo_Value *to, const char *in, const char *end) {
  if (end == NULL) {
    end = in + strlen(in);
  }
  in += SkipWhitespace(in, end - in);
  if (*in == '[')
    return Turbo_Array(to, in, end) != NULL;
  if (*in == '{')
    return Turbo_Object(to, in, end) != NULL;
  Turbo_Error(to, in, "Expected Object or Array as root");
  return 0;
}


x86 assembly (clang, -O0):
<TurboJSON>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <TurboJSON+0x40>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1060 <SkipWhitespace@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    11eb <TurboJSON+0x9b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <Turbo_Array@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    123b <TurboJSON+0xeb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7b,%eax
jne    1220 <TurboJSON+0xd0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <Turbo_Object@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    123b <TurboJSON+0xeb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xdd1(%rip),%rdx
call   1070 <Turbo_Error@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TurboJSON>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdx,%rdx
jne    1171 <TurboJSON+0x21>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%r15
add    %rbx,%r15
mov    %r15d,%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1060 <SkipWhitespace@plt>
cltq
lea    (%rbx,%rax,1),%rsi
mov    (%rbx,%rax,1),%al
cmp    $0x7b,%al
je     119c <TurboJSON+0x4c>
cmp    $0x5b,%al
jne    11af <TurboJSON+0x5f>
mov    %r14,%rdi
mov    %r15,%rdx
call   1040 <Turbo_Array@plt>
jmp    11a7 <TurboJSON+0x57>
mov    %r14,%rdi
mov    %r15,%rdx
call   1050 <Turbo_Object@plt>
test   %rax,%rax
setne  %al
jmp    11c0 <TurboJSON+0x70>
lea    0xe4a(%rip),%rdx
mov    %r14,%rdi
call   1070 <Turbo_Error@plt>
xor    %eax,%eax
movzbl %al,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.Turbo_Value = type { i32 }
@.str = [33 x i8] c"Expected Object or Array as root\00"
define i32 @TurboJSON(%struct.Turbo_Value* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.Turbo_Value*
%6 = alloca i8*
%7 = alloca i8*
store %struct.Turbo_Value* %0, %struct.Turbo_Value** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
store i8* %15, i8** %7
br label %16
16: ; preds = %10, %3
%17 = load i8*, i8** %6
%18 = load i8*, i8** %7
%19 = load i8*, i8** %6
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = trunc i64 %22 to i32
%24 = call i32 @SkipWhitespace(i8* %17, i32 %23)
%25 = load i8*, i8** %6
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8* %27, i8** %6
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 91
br i1 %31, label %32, label %39
32: ; preds = %16
%33 = load %struct.Turbo_Value*, %struct.Turbo_Value** %5
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = call i32* @Turbo_Array(%struct.Turbo_Value* %33, i8* %34, i8* %35)
%37 = icmp ne i32* %36, null
%38 = zext i1 %37 to i32
store i32 %38, i32* %4
br label %55
39: ; preds = %16
%40 = load i8*, i8** %6
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 123
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = load %struct.Turbo_Value*, %struct.Turbo_Value** %5
%46 = load i8*, i8** %6
%47 = load i8*, i8** %7
%48 = call i32* @Turbo_Object(%struct.Turbo_Value* %45, i8* %46, i8* %47)
%49 = icmp ne i32* %48, null
%50 = zext i1 %49 to i32
store i32 %50, i32* %4
br label %55
51: ; preds = %39
%52 = load %struct.Turbo_Value*, %struct.Turbo_Value** %5
%53 = load i8*, i8** %6
%54 = call i32 @Turbo_Error(%struct.Turbo_Value* %52, i8* %53, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %55
55: ; preds = %51, %44, %32
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
%struct.Turbo_Value = type { i32 }
@.str = [33 x i8] c"Expected Object or Array as root\00"
define i32 @TurboJSON(%struct.Turbo_Value* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %1)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
br label %9
9: ; preds = %5, %3
%10 = phi i8* [ %8, %5 ], [ %2, %3 ]
%11 = ptrtoint i8* %10 to i64
%12 = ptrtoint i8* %1 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
%15 = tail call i32 @SkipWhitespace(i8* %1, i32 %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
switch i8 %18, label %25 [
i8 91, label %19
i8 123, label %22
]
19: ; preds = %9
%20 = tail call i32* @Turbo_Array(%struct.Turbo_Value* %0, i8* %17, i8* %10)
%21 = icmp ne i32* %20, null
br label %27
22: ; preds = %9
%23 = tail call i32* @Turbo_Object(%struct.Turbo_Value* %0, i8* %17, i8* %10)
%24 = icmp ne i32* %23, null
br label %27
25: ; preds = %9
%26 = tail call i32 @Turbo_Error(%struct.Turbo_Value* %0, i8* %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %22, %19
%28 = phi i1 [ %21, %19 ], [ %24, %22 ], [ false, %25 ]
%29 = zext i1 %28 to i32
ret i32 %29
}