; LLVM IR from adventure-db/adventure :: src/struct (trie)

; 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.trie = type { ptr, ptr, ptr }
%struct.list = type { i64, ptr, ptr }
%struct.listelem = type { ptr, ptr, ptr }

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @trie_add(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  br label %102

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.trie, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.trie, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = call i64 @sdslen(ptr noundef %24)
  br label %27

26:                                               ; preds = %16
  br label %27

27:                                               ; preds = %26, %21
  %28 = phi i64 [ %25, %21 ], [ 0, %26 ]
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %8, align 4, !tbaa !11
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.trie, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = call i32 @strncmp(ptr noundef %32, ptr noundef %33, i64 noundef %35) #6
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %27
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %101

39:                                               ; preds = %27
  %40 = load i32, ptr %8, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i64 @strlen(ptr noundef %42) #6
  %44 = icmp eq i64 %41, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %39
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %101

46:                                               ; preds = %39
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.trie, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %83

51:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.trie, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = getelementptr inbounds %struct.list, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !14
  store ptr %56, ptr %10, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %75, %51
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %79

60:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.listelem, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !17
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call i32 @trie_add(ptr noundef %63, ptr noundef %64, ptr noundef %65)
  store i32 %66, ptr %11, align 4, !tbaa !11
  %67 = load i32, ptr %11, align 4, !tbaa !11
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %71

69:                                               ; preds = %60
  %70 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %70, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %72

71:                                               ; preds = %60
  store i32 0, ptr %9, align 4
  br label %72

72:                                               ; preds = %71, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  %73 = load i32, ptr %9, align 4
  switch i32 %73, label %80 [
    i32 0, label %74
  ]

74:                                               ; preds = %72
  br label %75

75:                                               ; preds = %74
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.listelem, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !19
  store ptr %78, ptr %10, align 8, !tbaa !5
  br label %57, !llvm.loop !20

79:                                               ; preds = %57
  store i32 0, ptr %9, align 4
  br label %80

80:                                               ; preds = %79, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %81 = load i32, ptr %9, align 4
  switch i32 %81, label %101 [
    i32 0, label %82
  ]

82:                                               ; preds = %80
  br label %87

83:                                               ; preds = %46
  %84 = call ptr (...) @list_create()
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.trie, ptr %85, i32 0, i32 2
  store ptr %84, ptr %86, align 8, !tbaa !13
  br label %87

87:                                               ; preds = %83, %82
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = load i32, ptr %8, align 4, !tbaa !11
  %90 = add nsw i32 %89, 1
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = call ptr @trie_make_node(ptr noundef %88, i32 noundef %90, ptr noundef %91)
  store ptr %92, ptr %12, align 8, !tbaa !5
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.trie, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %94, align 8, !tbaa !13
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  call void @list_push(ptr noundef %95, ptr noundef %96)
  %97 = load ptr, ptr %12, align 8, !tbaa !5
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = call i32 @trie_add(ptr noundef %97, ptr noundef %98, ptr noundef %99)
  store i32 %100, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %101

101:                                              ; preds = %87, %80, %45, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %102

102:                                              ; preds = %101, %15
  %103 = load i32, ptr %4, align 4
  ret i32 %103
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

declare ptr @list_create(...) #4

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

declare void @list_push(ptr noundef, ptr noundef) #4

attributes #0 = { inlinehint 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind willreturn memory(read) "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 = { "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 willreturn memory(read) }

!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 = !{!"trie", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!15, !6, i64 8}
!15 = !{!"list", !16, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!18, !6, i64 16}
!18 = !{!"listelem", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!18, !6, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"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"

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @trie_add(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %.not44 = icmp eq ptr %0, null
  br i1 %.not44, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.critedge
  %.tr45 = phi ptr [ %26, %.critedge ], [ %0, %3 ]
  %4 = load ptr, ptr %.tr45, align 8, !tbaa !5
  %.not36 = icmp eq ptr %4, null
  br i1 %.not36, label %8, label %5

5:                                                ; preds = %.lr.ph
  %6 = tail call i64 @sdslen(ptr noundef nonnull %4)
  %7 = trunc i64 %6 to i32
  %.pre = load ptr, ptr %.tr45, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %.lr.ph, %5
  %9 = phi ptr [ %.pre, %5 ], [ null, %.lr.ph ]
  %10 = phi i32 [ %7, %5 ], [ 0, %.lr.ph ]
  %11 = sext i32 %10 to i64
  %12 = tail call i32 @strncmp(ptr noundef %9, ptr noundef %1, i64 noundef %11) #4
  %.not37 = icmp eq i32 %12, 0
  br i1 %.not37, label %13, label %.loopexit

13:                                               ; preds = %8
  %14 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %15 = icmp eq i64 %14, %11
  br i1 %15, label %.loopexit, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %.tr45, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !10
  %.not38 = icmp eq ptr %18, null
  br i1 %.not38, label %23, label %.preheader

.preheader:                                       ; preds = %16, %19
  %.pn = phi ptr [ %.031, %19 ], [ %18, %16 ]
  %.031.in = getelementptr inbounds i8, ptr %.pn, i64 8
  %.031 = load ptr, ptr %.031.in, align 8, !tbaa !11
  %.not39 = icmp eq ptr %.031, null
  br i1 %.not39, label %.critedge, label %19

19:                                               ; preds = %.preheader
  %20 = getelementptr inbounds i8, ptr %.031, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = tail call i32 @trie_add(ptr noundef %21, ptr noundef %1, ptr noundef %2)
  %.not40 = icmp eq i32 %22, 0
  br i1 %.not40, label %.loopexit, label %.preheader, !llvm.loop !14

23:                                               ; preds = %16
  %24 = tail call ptr (...) @list_create() #5
  store ptr %24, ptr %17, align 8, !tbaa !10
  br label %.critedge

.critedge:                                        ; preds = %.preheader, %23
  %25 = add nsw i32 %10, 1
  %26 = tail call ptr @trie_make_node(ptr noundef %1, i32 noundef %25, ptr noundef %2)
  %27 = load ptr, ptr %17, align 8, !tbaa !10
  tail call void @list_push(ptr noundef %27, ptr noundef %26) #5
  %.not = icmp eq ptr %26, null
  br i1 %.not, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %.critedge, %13, %8, %19, %3
  %.4 = phi i32 [ -1, %3 ], [ 0, %19 ], [ -1, %.critedge ], [ 0, %13 ], [ -1, %8 ]
  ret i32 %.4
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

declare ptr @list_create(...) local_unnamed_addr #3

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

declare void @list_push(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { inlinehint 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 = { 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 #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { "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 willreturn memory(read) }
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 = !{!"trie", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 16}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 16}
!13 = !{!"listelem", !7, i64 0, !7, i64 8, !7, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass