; LLVM IR from JanaSabuj/cppdump :: TRIE+XOR/xor_maxsum_subarray_icpc.ll (Z5queryP8trieNodex)

; 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 @_Z5queryP8trieNodex(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 = %62, %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 %65

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 %61

41:                                               ; preds = %14
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.trieNode, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %56

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

56:                                               ; preds = %41
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.trieNode, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  store ptr %59, ptr %5, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %56, %46
  br label %61

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

62:                                               ; preds = %61
  %63 = load i64, ptr %7, align 8, !tbaa !9
  %64 = add nsw i64 %63, -1
  store i64 %64, ptr %7, align 8, !tbaa !9
  br label %10, !llvm.loop !14

65:                                               ; preds = %13
  %66 = 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 %66
}

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 @_Z5queryP8trieNodex(ptr nocapture noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  br label %4

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

4:                                                ; preds = %2, %28
  %.024 = phi ptr [ %0, %2 ], [ %.1, %28 ]
  %.01623 = phi i64 [ 31, %2 ], [ %29, %28 ]
  %.01722 = phi i64 [ 0, %2 ], [ %.118, %28 ]
  %5 = shl nuw i64 1, %.01623
  %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 %.024, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %.not21 = icmp eq ptr %10, null
  br i1 %.not21, label %16, label %11

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

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

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

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

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

28:                                               ; preds = %20, %25, %11, %16
  %.118 = phi i64 [ %15, %11 ], [ %.01722, %16 ], [ %24, %20 ], [ %.01722, %25 ]
  %.1 = phi ptr [ %10, %11 ], [ %17, %16 ], [ %19, %20 ], [ %27, %25 ]
  %29 = add nsw i64 %.01623, -1
  %.not25 = icmp eq i64 %.01623, 0
  br i1 %.not25, 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