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

; 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._gqlArg = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct._agooErr = type { i32, [256 x i8] }
%struct._gqlDir = type { ptr, ptr, ptr, ptr, ptr, i8, i8 }

@.str.2 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [27 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @alloc_string(ptr noundef, ptr noundef, i64 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @gql_dir_arg(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6) #4 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i64 %5, ptr %14, align 8, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %19 = call noalias ptr @malloc(i64 noundef 48) #6
  store ptr %19, ptr %16, align 8, !tbaa !5
  %20 = load ptr, ptr %16, align 8, !tbaa !5
  %21 = icmp eq ptr null, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %7
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = call i32 @agoo_err_memory(ptr noundef %23, ptr noundef @.str.12, ptr noundef @.str.2, i32 noundef 803)
  br label %88

25:                                               ; preds = %7
  %26 = load ptr, ptr %16, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._gqlArg, ptr %26, i32 0, i32 0
  store ptr null, ptr %27, align 8, !tbaa !11
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = call noalias ptr @strdup(ptr noundef %28) #5
  %30 = load ptr, ptr %16, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._gqlArg, ptr %30, i32 0, i32 1
  store ptr %29, ptr %31, align 8, !tbaa !13
  %32 = icmp eq ptr null, %29
  br i1 %32, label %33, label %37

33:                                               ; preds = %25
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = call i32 @agoo_err_memory(ptr noundef %34, ptr noundef @.str.5, ptr noundef @.str.2, i32 noundef 807)
  %36 = load ptr, ptr %16, align 8, !tbaa !5
  call void @free(ptr noundef %36) #5
  store ptr null, ptr %8, align 8
  store i32 1, ptr %17, align 4
  br label %90

37:                                               ; preds = %25
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = load ptr, ptr %16, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._gqlArg, ptr %39, i32 0, i32 3
  store ptr %38, ptr %40, align 8, !tbaa !14
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %13, align 8, !tbaa !5
  %43 = load i64, ptr %14, align 8, !tbaa !9
  %44 = call ptr @alloc_string(ptr noundef %41, ptr noundef %42, i64 noundef %43)
  %45 = load ptr, ptr %16, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._gqlArg, ptr %45, i32 0, i32 2
  store ptr %44, ptr %46, align 8, !tbaa !15
  %47 = icmp eq ptr null, %44
  br i1 %47, label %48, label %55

48:                                               ; preds = %37
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._agooErr, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !16
  %52 = icmp ne i32 0, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %48
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  call void @free(ptr noundef %54) #5
  store ptr null, ptr %8, align 8
  store i32 1, ptr %17, align 4
  br label %90

55:                                               ; preds = %48, %37
  %56 = load ptr, ptr %15, align 8, !tbaa !5
  %57 = load ptr, ptr %16, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._gqlArg, ptr %57, i32 0, i32 4
  store ptr %56, ptr %58, align 8, !tbaa !19
  %59 = load ptr, ptr %16, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._gqlArg, ptr %59, i32 0, i32 5
  store ptr null, ptr %60, align 8, !tbaa !20
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._gqlDir, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !21
  %64 = icmp eq ptr null, %63
  br i1 %64, label %65, label %69

65:                                               ; preds = %55
  %66 = load ptr, ptr %16, align 8, !tbaa !5
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._gqlDir, ptr %67, i32 0, i32 3
  store ptr %66, ptr %68, align 8, !tbaa !21
  br label %87

69:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._gqlDir, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !21
  store ptr %72, ptr %18, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %79, %69
  %74 = load ptr, ptr %18, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._gqlArg, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  %77 = icmp ne ptr null, %76
  br i1 %77, label %78, label %83

78:                                               ; preds = %73
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr %18, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._gqlArg, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !11
  store ptr %82, ptr %18, align 8, !tbaa !5
  br label %73, !llvm.loop !24

83:                                               ; preds = %73
  %84 = load ptr, ptr %16, align 8, !tbaa !5
  %85 = load ptr, ptr %18, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._gqlArg, ptr %85, i32 0, i32 0
  store ptr %84, ptr %86, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  br label %87

87:                                               ; preds = %83, %65
  br label %88

88:                                               ; preds = %87, %22
  %89 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %89, ptr %8, align 8
  store i32 1, ptr %17, align 4
  br label %90

90:                                               ; preds = %88, %53, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  %91 = load ptr, ptr %8, align 8
  ret ptr %91
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 #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 "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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_gqlArg", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !6, i64 16}
!16 = !{!17, !18, i64 0}
!17 = !{!"_agooErr", !18, i64 0, !7, i64 4}
!18 = !{!"int", !7, i64 0}
!19 = !{!12, !6, i64 32}
!20 = !{!12, !6, i64 40}
!21 = !{!22, !6, i64 24}
!22 = !{!"_gqlDir", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !23, i64 40, !23, i64 41}
!23 = !{!"_Bool", !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; 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.2 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare hidden ptr @alloc_string(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @gql_dir_arg(ptr noundef %0, ptr nocapture noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6) local_unnamed_addr #4 {
  %8 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.2, i32 noundef 803) #6
  br label %35

12:                                               ; preds = %7
  store ptr null, ptr %8, align 8, !tbaa !5
  %13 = tail call noalias ptr @strdup(ptr noundef %2) #6
  %14 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %13, ptr %14, align 8, !tbaa !10
  %15 = icmp eq ptr %13, null
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.2, i32 noundef 807) #6
  tail call void @free(ptr noundef nonnull %8) #6
  br label %35

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %8, i64 24
  store ptr %3, ptr %19, align 8, !tbaa !11
  %20 = tail call ptr @alloc_string(ptr noundef %0, ptr noundef %4, i64 noundef %5)
  %21 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr %20, ptr %21, align 8, !tbaa !12
  %22 = icmp eq ptr %20, null
  br i1 %22, label %23, label %26

23:                                               ; preds = %18
  %24 = load i32, ptr %0, align 4, !tbaa !13
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %26, label %25

25:                                               ; preds = %23
  tail call void @free(ptr noundef nonnull %8) #6
  br label %35

26:                                               ; preds = %23, %18
  %27 = getelementptr inbounds i8, ptr %8, i64 32
  store ptr %6, ptr %27, align 8, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %8, i64 40
  store ptr null, ptr %28, align 8, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %1, i64 24
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %.preheader

32:                                               ; preds = %26
  store ptr %8, ptr %29, align 8, !tbaa !18
  br label %35

.preheader:                                       ; preds = %26, %.preheader
  %.0 = phi ptr [ %33, %.preheader ], [ %30, %26 ]
  %33 = load ptr, ptr %.0, align 8, !tbaa !5
  %.not31 = icmp eq ptr %33, null
  br i1 %.not31, label %34, label %.preheader, !llvm.loop !21

34:                                               ; preds = %.preheader
  store ptr %8, ptr %.0, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %10, %34, %32, %25, %16
  %.027 = phi ptr [ null, %16 ], [ null, %25 ], [ %8, %32 ], [ %8, %34 ], [ null, %10 ]
  ret ptr %.027
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 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 #3 = { 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 #4 = { 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 #5 = { nounwind allocsize(0) }
attributes #6 = { 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 = !{!"_gqlArg", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 24}
!12 = !{!6, !7, i64 16}
!13 = !{!14, !15, i64 0}
!14 = !{!"_agooErr", !15, i64 0, !8, i64 4}
!15 = !{!"int", !8, i64 0}
!16 = !{!6, !7, i64 32}
!17 = !{!6, !7, i64 40}
!18 = !{!19, !7, i64 24}
!19 = !{!"_gqlDir", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !20, i64 40, !20, i64 41}
!20 = !{!"_Bool", !8, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass