; LLVM IR from tangjz/acm-icpc :: usaco/Training/Chapter 1 Getting started (palsquare)

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

@num = external dso_local global [18 x i32], align 16
@num2 = external dso_local global [10 x i32], align 16
@len = external dso_local global i32, align 4
@len2 = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZL9transform = external hidden constant [20 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5checkv() #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = load ptr, ptr @stdin, align 8, !tbaa !5
  %5 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.1, ptr noundef %4)
  %6 = load ptr, ptr @stdout, align 8, !tbaa !5
  %7 = call ptr @freopen(ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %6)
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 1, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  br label %9

9:                                                ; preds = %91, %0
  %10 = load i32, ptr %2, align 4, !tbaa !9
  %11 = icmp sle i32 %10, 300
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %94

13:                                               ; preds = %9
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = load i32, ptr %2, align 4, !tbaa !9
  %16 = mul nsw i32 %14, %15
  store i32 %16, ptr %3, align 4, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @num, i8 0, i64 72, i1 false)
  store i32 0, ptr @len, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %20, %13
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %31

20:                                               ; preds = %17
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = load i32, ptr @n, align 4, !tbaa !9
  %23 = srem i32 %21, %22
  %24 = load i32, ptr @len, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @len, align 4, !tbaa !9
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [18 x i32], ptr @num, i64 0, i64 %26
  store i32 %23, ptr %27, align 4, !tbaa !9
  %28 = load i32, ptr @n, align 4, !tbaa !9
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = sdiv i32 %29, %28
  store i32 %30, ptr %3, align 4, !tbaa !9
  br label %17, !llvm.loop !11

31:                                               ; preds = %17
  %32 = call noundef zeroext i1 @_Z5checkv()
  br i1 %32, label %33, label %90

33:                                               ; preds = %31
  %34 = load i32, ptr %2, align 4, !tbaa !9
  store i32 %34, ptr %3, align 4, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 16 @num2, i8 0, i64 40, i1 false)
  store i32 0, ptr @len2, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %38, %33
  %36 = load i32, ptr %3, align 4, !tbaa !9
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %49

38:                                               ; preds = %35
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = load i32, ptr @n, align 4, !tbaa !9
  %41 = srem i32 %39, %40
  %42 = load i32, ptr @len2, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr @len2, align 4, !tbaa !9
  %44 = sext i32 %42 to i64
  %45 = getelementptr inbounds [10 x i32], ptr @num2, i64 0, i64 %44
  store i32 %41, ptr %45, align 4, !tbaa !9
  %46 = load i32, ptr @n, align 4, !tbaa !9
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = sdiv i32 %47, %46
  store i32 %48, ptr %3, align 4, !tbaa !9
  br label %35, !llvm.loop !13

49:                                               ; preds = %35
  %50 = load i32, ptr @len2, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %65, %49
  %53 = load i32, ptr %3, align 4, !tbaa !9
  %54 = icmp sge i32 %53, 0
  br i1 %54, label %55, label %68

55:                                               ; preds = %52
  %56 = load i32, ptr %3, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [10 x i32], ptr @num2, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [20 x i8], ptr @_ZL9transform, i64 0, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !14
  %63 = sext i8 %62 to i32
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %63)
  br label %65

65:                                               ; preds = %55
  %66 = load i32, ptr %3, align 4, !tbaa !9
  %67 = add nsw i32 %66, -1
  store i32 %67, ptr %3, align 4, !tbaa !9
  br label %52, !llvm.loop !15

68:                                               ; preds = %52
  %69 = call i32 @putchar(i32 noundef 32)
  %70 = load i32, ptr @len, align 4, !tbaa !9
  %71 = sub nsw i32 %70, 1
  store i32 %71, ptr %3, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %85, %68
  %73 = load i32, ptr %3, align 4, !tbaa !9
  %74 = icmp sge i32 %73, 0
  br i1 %74, label %75, label %88

75:                                               ; preds = %72
  %76 = load i32, ptr %3, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [18 x i32], ptr @num, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [20 x i8], ptr @_ZL9transform, i64 0, i64 %80
  %82 = load i8, ptr %81, align 1, !tbaa !14
  %83 = sext i8 %82 to i32
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %83)
  br label %85

85:                                               ; preds = %75
  %86 = load i32, ptr %3, align 4, !tbaa !9
  %87 = add nsw i32 %86, -1
  store i32 %87, ptr %3, align 4, !tbaa !9
  br label %72, !llvm.loop !16

88:                                               ; preds = %72
  %89 = call i32 @putchar(i32 noundef 10)
  br label %90

90:                                               ; preds = %88, %31
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %2, align 4, !tbaa !9
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %2, align 4, !tbaa !9
  br label %9, !llvm.loop !17

94:                                               ; preds = %12
  %95 = load ptr, ptr @stdin, align 8, !tbaa !5
  %96 = call i32 @fclose(ptr noundef %95)
  %97 = load ptr, ptr @stdout, align 8, !tbaa !5
  %98 = call i32 @fclose(ptr noundef %97)
  ret i32 0
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @putchar(i32 noundef) #5

declare i32 @fclose(ptr noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { inlinehint 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" }
attributes #6 = { 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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


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

@num = external dso_local local_unnamed_addr global [18 x i32], align 16
@num2 = external dso_local local_unnamed_addr global [10 x i32], align 16
@len = external dso_local local_unnamed_addr global i32, align 4
@len2 = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZL9transform = external hidden local_unnamed_addr constant [20 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5checkv() local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = load ptr, ptr @stdin, align 8, !tbaa !5
  %2 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, ptr noundef %1)
  %3 = load ptr, ptr @stdout, align 8, !tbaa !5
  %4 = tail call ptr @freopen(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef %3)
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull @n)
  br label %11

6:                                                ; preds = %51
  %7 = load ptr, ptr @stdin, align 8, !tbaa !5
  %8 = tail call i32 @fclose(ptr noundef %7)
  %9 = load ptr, ptr @stdout, align 8, !tbaa !5
  %10 = tail call i32 @fclose(ptr noundef %9)
  ret i32 0

11:                                               ; preds = %0, %51
  %.01727 = phi i32 [ 1, %0 ], [ %52, %51 ]
  %12 = mul nuw nsw i32 %.01727, %.01727
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(72) @num, i8 0, i64 72, i1 false)
  %13 = load i32, ptr @n, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %11, %14
  %indvars.iv = phi i64 [ 0, %11 ], [ %indvars.iv.next, %14 ]
  %.019 = phi i32 [ %12, %11 ], [ %17, %14 ]
  %15 = srem i32 %.019, %13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = getelementptr inbounds [18 x i32], ptr @num, i64 0, i64 %indvars.iv
  store i32 %15, ptr %16, align 4, !tbaa !9
  %17 = sdiv i32 %.019, %13
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %18, label %14, !llvm.loop !11

18:                                               ; preds = %14
  %19 = trunc nuw i64 %indvars.iv.next to i32
  store i32 %19, ptr @len, align 4, !tbaa !9
  %20 = tail call noundef zeroext i1 @_Z5checkv()
  br i1 %20, label %21, label %51

21:                                               ; preds = %18
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) @num2, i8 0, i64 40, i1 false)
  %22 = load i32, ptr @n, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %21, %23
  %indvars.iv33 = phi i64 [ 1, %21 ], [ %indvars.iv.next34, %23 ]
  %indvars.iv30 = phi i64 [ 0, %21 ], [ %indvars.iv.next31, %23 ]
  %.121 = phi i32 [ %.01727, %21 ], [ %26, %23 ]
  %24 = srem i32 %.121, %22
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %25 = getelementptr inbounds [10 x i32], ptr @num2, i64 0, i64 %indvars.iv30
  store i32 %24, ptr %25, align 4, !tbaa !9
  %26 = sdiv i32 %.121, %22
  %.not18 = icmp eq i32 %26, 0
  %indvars.iv.next34 = add nuw i64 %indvars.iv33, 1
  br i1 %.not18, label %.lr.ph.preheader, label %23, !llvm.loop !13

.lr.ph.preheader:                                 ; preds = %23
  %27 = trunc nuw i64 %indvars.iv.next31 to i32
  store i32 %27, ptr @len2, align 4, !tbaa !9
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv35 = phi i64 [ %indvars.iv33, %.lr.ph.preheader ], [ %indvars.iv.next36, %.lr.ph ]
  %indvars.iv.next36 = add nsw i64 %indvars.iv35, -1
  %28 = and i64 %indvars.iv.next36, 4294967295
  %29 = getelementptr inbounds [10 x i32], ptr @num2, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [20 x i8], ptr @_ZL9transform, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !14
  %34 = sext i8 %33 to i32
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %34)
  %36 = trunc nuw i64 %indvars.iv35 to i32
  %37 = icmp sgt i32 %36, 1
  br i1 %37, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph
  %38 = tail call i32 @putchar(i32 noundef 32)
  %39 = load i32, ptr @len, align 4, !tbaa !9
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %.lr.ph25.preheader, label %._crit_edge26

.lr.ph25.preheader:                               ; preds = %._crit_edge
  %41 = zext nneg i32 %39 to i64
  br label %.lr.ph25

.lr.ph25:                                         ; preds = %.lr.ph25.preheader, %.lr.ph25
  %indvars.iv38 = phi i64 [ %41, %.lr.ph25.preheader ], [ %indvars.iv.next39, %.lr.ph25 ]
  %indvars.iv.next39 = add nsw i64 %indvars.iv38, -1
  %42 = getelementptr inbounds [18 x i32], ptr @num, i64 0, i64 %indvars.iv.next39
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [20 x i8], ptr @_ZL9transform, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !14
  %47 = sext i8 %46 to i32
  %48 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %47)
  %49 = icmp ugt i64 %indvars.iv38, 1
  br i1 %49, label %.lr.ph25, label %._crit_edge26, !llvm.loop !16

._crit_edge26:                                    ; preds = %.lr.ph25, %._crit_edge
  %50 = tail call i32 @putchar(i32 noundef 10)
  br label %51

51:                                               ; preds = %18, %._crit_edge26
  %52 = add nuw nsw i32 %.01727, 1
  %exitcond.not = icmp eq i32 %52, 301
  br i1 %exitcond.not, label %6, label %11, !llvm.loop !17
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #3

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 norecurse 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 #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 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { inlinehint mustprogress 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" }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass