; LLVM IR from JanaSabuj/cppdump :: TRIE+XOR/max_xor_of_pairs.ll (Z6queryxP8trieNodex)

; 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.trieNode = type { ptr, ptr }

; 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: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z6queryxP8trieNodex(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %9, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 31, ptr %7, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %66, %2
  %11 = load i64, ptr %7, align 8, !tbaa !9
  %12 = icmp sge i64 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %69

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = ashr i64 %15, %16
  %18 = and i64 %17, 1
  store i64 %18, ptr %8, align 8, !tbaa !9
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %41

21:                                               ; preds = %14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.trieNode, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %36

26:                                               ; preds = %21
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = trunc i64 %27 to i32
  %29 = shl i32 1, %28
  %30 = sext i32 %29 to i64
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = add nsw i64 %31, %30
  store i64 %32, ptr %6, align 8, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.trieNode, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  store ptr %35, ptr %5, align 8, !tbaa !5
  br label %40

36:                                               ; preds = %21
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.trieNode, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  store ptr %39, ptr %5, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %36, %26
  br label %65

41:                                               ; preds = %14
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = icmp eq i64 %42, 1
  br i1 %43, label %44, label %64

44:                                               ; preds = %41
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.trieNode, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %59

49:                                               ; preds = %44
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = trunc i64 %50 to i32
  %52 = shl i32 1, %51
  %53 = sext i32 %52 to i64
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = add nsw i64 %54, %53
  store i64 %55, ptr %6, align 8, !tbaa !9
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.trieNode, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  store ptr %58, ptr %5, align 8, !tbaa !5
  br label %63

59:                                               ; preds = %44
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.trieNode, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  store ptr %62, ptr %5, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %59, %49
  br label %64

64:                                               ; preds = %63, %41
  br label %65

65:                                               ; preds = %64, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %7, align 8, !tbaa !9
  %68 = add nsw i64 %67, -1
  store i64 %68, ptr %7, align 8, !tbaa !9
  br label %10, !llvm.loop !14

69:                                               ; preds = %13
  %70 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %70
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS8trieNode", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z6queryxP8trieNodex(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  br label %4

3:                                                ; preds = %28
  ret i64 %.119

4:                                                ; preds = %2, %28
  %.026 = phi ptr [ %0, %2 ], [ %.1, %28 ]
  %.01725 = phi i64 [ 31, %2 ], [ %29, %28 ]
  %.01824 = phi i64 [ 0, %2 ], [ %.119, %28 ]
  %5 = shl nuw i64 1, %.01725
  %6 = and i64 %5, %1
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %8, label %18

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %.026, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %.not23 = icmp eq ptr %10, null
  br i1 %.not23, label %16, label %11

11:                                               ; preds = %8
  %12 = trunc i64 %.01725 to i32
  %13 = shl nuw i32 1, %12
  %14 = sext i32 %13 to i64
  %15 = add nsw i64 %.01824, %14
  br label %28

16:                                               ; preds = %8
  %17 = load ptr, ptr %.026, align 8, !tbaa !10
  br label %28

18:                                               ; preds = %4
  %19 = load ptr, ptr %.026, align 8, !tbaa !10
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %25, label %20

20:                                               ; preds = %18
  %21 = trunc i64 %.01725 to i32
  %22 = shl nuw i32 1, %21
  %23 = sext i32 %22 to i64
  %24 = add nsw i64 %.01824, %23
  br label %28

25:                                               ; preds = %18
  %26 = getelementptr inbounds i8, ptr %.026, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %25, %20, %11, %16
  %.119 = phi i64 [ %15, %11 ], [ %.01824, %16 ], [ %24, %20 ], [ %.01824, %25 ]
  %.1 = phi ptr [ %10, %11 ], [ %17, %16 ], [ %19, %20 ], [ %27, %25 ]
  %29 = add nsw i64 %.01725, -1
  %.not27 = icmp eq i64 %.01725, 0
  br i1 %.not27, label %3, label %4, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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" }

!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 8}
!6 = !{!"_ZTS8trieNode", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass