; LLVM IR from MinhasKamal/AlgorithmImplementations :: playWithNumbers/pascalTriangle (RealPascalTriangle)

; 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 [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %12, label %14

12:                                               ; preds = %0
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %115

14:                                               ; preds = %0
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %109, %14
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %112

20:                                               ; preds = %16
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sub nsw i32 9, %21
  store i32 %22, ptr %5, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %28, %20
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %23
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %28

28:                                               ; preds = %26
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr %5, align 4, !tbaa !5
  br label %23, !llvm.loop !9

31:                                               ; preds = %23
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %104, %31
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %107

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = call i64 @num(i32 noundef %37, i32 noundef %38)
  store i64 %39, ptr %7, align 8, !tbaa !11
  %40 = load i64, ptr %7, align 8, !tbaa !11
  %41 = icmp slt i64 %40, 1
  br i1 %41, label %42, label %44

42:                                               ; preds = %36
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %101

44:                                               ; preds = %36
  %45 = load i64, ptr %7, align 8, !tbaa !11
  %46 = icmp slt i64 %45, 10
  br i1 %46, label %47, label %50

47:                                               ; preds = %44
  %48 = load i64, ptr %7, align 8, !tbaa !11
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i64 noundef %48)
  br label %99

50:                                               ; preds = %44
  %51 = load i64, ptr %7, align 8, !tbaa !11
  %52 = icmp slt i64 %51, 100
  br i1 %52, label %53, label %56

53:                                               ; preds = %50
  %54 = load i64, ptr %7, align 8, !tbaa !11
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i64 noundef %54)
  br label %98

56:                                               ; preds = %50
  %57 = load i64, ptr %7, align 8, !tbaa !11
  %58 = icmp slt i64 %57, 1000
  br i1 %58, label %59, label %62

59:                                               ; preds = %56
  %60 = load i64, ptr %7, align 8, !tbaa !11
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i64 noundef %60)
  br label %97

62:                                               ; preds = %56
  %63 = load i64, ptr %7, align 8, !tbaa !11
  %64 = icmp slt i64 %63, 10000
  br i1 %64, label %65, label %68

65:                                               ; preds = %62
  %66 = load i64, ptr %7, align 8, !tbaa !11
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i64 noundef %66)
  br label %96

68:                                               ; preds = %62
  %69 = load i64, ptr %7, align 8, !tbaa !11
  %70 = icmp slt i64 %69, 100000
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load i64, ptr %7, align 8, !tbaa !11
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, i64 noundef %72)
  br label %95

74:                                               ; preds = %68
  %75 = load i64, ptr %7, align 8, !tbaa !11
  %76 = icmp slt i64 %75, 1000000
  br i1 %76, label %77, label %80

77:                                               ; preds = %74
  %78 = load i64, ptr %7, align 8, !tbaa !11
  %79 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, i64 noundef %78)
  br label %94

80:                                               ; preds = %74
  %81 = load i64, ptr %7, align 8, !tbaa !11
  %82 = icmp slt i64 %81, 10000000
  br i1 %82, label %83, label %86

83:                                               ; preds = %80
  %84 = load i64, ptr %7, align 8, !tbaa !11
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.12, i64 noundef %84)
  br label %93

86:                                               ; preds = %80
  %87 = load i64, ptr %7, align 8, !tbaa !11
  %88 = icmp sge i64 %87, 10000000
  br i1 %88, label %89, label %92

89:                                               ; preds = %86
  %90 = load i64, ptr %7, align 8, !tbaa !11
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %90)
  br label %92

92:                                               ; preds = %89, %86
  br label %93

93:                                               ; preds = %92, %83
  br label %94

94:                                               ; preds = %93, %77
  br label %95

95:                                               ; preds = %94, %71
  br label %96

96:                                               ; preds = %95, %65
  br label %97

97:                                               ; preds = %96, %59
  br label %98

98:                                               ; preds = %97, %53
  br label %99

99:                                               ; preds = %98, %47
  br label %100

100:                                              ; preds = %99
  store i32 0, ptr %3, align 4
  br label %101

101:                                              ; preds = %100, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %102 = load i32, ptr %3, align 4
  switch i32 %102, label %114 [
    i32 0, label %103
  ]

103:                                              ; preds = %101
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %6, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %6, align 4, !tbaa !5
  br label %32, !llvm.loop !13

107:                                              ; preds = %32
  %108 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  br label %109

109:                                              ; preds = %107
  %110 = load i32, ptr %4, align 4, !tbaa !5
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %4, align 4, !tbaa !5
  br label %16, !llvm.loop !14

112:                                              ; preds = %16
  %113 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %114

114:                                              ; preds = %112, %101
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %115

115:                                              ; preds = %114, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %116 = load i32, ptr %1, align 4
  ret i32 %116
}

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

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @num(i32 noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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 [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 1
  br i1 %5, label %._crit_edge, label %6

6:                                                ; preds = %0
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph37, label %._crit_edge

.lr.ph37:                                         ; preds = %6, %34
  %indvars.iv = phi i32 [ %indvars.iv.next, %34 ], [ 1, %6 ]
  %.03136 = phi i32 [ %36, %34 ], [ 0, %6 ]
  %10 = icmp ult i32 %.03136, 9
  br i1 %10, label %.lr.ph.preheader, label %.preheader.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph37
  %11 = sub nuw nsw i32 9, %.03136
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.03034 = phi i32 [ %13, %.lr.ph ], [ %11, %.lr.ph.preheader ]
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %13 = add nsw i32 %.03034, -1
  %14 = icmp ugt i32 %.03034, 1
  br i1 %14, label %.lr.ph, label %.preheader.preheader, !llvm.loop !9

.preheader.preheader:                             ; preds = %.lr.ph, %.lr.ph37
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %31
  %.02935 = phi i32 [ %33, %31 ], [ 0, %.preheader.preheader ]
  %15 = call i64 @num(i32 noundef %.03136, i32 noundef %.02935)
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %17, label %._crit_edge

17:                                               ; preds = %.preheader
  %18 = icmp ult i64 %15, 10
  br i1 %18, label %31, label %19

19:                                               ; preds = %17
  %20 = icmp ult i64 %15, 100
  br i1 %20, label %31, label %21

21:                                               ; preds = %19
  %22 = icmp ult i64 %15, 1000
  br i1 %22, label %31, label %23

23:                                               ; preds = %21
  %24 = icmp ult i64 %15, 10000
  br i1 %24, label %31, label %25

25:                                               ; preds = %23
  %26 = icmp ult i64 %15, 100000
  br i1 %26, label %31, label %27

27:                                               ; preds = %25
  %28 = icmp ult i64 %15, 1000000
  br i1 %28, label %31, label %29

29:                                               ; preds = %27
  %30 = icmp ult i64 %15, 10000000
  %.str.12..str.1 = select i1 %30, ptr @.str.12, ptr @.str.1
  br label %31

31:                                               ; preds = %29, %27, %25, %23, %21, %19, %17
  %.str.7.sink = phi ptr [ @.str.6, %17 ], [ @.str.7, %19 ], [ @.str.8, %21 ], [ @.str.9, %23 ], [ @.str.10, %25 ], [ @.str.11, %27 ], [ %.str.12..str.1, %29 ]
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.7.sink, i64 noundef %15)
  %33 = add nuw nsw i32 %.02935, 1
  %exitcond.not = icmp eq i32 %33, %indvars.iv
  br i1 %exitcond.not, label %34, label %.preheader, !llvm.loop !11

34:                                               ; preds = %31
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  %36 = add nuw nsw i32 %.03136, 1
  %37 = load i32, ptr %1, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  %indvars.iv.next = add nuw i32 %indvars.iv, 1
  br i1 %38, label %.lr.ph37, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %34, %.preheader, %6, %0
  %.str.5.sink = phi ptr [ @.str.2, %0 ], [ @.str.3, %6 ], [ @.str.5, %.preheader ], [ @.str.3, %34 ]
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.5.sink)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0
}

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @num(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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" }
attributes #3 = { 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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass