; LLVM IR from tangjz/acm-icpc :: projecteuler (8)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [1001 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 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 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
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %8

8:                                                ; preds = %63, %0
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @t, align 4, !tbaa !5
  %11 = icmp ne i32 %9, 0
  br i1 %11, label %12, label %66

12:                                               ; preds = %8
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %24, %12
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %27

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr @a, i64 %21
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %22)
  br label %24

24:                                               ; preds = %19
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !9

27:                                               ; preds = %18
  store i32 0, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %60, %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr @m, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %28
  store i32 7, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %63

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

36:                                               ; preds = %50, %35
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 10, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %53

41:                                               ; preds = %36
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = mul nsw i32 %48, %47
  store i32 %49, ptr %5, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %41
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %6, align 4, !tbaa !5
  br label %36, !llvm.loop !11

53:                                               ; preds = %40
  %54 = load i32, ptr @ans, align 4, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %59

57:                                               ; preds = %53
  %58 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %58, ptr @ans, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %57, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %60

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

63:                                               ; preds = %34
  %64 = load i32, ptr @ans, align 4, !tbaa !5
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %64)
  br label %8, !llvm.loop !13

66:                                               ; preds = %8
  ret i32 0
}

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

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

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

declare i32 @printf(ptr noundef, ...) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [1001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not28 = icmp eq i32 %2, 0
  br i1 %.not28, label %._crit_edge31, label %.lr.ph30

.lr.ph30:                                         ; preds = %0, %._crit_edge27
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph30
  %.lcssa = phi i32 [ %5, %.lr.ph30 ], [ %28, %.lr.ph ]
  store i32 0, ptr @ans, align 4, !tbaa !5
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %.not1524 = icmp sgt i32 %7, %.lcssa
  br i1 %.not1524, label %._crit_edge27, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %._crit_edge
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.preheader.us.preheader, label %.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %9 = zext nneg i32 %7 to i64
  %min.iters.check = icmp ult i32 %7, 8
  %n.vec = and i64 %9, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %9
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %18
  %indvars.iv39 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next40, %18 ]
  %.012.lcssa2325.us = phi i32 [ 0, %.preheader.us.preheader ], [ %.012.lcssa22.us, %18 ]
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us
  %indvars.iv36.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  %.01217.us.ph = phi i32 [ 1, %.preheader.us ], [ %16, %middle.block ]
  br label %scalar.ph

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %vec.phi = phi <4 x i32> [ %13, %vector.body ], [ <i32 1, i32 1, i32 1, i32 1>, %.preheader.us ]
  %vec.phi48 = phi <4 x i32> [ %14, %vector.body ], [ <i32 1, i32 1, i32 1, i32 1>, %.preheader.us ]
  %10 = add nuw nsw i64 %index, %indvars.iv39
  %11 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <4 x i32>, ptr %11, align 4, !tbaa !5
  %wide.load49 = load <4 x i32>, ptr %12, align 4, !tbaa !5
  %13 = mul <4 x i32> %wide.load, %vec.phi
  %14 = mul <4 x i32> %wide.load49, %vec.phi48
  %index.next = add nuw i64 %index, 8
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = mul <4 x i32> %14, %13
  %16 = tail call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %bin.rdx)
  br i1 %cmp.n, label %._crit_edge20.us, label %scalar.ph.preheader

17:                                               ; preds = %._crit_edge20.us
  store i32 %.lcssa47, ptr @ans, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %17, %._crit_edge20.us
  %.012.lcssa22.us = phi i32 [ %.lcssa47, %17 ], [ %.012.lcssa2325.us, %._crit_edge20.us ]
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %19 = trunc i64 %indvars.iv.next40 to i32
  %20 = add i32 %7, %19
  %.not15.us = icmp sgt i32 %20, %.lcssa
  br i1 %.not15.us, label %._crit_edge27, label %.preheader.us, !llvm.loop !13

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %scalar.ph ], [ %indvars.iv36.ph, %scalar.ph.preheader ]
  %.01217.us = phi i32 [ %24, %scalar.ph ], [ %.01217.us.ph, %scalar.ph.preheader ]
  %21 = add nuw nsw i64 %indvars.iv36, %indvars.iv39
  %22 = getelementptr inbounds [1001 x i32], ptr @a, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = mul nsw i32 %23, %.01217.us
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next37, %9
  br i1 %exitcond.not, label %._crit_edge20.us, label %scalar.ph, !llvm.loop !14

._crit_edge20.us:                                 ; preds = %scalar.ph, %middle.block
  %.lcssa47 = phi i32 [ %16, %middle.block ], [ %24, %scalar.ph ]
  %25 = icmp slt i32 %.012.lcssa2325.us, %.lcssa47
  br i1 %25, label %17, label %18

.lr.ph:                                           ; preds = %.lr.ph30, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph30 ]
  %26 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %27 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %26)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = icmp slt i64 %indvars.iv.next, %29
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !15

.preheader:                                       ; preds = %.preheader.lr.ph, %37
  %.01326 = phi i32 [ %38, %37 ], [ 0, %.preheader.lr.ph ]
  %.012.lcssa2325 = phi i32 [ %.012.lcssa22, %37 ], [ 0, %.preheader.lr.ph ]
  %31 = icmp slt i32 %.012.lcssa2325, 1
  br i1 %31, label %36, label %37

._crit_edge27:                                    ; preds = %37, %18, %._crit_edge
  %32 = phi i32 [ 0, %._crit_edge ], [ %.012.lcssa22.us, %18 ], [ %.012.lcssa22, %37 ]
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %32)
  %34 = load i32, ptr @t, align 4, !tbaa !5
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %34, 0
  br i1 %.not, label %._crit_edge31, label %.lr.ph30, !llvm.loop !16

36:                                               ; preds = %.preheader
  store i32 1, ptr @ans, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %36, %.preheader
  %.012.lcssa22 = phi i32 [ 1, %36 ], [ %.012.lcssa2325, %.preheader ]
  %38 = add nuw nsw i32 %.01326, 1
  %39 = add nsw i32 %7, %38
  %.not15 = icmp sgt i32 %39, %.lcssa
  br i1 %.not15, label %._crit_edge27, label %.preheader, !llvm.loop !13

._crit_edge31:                                    ; preds = %._crit_edge27, %0
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.mul.v4i32(<4 x i32>) #2

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 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass