; LLVM IR from ohler55/agoo :: ext/agoo (gqlvalue)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct._gqlValue = type { ptr, %union.anon.1 }
%union.anon.1 = type { %union.anon.2 }
%union.anon.2 = type { %struct.anon.4 }
%struct.anon.4 = type { i8, [7 x i8], ptr }
%struct._gqlType = type { ptr, ptr, ptr, i32, i32, i8, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, ptr, ptr }

@.str.34 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden ptr @string_to_text(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

declare ptr @agoo_text_append(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @gql_value_json(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._gqlValue, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = icmp eq ptr null, %11
  br i1 %12, label %20, label %13

13:                                               ; preds = %4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._gqlValue, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %struct._gqlType, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = icmp ne i32 8, %18
  br i1 %19, label %20, label %37

20:                                               ; preds = %13, %4
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._gqlValue, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct._gqlType, ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = icmp eq i32 7, %25
  br i1 %26, label %27, label %33

27:                                               ; preds = %20
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = call ptr @string_to_text(ptr noundef %28, ptr noundef %29, i32 noundef %30, i32 noundef %31)
  store ptr %32, ptr %5, align 8, !tbaa !5
  br label %36

33:                                               ; preds = %20
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call ptr @agoo_text_append(ptr noundef %34, ptr noundef @.str.34, i32 noundef 4)
  store ptr %35, ptr %5, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %33, %27
  br label %61

37:                                               ; preds = %13
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._gqlValue, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds %struct._gqlType, ptr %40, i32 0, i32 6
  %42 = getelementptr inbounds %struct.anon, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = icmp eq ptr null, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %37
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call ptr @agoo_text_append(ptr noundef %46, ptr noundef @.str.34, i32 noundef 4)
  store ptr %47, ptr %5, align 8, !tbaa !5
  br label %60

48:                                               ; preds = %37
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._gqlValue, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct._gqlType, ptr %51, i32 0, i32 6
  %53 = getelementptr inbounds %struct.anon, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = call ptr %54(ptr noundef %55, ptr noundef %56, i32 noundef %57, i32 noundef %58)
  store ptr %59, ptr %5, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %48, %45
  br label %61

61:                                               ; preds = %60, %36
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  ret ptr %62
}

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_gqlValue", !6, i64 0, !7, i64 8}
!13 = !{!14, !10, i64 24}
!14 = !{!"_gqlType", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !15, i64 32, !7, i64 40}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!7, !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str.34 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden ptr @string_to_text(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare ptr @agoo_text_append(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @gql_value_json(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %._crit_edge, label %7

._crit_edge:                                      ; preds = %4
  %.pre = load i32, ptr inttoptr (i64 24 to ptr), align 8, !tbaa !10
  br label %10

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %5, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !10
  %.not = icmp eq i32 %9, 8
  br i1 %.not, label %17, label %10

10:                                               ; preds = %._crit_edge, %7
  %11 = phi i32 [ %.pre, %._crit_edge ], [ %9, %7 ]
  %12 = icmp eq i32 %11, 7
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = tail call ptr @string_to_text(ptr noundef %0, ptr noundef nonnull %1, i32 noundef %2, i32 noundef %3)
  br label %25

15:                                               ; preds = %10
  %16 = tail call ptr @agoo_text_append(ptr noundef %0, ptr noundef nonnull @.str.34, i32 noundef 4) #2
  br label %25

17:                                               ; preds = %7
  %18 = getelementptr inbounds i8, ptr %5, i64 48
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  %22 = tail call ptr @agoo_text_append(ptr noundef %0, ptr noundef nonnull @.str.34, i32 noundef 4) #2
  br label %25

23:                                               ; preds = %17
  %24 = tail call ptr %19(ptr noundef %0, ptr noundef nonnull %1, i32 noundef %2, i32 noundef %3) #2
  br label %25

25:                                               ; preds = %21, %23, %13, %15
  %.0 = phi ptr [ %14, %13 ], [ %16, %15 ], [ %22, %21 ], [ %24, %23 ]
  ret ptr %.0
}

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"_gqlValue", !7, i64 0, !8, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 24}
!11 = !{!"_gqlType", !7, i64 0, !7, i64 8, !7, i64 16, !12, i64 24, !12, i64 28, !13, i64 32, !8, i64 40}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!8, !8, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass