; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2007-08/alake.ll (Z8fromLeftii)

; 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"

@w = external dso_local global [100001 x i32], align 16
@child = external dso_local global [100001 x [2 x i32]], align 16
@par = external dso_local global [100001 x i32], align 16
@leftmost = external dso_local global [100001 x i32], align 16
@ans = external dso_local global [100001 x i64], align 16
@ti = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z6getPari(i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8fromLeftii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %11

7:                                                ; preds = %2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %7, %2
  br label %41

12:                                               ; preds = %7
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100001 x [2 x i32]], ptr @child, i64 0, i64 %14
  %16 = getelementptr inbounds [2 x i32], ptr %15, i64 0, i64 1
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100001 x i32], ptr @leftmost, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z8fromLeftii(i32 noundef %20, i32 noundef %21)
  %22 = load i64, ptr @ti, align 8, !tbaa !9
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i32], ptr @w, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = add nsw i64 %22, %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %30
  store i64 %28, ptr %31, align 8, !tbaa !9
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = call noundef i64 @_Z6getPari(i32 noundef %32)
  %34 = load i64, ptr @ti, align 8, !tbaa !9
  %35 = add nsw i64 %34, %33
  store i64 %35, ptr @ti, align 8, !tbaa !9
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100001 x i32], ptr @par, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z8fromLeftii(i32 noundef %39, i32 noundef %40)
  br label %41

41:                                               ; preds = %12, %11
  ret void
}

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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


; 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"

@w = external dso_local local_unnamed_addr global [100001 x i32], align 16
@child = external dso_local local_unnamed_addr global [100001 x [2 x i32]], align 16
@par = external dso_local local_unnamed_addr global [100001 x i32], align 16
@leftmost = external dso_local local_unnamed_addr global [100001 x i32], align 16
@ans = external dso_local local_unnamed_addr global [100001 x i64], align 16
@ti = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z6getPari(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8fromLeftii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not12 = icmp eq i32 %0, 0
  %3 = icmp eq i32 %0, %1
  %or.cond13 = or i1 %.not12, %3
  br i1 %or.cond13, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse:                                      ; preds = %2, %tailrecurse
  %.tr14 = phi i32 [ %20, %tailrecurse ], [ %0, %2 ]
  %4 = sext i32 %.tr14 to i64
  %5 = getelementptr inbounds [100001 x [2 x i32]], ptr @child, i64 0, i64 %4, i64 1
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100001 x i32], ptr @leftmost, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  tail call void @_Z8fromLeftii(i32 noundef %9, i32 noundef %.tr14)
  %10 = load i64, ptr @ti, align 8, !tbaa !9
  %11 = getelementptr inbounds [100001 x i32], ptr @w, i64 0, i64 %4
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = add nsw i64 %10, %13
  %15 = getelementptr inbounds [100001 x i64], ptr @ans, i64 0, i64 %4
  store i64 %14, ptr %15, align 8, !tbaa !9
  %16 = tail call noundef i64 @_Z6getPari(i32 noundef %.tr14)
  %17 = load i64, ptr @ti, align 8, !tbaa !9
  %18 = add nsw i64 %17, %16
  store i64 %18, ptr @ti, align 8, !tbaa !9
  %19 = getelementptr inbounds [100001 x i32], ptr @par, i64 0, i64 %4
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not = icmp eq i32 %20, 0
  %21 = icmp eq i32 %20, %1
  %or.cond = or i1 %.not, %21
  br i1 %or.cond, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  ret void
}

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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass