; LLVM IR from AllAlgorithms/c :: algorithms/math/Triangle (pascal)

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

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @Pascal(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = zext i32 %12 to i64
  %14 = call ptr @llvm.stacksave.p0()
  store ptr %14, ptr %3, align 8
  %15 = mul nuw i64 %11, %13
  %16 = alloca i32, i64 %15, align 16
  store i64 %11, ptr %4, align 8
  store i64 %13, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %99, %1
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %102

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %32, %22
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = sub nsw i32 %25, %26
  %28 = icmp slt i32 %24, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %23
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %35

30:                                               ; preds = %23
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %32

32:                                               ; preds = %30
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %8, align 4, !tbaa !5
  br label %23, !llvm.loop !9

35:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %94, %35
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = icmp sle i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %97

41:                                               ; preds = %36
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = icmp eq i32 %42, %43
  br i1 %44, label %48, label %45

45:                                               ; preds = %41
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %56

48:                                               ; preds = %45, %41
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = mul nsw i64 %50, %13
  %52 = getelementptr inbounds i32, ptr %16, i64 %51
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  store i32 1, ptr %55, align 4, !tbaa !5
  br label %84

56:                                               ; preds = %45
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = sub nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %59, %13
  %61 = getelementptr inbounds i32, ptr %16, i64 %60
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = sub nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr %61, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = sub nsw i32 %67, 1
  %69 = sext i32 %68 to i64
  %70 = mul nsw i64 %69, %13
  %71 = getelementptr inbounds i32, ptr %16, i64 %70
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i32, ptr %71, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = add nsw i32 %66, %75
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = mul nsw i64 %78, %13
  %80 = getelementptr inbounds i32, ptr %16, i64 %79
  %81 = load i32, ptr %9, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i32, ptr %80, i64 %82
  store i32 %76, ptr %83, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %56, %48
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = mul nsw i64 %86, %13
  %88 = getelementptr inbounds i32, ptr %16, i64 %87
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i32, ptr %88, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %92)
  br label %94

94:                                               ; preds = %84
  %95 = load i32, ptr %9, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %9, align 4, !tbaa !5
  br label %36, !llvm.loop !11

97:                                               ; preds = %40
  %98 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %99

99:                                               ; preds = %97
  %100 = load i32, ptr %6, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %6, align 4, !tbaa !5
  br label %17, !llvm.loop !12

102:                                              ; preds = %21
  %103 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %103)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @Pascal(i32 noundef %0) local_unnamed_addr #0 {
  %2 = zext i32 %0 to i64
  %3 = mul nuw i64 %2, %2
  %4 = alloca i32, i64 %3, align 16
  %5 = icmp sgt i32 %0, 0
  br i1 %5, label %.preheader29.preheader, label %._crit_edge

.preheader29.preheader:                           ; preds = %1
  %6 = zext nneg i32 %0 to i64
  br label %.preheader29

.preheader29:                                     ; preds = %.preheader29.preheader, %.loopexit
  %indvars.iv42 = phi i64 [ 0, %.preheader29.preheader ], [ %indvars.iv.next43, %.loopexit ]
  %indvars.iv40 = phi i64 [ 1, %.preheader29.preheader ], [ %indvars.iv.next41, %.loopexit ]
  %indvars.iv = phi i32 [ %0, %.preheader29.preheader ], [ %indvars.iv.next, %.loopexit ]
  %7 = icmp ult i64 %indvars.iv42, %6
  br i1 %7, label %.lr.ph, label %.loopexit49

._crit_edge:                                      ; preds = %.loopexit, %1
  ret void

.loopexit49:                                      ; preds = %.lr.ph, %.preheader29
  %8 = mul nuw nsw i64 %indvars.iv42, %2
  %9 = getelementptr inbounds i32, ptr %4, i64 %8
  %10 = add nsw i64 %indvars.iv42, -1
  %11 = mul nsw i64 %10, %2
  %12 = getelementptr inbounds i32, ptr %4, i64 %11
  store i32 1, ptr %9, align 4, !tbaa !5
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef 1)
  %exitcond38.peel.not = icmp eq i64 %indvars.iv40, 1
  br i1 %exitcond38.peel.not, label %.loopexit, label %.peel.next

.peel.next:                                       ; preds = %.loopexit49
  %14 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv42
  br label %18

.lr.ph:                                           ; preds = %.preheader29, %.lr.ph
  %.02630 = phi i32 [ %16, %.lr.ph ], [ 0, %.preheader29 ]
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %16 = add nuw nsw i32 %.02630, 1
  %exitcond.not = icmp eq i32 %16, %indvars.iv
  br i1 %exitcond.not, label %.loopexit49, label %.lr.ph, !llvm.loop !9

.loopexit:                                        ; preds = %28, %.loopexit49
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %indvars.iv.next = add i32 %indvars.iv, -1
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond48.not = icmp eq i64 %indvars.iv.next43, %2
  br i1 %exitcond48.not, label %._crit_edge, label %.preheader29, !llvm.loop !11

18:                                               ; preds = %.peel.next, %28
  %indvars.iv33 = phi i64 [ 1, %.peel.next ], [ %indvars.iv.next34, %28 ]
  %19 = icmp eq i64 %indvars.iv42, %indvars.iv33
  br i1 %19, label %20, label %21

20:                                               ; preds = %18
  store i32 1, ptr %14, align 4, !tbaa !5
  br label %28

21:                                               ; preds = %18
  %22 = getelementptr i32, ptr %12, i64 %indvars.iv33
  %23 = getelementptr i8, ptr %22, i64 -4
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %22, align 4, !tbaa !5
  %26 = add nsw i32 %25, %24
  %27 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv33
  store i32 %26, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %21, %20
  %29 = phi i32 [ %26, %21 ], [ 1, %20 ]
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %29)
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next34, %indvars.iv40
  br i1 %exitcond38.not, label %.loopexit, label %18, !llvm.loop !12
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { nofree 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 = { nofree nounwind "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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10, !13}
!13 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass