; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (1998（Merzirac奇数幻方生成法构造）)

; 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: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [20 x [20 x i32]], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = 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 1600, 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  br label %13

13:                                               ; preds = %92, %0
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr %4, align 4, !tbaa !5
  %16 = icmp ne i32 %14, 0
  br i1 %16, label %17, label %93

17:                                               ; preds = %13
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  store i32 0, ptr %8, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  %21 = sdiv i32 %20, 2
  %22 = sub nsw i32 %21, 1
  store i32 %22, ptr %9, align 4, !tbaa !5
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %62, %17
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = mul nsw i32 %25, %26
  %28 = icmp sle i32 %24, %27
  br i1 %28, label %29, label %65

29:                                               ; preds = %23
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %8, align 4, !tbaa !5
  store i32 %30, ptr %10, align 4, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %9, align 4, !tbaa !5
  store i32 %32, ptr %11, align 4, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [20 x [20 x i32]], ptr %3, i64 0, i64 %36
  %38 = load i32, ptr %11, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [20 x i32], ptr %37, i64 0, i64 %39
  store i32 %34, ptr %40, align 4, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = srem i32 %41, %42
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %50

45:                                               ; preds = %29
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = add nsw i32 %46, 2
  store i32 %47, ptr %8, align 4, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = sub nsw i32 %48, 1
  store i32 %49, ptr %9, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %45, %29
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = icmp slt i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %50
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sub nsw i32 %54, 1
  store i32 %55, ptr %8, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %53, %50
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = icmp sge i32 %57, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %56
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %60, %56
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %7, align 4, !tbaa !5
  br label %23, !llvm.loop !9

65:                                               ; preds = %23
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %89, %65
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = icmp slt i32 %67, %68
  br i1 %69, label %70, label %92

70:                                               ; preds = %66
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %84, %70
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = icmp slt i32 %72, %73
  br i1 %74, label %75, label %87

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

84:                                               ; preds = %75
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %6, align 4, !tbaa !5
  br label %71, !llvm.loop !11

87:                                               ; preds = %71
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %89

89:                                               ; preds = %87
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %5, align 4, !tbaa !5
  br label %66, !llvm.loop !12

92:                                               ; preds = %66
  br label %13, !llvm.loop !13

93:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  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 1600, 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 = { 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 #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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca [20 x [20 x i32]], align 16
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 1600, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr %3, align 4, !tbaa !5
  %.not34 = icmp eq i32 %5, 0
  br i1 %.not34, label %._crit_edge37, label %.lr.ph36

.loopexit:                                        ; preds = %._crit_edge, %.lr.ph36, %.preheader26
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %._crit_edge37, label %.lr.ph36, !llvm.loop !9

.lr.ph36:                                         ; preds = %0, %.loopexit
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %10 = load i32, ptr %1, align 4
  %.not2327 = icmp eq i32 %10, 0
  br i1 %.not2327, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph36
  %11 = mul i32 %10, %10
  %12 = add nsw i32 %10, 1
  %13 = sdiv i32 %12, 2
  %14 = add nsw i32 %13, -1
  %15 = add nsw i32 %10, -1
  %umax = call i32 @llvm.umax.i32(i32 %11, i32 1)
  br label %17

.preheader26:                                     ; preds = %17
  %16 = icmp sgt i32 %10, 0
  br i1 %16, label %.preheader, label %.loopexit

17:                                               ; preds = %.lr.ph, %17
  %.01930 = phi i32 [ %14, %.lr.ph ], [ %spec.store.select, %17 ]
  %.02029 = phi i32 [ 0, %.lr.ph ], [ %.2, %17 ]
  %.02228 = phi i32 [ 1, %.lr.ph ], [ %25, %17 ]
  %18 = sext i32 %.02029 to i64
  %19 = sext i32 %.01930 to i64
  %20 = getelementptr inbounds [20 x [20 x i32]], ptr %2, i64 0, i64 %18, i64 %19
  store i32 %.02228, ptr %20, align 4, !tbaa !5
  %21 = srem i32 %.02228, %10
  %22 = icmp ne i32 %21, 0
  %spec.select.v = select i1 %22, i32 -1, i32 1
  %spec.select = add nsw i32 %spec.select.v, %.02029
  %23 = zext i1 %22 to i32
  %spec.select25 = add nsw i32 %.01930, %23
  %24 = icmp slt i32 %spec.select, 0
  %.2 = select i1 %24, i32 %15, i32 %spec.select
  %.not24 = icmp slt i32 %spec.select25, %10
  %spec.store.select = select i1 %.not24, i32 %spec.select25, i32 0
  %25 = add nuw i32 %.02228, 1
  %exitcond.not = icmp eq i32 %.02228, %umax
  br i1 %exitcond.not, label %.preheader26, label %17, !llvm.loop !11

.preheader:                                       ; preds = %.preheader26, %._crit_edge
  %26 = phi i32 [ %35, %._crit_edge ], [ %10, %.preheader26 ]
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %._crit_edge ], [ 0, %.preheader26 ]
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.lr.ph32, label %._crit_edge

.lr.ph32:                                         ; preds = %.preheader, %.lr.ph32
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph32 ], [ 0, %.preheader ]
  %28 = getelementptr inbounds [20 x [20 x i32]], ptr %2, i64 0, i64 %indvars.iv39, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %29)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %indvars.iv.next, %32
  br i1 %33, label %.lr.ph32, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph32, %.preheader
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next40, %36
  br i1 %37, label %.preheader, label %.loopexit, !llvm.loop !13

._crit_edge37:                                    ; preds = %.loopexit, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 1600, ptr nonnull %2) #4
  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.umax.i32(i32, i32) #3

attributes #0 = { mustprogress nofree norecurse 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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