; LLVM IR from pranjalwalia/Competitive-programming :: Hackerrank/language/C (Printing Pattern using Loops)

; 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 [3 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 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #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
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %8 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %8, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %61, %0
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp sge i32 %10, 1
  br i1 %11, label %12, label %64

12:                                               ; preds = %9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %13, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %14, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %29, %12
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp sge i32 %16, 1
  br i1 %17, label %18, label %34

18:                                               ; preds = %15
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %18
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %23)
  br label %28

25:                                               ; preds = %18
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %26)
  br label %28

28:                                               ; preds = %25, %22
  br label %29

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

34:                                               ; preds = %15
  store i32 2, ptr %6, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  store i32 %36, ptr %4, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %54, %34
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = icmp sge i32 %38, 1
  br i1 %39, label %40, label %59

40:                                               ; preds = %37
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sub nsw i32 %42, %43
  %45 = add nsw i32 %44, 1
  %46 = icmp slt i32 %41, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %40
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %48)
  br label %53

50:                                               ; preds = %40
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %51)
  br label %53

53:                                               ; preds = %50, %47
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %4, align 4, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %6, align 4, !tbaa !5
  br label %37, !llvm.loop !11

59:                                               ; preds = %37
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %61

61:                                               ; preds = %59
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !12

64:                                               ; preds = %9
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %118, %64
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = icmp sle i32 %66, %67
  br i1 %68, label %69, label %121

69:                                               ; preds = %65
  %70 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %70, ptr %5, align 4, !tbaa !5
  %71 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %71, ptr %4, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %86, %69
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = icmp sge i32 %73, 1
  br i1 %74, label %75, label %91

75:                                               ; preds = %72
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %79, label %82

79:                                               ; preds = %75
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %80)
  br label %85

82:                                               ; preds = %75
  %83 = load i32, ptr %3, align 4, !tbaa !5
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %83)
  br label %85

85:                                               ; preds = %82, %79
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = add nsw i32 %87, -1
  store i32 %88, ptr %4, align 4, !tbaa !5
  %89 = load i32, ptr %5, align 4, !tbaa !5
  %90 = add nsw i32 %89, -1
  store i32 %90, ptr %5, align 4, !tbaa !5
  br label %72, !llvm.loop !13

91:                                               ; preds = %72
  store i32 2, ptr %6, align 4, !tbaa !5
  %92 = load i32, ptr %2, align 4, !tbaa !5
  %93 = sub nsw i32 %92, 1
  store i32 %93, ptr %4, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %111, %91
  %95 = load i32, ptr %4, align 4, !tbaa !5
  %96 = icmp sge i32 %95, 1
  br i1 %96, label %97, label %116

97:                                               ; preds = %94
  %98 = load i32, ptr %3, align 4, !tbaa !5
  %99 = load i32, ptr %2, align 4, !tbaa !5
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = sub nsw i32 %99, %100
  %102 = add nsw i32 %101, 1
  %103 = icmp slt i32 %98, %102
  br i1 %103, label %104, label %107

104:                                              ; preds = %97
  %105 = load i32, ptr %6, align 4, !tbaa !5
  %106 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %105)
  br label %110

107:                                              ; preds = %97
  %108 = load i32, ptr %3, align 4, !tbaa !5
  %109 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %108)
  br label %110

110:                                              ; preds = %107, %104
  br label %111

111:                                              ; preds = %110
  %112 = load i32, ptr %4, align 4, !tbaa !5
  %113 = add nsw i32 %112, -1
  store i32 %113, ptr %4, align 4, !tbaa !5
  %114 = load i32, ptr %6, align 4, !tbaa !5
  %115 = add nsw i32 %114, 1
  store i32 %115, ptr %6, align 4, !tbaa !5
  br label %94, !llvm.loop !14

116:                                              ; preds = %94
  %117 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %118

118:                                              ; preds = %116
  %119 = load i32, ptr %3, align 4, !tbaa !5
  %120 = add nsw i32 %119, 1
  store i32 %120, ptr %3, align 4, !tbaa !5
  br label %65, !llvm.loop !15

121:                                              ; preds = %65
  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
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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

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

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

; 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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !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 [3 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 noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph52, label %._crit_edge65

.preheader41:                                     ; preds = %._crit_edge49
  %.not63 = icmp slt i32 %.pr, 2
  br i1 %.not63, label %._crit_edge65, label %.preheader

.lr.ph52:                                         ; preds = %0, %._crit_edge49
  %5 = phi i32 [ %.pr, %._crit_edge49 ], [ %3, %0 ]
  %.03650 = phi i32 [ %16, %._crit_edge49 ], [ %3, %0 ]
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge49

.lr.ph:                                           ; preds = %.lr.ph52, %.lr.ph
  %.03243 = phi i32 [ %8, %.lr.ph ], [ %5, %.lr.ph52 ]
  %.03243..03650 = call i32 @llvm.smax.i32(i32 %.03650, i32 %.03243)
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.03243..03650)
  %8 = add nsw i32 %.03243, -1
  %9 = icmp sgt i32 %.03243, 1
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp sgt i32 %.pre, 1
  br i1 %10, label %.lr.ph48, label %._crit_edge49

.lr.ph48:                                         ; preds = %._crit_edge, %.lr.ph48
  %.13546.in = phi i32 [ %.13546, %.lr.ph48 ], [ %.pre, %._crit_edge ]
  %.045 = phi i32 [ %14, %.lr.ph48 ], [ 2, %._crit_edge ]
  %.13546 = add nsw i32 %.13546.in, -1
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sub nsw i32 %11, %.13546
  %.not40 = icmp sgt i32 %.03650, %12
  %.03650..045 = select i1 %.not40, i32 %.03650, i32 %.045
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.03650..045)
  %14 = add nuw i32 %.045, 1
  %exitcond.not = icmp eq i32 %.045, %.pre
  br i1 %exitcond.not, label %._crit_edge49, label %.lr.ph48, !llvm.loop !11

._crit_edge49:                                    ; preds = %.lr.ph48, %.lr.ph52, %._crit_edge
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %16 = add nsw i32 %.03650, -1
  %17 = icmp sgt i32 %.03650, 1
  %.pr = load i32, ptr %1, align 4, !tbaa !5
  br i1 %17, label %.lr.ph52, label %.preheader41, !llvm.loop !12

.preheader:                                       ; preds = %.preheader41, %._crit_edge62
  %18 = phi i32 [ %30, %._crit_edge62 ], [ %.pr, %.preheader41 ]
  %.13764 = phi i32 [ %29, %._crit_edge62 ], [ 2, %.preheader41 ]
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph55, label %._crit_edge62

.lr.ph55:                                         ; preds = %.preheader, %.lr.ph55
  %.13354 = phi i32 [ %21, %.lr.ph55 ], [ %18, %.preheader ]
  %.13354..13764 = call i32 @llvm.smax.i32(i32 %.13764, i32 %.13354)
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.13354..13764)
  %21 = add nsw i32 %.13354, -1
  %22 = icmp sgt i32 %.13354, 1
  br i1 %22, label %.lr.ph55, label %._crit_edge56, !llvm.loop !13

._crit_edge56:                                    ; preds = %.lr.ph55
  %.pre68 = load i32, ptr %1, align 4, !tbaa !5
  %23 = icmp sgt i32 %.pre68, 1
  br i1 %23, label %.lr.ph61, label %._crit_edge62

.lr.ph61:                                         ; preds = %._crit_edge56, %.lr.ph61
  %.359.in = phi i32 [ %.359, %.lr.ph61 ], [ %.pre68, %._crit_edge56 ]
  %.158 = phi i32 [ %27, %.lr.ph61 ], [ 2, %._crit_edge56 ]
  %.359 = add nsw i32 %.359.in, -1
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = sub nsw i32 %24, %.359
  %.not39 = icmp sgt i32 %.13764, %25
  %.13764..158 = select i1 %.not39, i32 %.13764, i32 %.158
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.13764..158)
  %27 = add nuw i32 %.158, 1
  %exitcond66.not = icmp eq i32 %.158, %.pre68
  br i1 %exitcond66.not, label %._crit_edge62, label %.lr.ph61, !llvm.loop !14

._crit_edge62:                                    ; preds = %.lr.ph61, %.preheader, %._crit_edge56
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %29 = add nuw nsw i32 %.13764, 1
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.13764, %30
  br i1 %.not.not, label %.preheader, label %._crit_edge65, !llvm.loop !15

._crit_edge65:                                    ; preds = %._crit_edge62, %0, %.preheader41
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  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 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass