; LLVM IR from Hunterdii/GeeksforGeeks-POTD :: July 2024 GFG SOLUTION/July-25.ll (Z4helpP4Nodexx)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z4helpP4Nodexx(ptr noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = sext i32 %11 to i64
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp sge i64 %12, %13
  br i1 %14, label %22, label %15

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Node, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = icmp sle i64 %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %15, %3
  store i1 false, ptr %4, align 1
  br label %61

23:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  store i8 1, ptr %8, align 1, !tbaa !14
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Node, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %39

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Node, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Node, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = call noundef zeroext i1 @_Z4helpP4Nodexx(ptr noundef %31, i64 noundef %35, i64 noundef %36)
  %38 = zext i1 %37 to i8
  store i8 %38, ptr %8, align 1, !tbaa !14
  br label %39

39:                                               ; preds = %28, %23
  %40 = load i8, ptr %8, align 1, !tbaa !14, !range !17, !noundef !18
  %41 = trunc i8 %40 to i1
  br i1 %41, label %42, label %58

42:                                               ; preds = %39
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.Node, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !19
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %58

47:                                               ; preds = %42
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = load i64, ptr %6, align 8, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Node, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = call noundef zeroext i1 @_Z4helpP4Nodexx(ptr noundef %50, i64 noundef %51, i64 noundef %55)
  %57 = zext i1 %56 to i8
  store i8 %57, ptr %8, align 1, !tbaa !14
  br label %58

58:                                               ; preds = %47, %42, %39
  %59 = load i8, ptr %8, align 1, !tbaa !14, !range !17, !noundef !18
  %60 = trunc i8 %59 to i1
  store i1 %60, ptr %4, align 1
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  br label %61

61:                                               ; preds = %58, %22
  %62 = load i1, ptr %4, align 1
  ret i1 %62
}

; 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

attributes #0 = { mustprogress 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 }

!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, !13, i64 0}
!12 = !{!"_ZTS4Node", !13, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!12, !6, i64 8}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!12, !6, i64 16}


; 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 nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z4helpP4Nodexx(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %.thread, %3
  %.tr = phi ptr [ %0, %3 ], [ %12, %.thread ]
  %.tr26 = phi i64 [ %2, %3 ], [ %5, %.thread ]
  %4 = load i32, ptr %.tr, align 8, !tbaa !5
  %5 = sext i32 %4 to i64
  %.not = icmp slt i64 %5, %1
  %.not20 = icmp sgt i64 %5, %.tr26
  %or.cond = and i1 %.not, %.not20
  br i1 %or.cond, label %6, label %13

6:                                                ; preds = %tailrecurse
  %7 = getelementptr inbounds i8, ptr %.tr, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %.not21 = icmp eq ptr %8, null
  br i1 %.not21, label %.thread, label %9

9:                                                ; preds = %6
  %10 = tail call noundef zeroext i1 @_Z4helpP4Nodexx(ptr noundef nonnull %8, i64 noundef %5, i64 noundef %.tr26)
  br i1 %10, label %.thread, label %13

.thread:                                          ; preds = %6, %9
  %11 = getelementptr inbounds i8, ptr %.tr, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %.not22 = icmp eq ptr %12, null
  br i1 %.not22, label %13, label %tailrecurse

13:                                               ; preds = %9, %.thread, %tailrecurse
  %.014 = phi i1 [ false, %tailrecurse ], [ true, %.thread ], [ false, %9 ]
  ret i1 %.014
}

attributes #0 = { mustprogress nofree 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 0}
!6 = !{!"_ZTS4Node", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 16}


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