; 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 }
%struct.anon.3 = type { i8, [15 x i8] }
%struct.anon.5 = type { i64, i64 }

@.str.32 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

declare i32 @agoo_err_memory(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden ptr @value_create(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @gql_value_dup(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._gqlValue, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = call ptr @value_create(ptr noundef %10)
  store ptr %11, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  br i1 %13, label %14, label %17

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call i32 @agoo_err_memory(ptr noundef %15, ptr noundef @.str.35, ptr noundef @.str.32, i32 noundef 1616)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %104

17:                                               ; preds = %2
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._gqlValue, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct._gqlType, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 4, !tbaa !11
  switch i32 %22, label %101 [
    i32 2, label %23
    i32 3, label %31
    i32 4, label %37
    i32 5, label %43
    i32 6, label %49
    i32 7, label %49
    i32 11, label %49
    i32 9, label %80
    i32 10, label %86
  ]

23:                                               ; preds = %17
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._gqlValue, ptr %24, i32 0, i32 1
  %26 = load i8, ptr %25, align 8, !tbaa !15, !range !16, !noundef !17
  %27 = trunc i8 %26 to i1
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._gqlValue, ptr %28, i32 0, i32 1
  %30 = zext i1 %27 to i8
  store i8 %30, ptr %29, align 8, !tbaa !15
  br label %102

31:                                               ; preds = %17
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._gqlValue, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !15
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._gqlValue, ptr %35, i32 0, i32 1
  store i32 %34, ptr %36, align 8, !tbaa !15
  br label %102

37:                                               ; preds = %17
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._gqlValue, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._gqlValue, ptr %41, i32 0, i32 1
  store i64 %40, ptr %42, align 8, !tbaa !15
  br label %102

43:                                               ; preds = %17
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._gqlValue, ptr %44, i32 0, i32 1
  %46 = load double, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._gqlValue, ptr %47, i32 0, i32 1
  store double %46, ptr %48, align 8, !tbaa !15
  br label %102

49:                                               ; preds = %17, %17, %17
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._gqlValue, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %struct.anon.3, ptr %51, i32 0, i32 0
  %53 = load i8, ptr %52, align 8, !tbaa !15
  %54 = icmp ne i8 %53, 0
  br i1 %54, label %55, label %70

55:                                               ; preds = %49
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._gqlValue, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds %struct.anon.4, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  %60 = call noalias ptr @strdup(ptr noundef %59) #5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._gqlValue, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds %struct.anon.4, ptr %62, i32 0, i32 2
  store ptr %60, ptr %63, align 8, !tbaa !15
  %64 = icmp eq ptr null, %60
  br i1 %64, label %65, label %69

65:                                               ; preds = %55
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = call i32 @agoo_err_memory(ptr noundef %66, ptr noundef @.str.33, ptr noundef @.str.32, i32 noundef 1637)
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %68) #5
  store ptr null, ptr %6, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %65, %55
  br label %79

70:                                               ; preds = %49
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._gqlValue, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds %struct.anon.3, ptr %72, i32 0, i32 1
  %74 = getelementptr inbounds [15 x i8], ptr %73, i64 0, i64 0
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._gqlValue, ptr %75, i32 0, i32 1
  %77 = getelementptr inbounds %struct.anon.3, ptr %76, i32 0, i32 1
  %78 = getelementptr inbounds [15 x i8], ptr %77, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %74, ptr align 1 %78, i64 15, i1 false)
  br label %79

79:                                               ; preds = %70, %69
  br label %102

80:                                               ; preds = %17
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._gqlValue, ptr %81, i32 0, i32 1
  %83 = load i64, ptr %82, align 8, !tbaa !15
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._gqlValue, ptr %84, i32 0, i32 1
  store i64 %83, ptr %85, align 8, !tbaa !15
  br label %102

86:                                               ; preds = %17
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct._gqlValue, ptr %87, i32 0, i32 1
  %89 = getelementptr inbounds %struct.anon.5, ptr %88, i32 0, i32 0
  %90 = load i64, ptr %89, align 8, !tbaa !15
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._gqlValue, ptr %91, i32 0, i32 1
  %93 = getelementptr inbounds %struct.anon.5, ptr %92, i32 0, i32 0
  store i64 %90, ptr %93, align 8, !tbaa !15
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct._gqlValue, ptr %94, i32 0, i32 1
  %96 = getelementptr inbounds %struct.anon.5, ptr %95, i32 0, i32 1
  %97 = load i64, ptr %96, align 8, !tbaa !15
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct._gqlValue, ptr %98, i32 0, i32 1
  %100 = getelementptr inbounds %struct.anon.5, ptr %99, i32 0, i32 1
  store i64 %97, ptr %100, align 8, !tbaa !15
  br label %102

101:                                              ; preds = %17
  br label %102

102:                                              ; preds = %101, %86, %80, %79, %43, %37, %31, %23
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %103, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %104

104:                                              ; preds = %102, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %105 = load ptr, ptr %3, align 8
  ret ptr %105
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { "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 #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_gqlValue", !6, i64 0, !7, i64 8}
!11 = !{!12, !13, i64 28}
!12 = !{!"_gqlType", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !14, i64 32, !7, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}


; 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.32 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @value_create(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @gql_value_dup(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #3 {
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = tail call ptr @value_create(ptr noundef %3)
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str.35, ptr noundef nonnull @.str.32, i32 noundef 1616) #5
  br label %53

8:                                                ; preds = %2
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 28
  %11 = load i32, ptr %10, align 4, !tbaa !10
  switch i32 %11, label %53 [
    i32 2, label %12
    i32 3, label %16
    i32 4, label %20
    i32 5, label %24
    i32 6, label %28
    i32 7, label %28
    i32 11, label %28
    i32 9, label %42
    i32 10, label %46
  ]

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = load i8, ptr %13, align 8, !tbaa !14, !range !15, !noundef !16
  %15 = getelementptr inbounds i8, ptr %4, i64 8
  store i8 %14, ptr %15, align 8, !tbaa !14
  br label %53

16:                                               ; preds = %8
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %18, ptr %19, align 8, !tbaa !14
  br label %53

20:                                               ; preds = %8
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 %22, ptr %23, align 8, !tbaa !14
  br label %53

24:                                               ; preds = %8
  %25 = getelementptr inbounds i8, ptr %1, i64 8
  %26 = load double, ptr %25, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %4, i64 8
  store double %26, ptr %27, align 8, !tbaa !14
  br label %53

28:                                               ; preds = %8, %8, %8
  %29 = getelementptr inbounds i8, ptr %1, i64 8
  %30 = load i8, ptr %29, align 8, !tbaa !14
  %.not = icmp eq i8 %30, 0
  br i1 %.not, label %39, label %31

31:                                               ; preds = %28
  %32 = getelementptr inbounds i8, ptr %1, i64 16
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = tail call noalias ptr @strdup(ptr noundef %33) #5
  %35 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %34, ptr %35, align 8, !tbaa !14
  %36 = icmp eq ptr %34, null
  br i1 %36, label %37, label %53

37:                                               ; preds = %31
  %38 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str.33, ptr noundef nonnull @.str.32, i32 noundef 1637) #5
  tail call void @free(ptr noundef nonnull %4) #5
  br label %53

39:                                               ; preds = %28
  %40 = getelementptr inbounds i8, ptr %4, i64 9
  %41 = getelementptr inbounds i8, ptr %1, i64 9
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(15) %40, ptr noundef nonnull align 1 dereferenceable(15) %41, i64 15, i1 false)
  br label %53

42:                                               ; preds = %8
  %43 = getelementptr inbounds i8, ptr %1, i64 8
  %44 = load i64, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 %44, ptr %45, align 8, !tbaa !14
  br label %53

46:                                               ; preds = %8
  %47 = getelementptr inbounds i8, ptr %1, i64 8
  %48 = load i64, ptr %47, align 8, !tbaa !14
  %49 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 %48, ptr %49, align 8, !tbaa !14
  %50 = getelementptr inbounds i8, ptr %1, i64 16
  %51 = load i64, ptr %50, align 8, !tbaa !14
  %52 = getelementptr inbounds i8, ptr %4, i64 16
  store i64 %51, ptr %52, align 8, !tbaa !14
  br label %53

53:                                               ; preds = %12, %16, %20, %24, %42, %46, %31, %37, %39, %8, %6
  %.027 = phi ptr [ null, %6 ], [ %4, %8 ], [ %4, %46 ], [ %4, %42 ], [ null, %37 ], [ %4, %31 ], [ %4, %39 ], [ %4, %24 ], [ %4, %20 ], [ %4, %16 ], [ %4, %12 ]
  ret ptr %.027
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #3 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 28}
!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}
!15 = !{i8 0, i8 2}
!16 = !{}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass