; LLVM IR from viveakrt/Competitive-programing :: SPOJ/orderset.ll (Z5countRP4nodei)

; 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, i32, i32, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z2szP4node(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5countRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %2
  store i32 0, ptr %3, align 4
  br label %36

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.node, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %30

17:                                               ; preds = %10
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.node, ptr %19, i32 0, i32 4
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = call noundef i32 @_Z5countRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %20, i32 noundef %21)
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.node, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = call noundef i32 @_Z2szP4node(ptr noundef %26)
  %28 = add nsw i32 %22, %27
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %3, align 4
  br label %36

30:                                               ; preds = %10
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = call noundef i32 @_Z5countRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %33, i32 noundef %34)
  store i32 %35, ptr %3, align 4
  br label %36

36:                                               ; preds = %30, %17, %9
  %37 = load i32, ptr %3, align 4
  ret i32 %37
}

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

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS4node", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!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 nounwind uwtable
declare dso_local noundef i32 @_Z2szP4node(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z5countRP4nodei(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not13 = icmp eq ptr %3, null
  br i1 %.not13, label %common.ret31, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = icmp slt i32 %5, %1
  br i1 %6, label %.lr.ph._crit_edge, label %tailrecurse

.lr.ph:                                           ; preds = %tailrecurse
  %7 = getelementptr inbounds i8, ptr %21, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp slt i32 %8, %1
  br i1 %9, label %.lr.ph._crit_edge.loopexit, label %tailrecurse

common.ret31:                                     ; preds = %2, %tailrecurse, %.lr.ph._crit_edge
  %common.ret31.op = phi i32 [ %18, %.lr.ph._crit_edge ], [ 0, %tailrecurse ], [ 0, %2 ]
  ret i32 %common.ret31.op

.lr.ph._crit_edge.loopexit:                       ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %19, i64 16
  br label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph._crit_edge.loopexit, %.lr.ph.preheader
  %.lcssa = phi ptr [ %3, %.lr.ph.preheader ], [ %21, %.lr.ph._crit_edge.loopexit ]
  %.tr14.lcssa = phi ptr [ %0, %.lr.ph.preheader ], [ %10, %.lr.ph._crit_edge.loopexit ]
  %11 = getelementptr inbounds i8, ptr %.lcssa, i64 24
  %12 = tail call noundef i32 @_Z5countRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %11, i32 noundef %1)
  %13 = load ptr, ptr %.tr14.lcssa, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = tail call noundef i32 @_Z2szP4node(ptr noundef %15)
  %17 = add i32 %12, 1
  %18 = add i32 %17, %16
  br label %common.ret31

tailrecurse:                                      ; preds = %.lr.ph.preheader, %.lr.ph
  %19 = phi ptr [ %21, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %common.ret31, label %.lr.ph
}

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

!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, !11, i64 4}
!10 = !{!"_ZTS4node", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass