; LLVM IR from tangjz/acm-icpc :: 51nod/1232.ll (Z5solvex)

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

@pos = external dso_local global [2521 x i32], align 16
@f = external dso_local global [19 x [49 x [2521 x i64]]], align 16
@_ZZ5solvexE3dig = external hidden global [19 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvex(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %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
  %12 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef @_ZZ5solvexE3dig, ptr noundef @.str, i64 noundef %13) #5
  store i32 %14, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr @_ZZ5solvexE3dig, i64 %16
  call void @_ZSt7reverseIPcEvT_S1_(ptr noundef @_ZZ5solvexE3dig, ptr noundef %17)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  store i32 %19, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %94, %1
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp sge i32 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %97

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [19 x i8], ptr @_ZZ5solvexE3dig, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = sub nsw i32 %29, 48
  store i32 %30, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %71, %24
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %74

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %47

39:                                               ; preds = %36
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %41, i32 noundef %42)
  %44 = sdiv i32 %40, %43
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = mul nsw i32 %44, %45
  br label %49

47:                                               ; preds = %36
  %48 = load i32, ptr %5, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %47, %39
  %50 = phi i32 [ %46, %39 ], [ %48, %47 ]
  store i32 %50, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = mul nsw i32 %51, 10
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = add nsw i32 %52, %53
  %55 = srem i32 %54, 2520
  store i32 %55, ptr %12, align 4, !tbaa !9
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [19 x [49 x [2521 x i64]]], ptr @f, i64 0, i64 %57
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [2521 x i32], ptr @pos, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [49 x [2521 x i64]], ptr %58, i64 0, i64 %63
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [2521 x i64], ptr %64, i64 0, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !5
  %69 = load i64, ptr %3, align 8, !tbaa !5
  %70 = add nsw i64 %69, %68
  store i64 %70, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %71

71:                                               ; preds = %49
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %10, align 4, !tbaa !9
  br label %31, !llvm.loop !12

74:                                               ; preds = %35
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %85

77:                                               ; preds = %74
  %78 = load i32, ptr %5, align 4, !tbaa !9
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %79, i32 noundef %80)
  %82 = sdiv i32 %78, %81
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = mul nsw i32 %82, %83
  br label %87

85:                                               ; preds = %74
  %86 = load i32, ptr %5, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %85, %77
  %88 = phi i32 [ %84, %77 ], [ %86, %85 ]
  store i32 %88, ptr %5, align 4, !tbaa !9
  %89 = load i32, ptr %6, align 4, !tbaa !9
  %90 = mul nsw i32 %89, 10
  %91 = load i32, ptr %9, align 4, !tbaa !9
  %92 = add nsw i32 %90, %91
  %93 = srem i32 %92, 2520
  store i32 %93, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %94

94:                                               ; preds = %87
  %95 = load i32, ptr %7, align 4, !tbaa !9
  %96 = add nsw i32 %95, -1
  store i32 %96, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !14

97:                                               ; preds = %23
  %98 = load i64, ptr %3, align 8, !tbaa !5
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret i64 %98
}

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

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPcEvT_S1_(ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) #4

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 #4 = { 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 #5 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

@pos = external dso_local local_unnamed_addr global [2521 x i32], align 16
@f = external dso_local local_unnamed_addr global [19 x [49 x [2521 x i64]]], align 16
@_ZZ5solvexE3dig = external hidden global [19 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvex(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) @_ZZ5solvexE3dig, ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %0) #4
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds i8, ptr @_ZZ5solvexE3dig, i64 %3
  tail call void @_ZSt7reverseIPcEvT_S1_(ptr noundef nonnull @_ZZ5solvexE3dig, ptr noundef nonnull %4)
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph44.preheader, label %._crit_edge45

.lr.ph44.preheader:                               ; preds = %1
  %6 = zext nneg i32 %2 to i64
  br label %.lr.ph44

._crit_edge45:                                    ; preds = %37, %1
  %.0.lcssa = phi i64 [ 0, %1 ], [ %.1.lcssa57, %37 ]
  ret i64 %.0.lcssa

.lr.ph44:                                         ; preds = %.lr.ph44.preheader, %37
  %indvars.iv = phi i64 [ %6, %.lr.ph44.preheader ], [ %indvars.iv.next, %37 ]
  %.041 = phi i64 [ 0, %.lr.ph44.preheader ], [ %.1.lcssa57, %37 ]
  %.03040 = phi i32 [ 1, %.lr.ph44.preheader ], [ %38, %37 ]
  %.03239 = phi i32 [ 0, %.lr.ph44.preheader ], [ %41, %37 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %7 = getelementptr inbounds [19 x i8], ptr @_ZZ5solvexE3dig, i64 0, i64 %indvars.iv.next
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = sext i8 %8 to i32
  %10 = add nsw i32 %9, -48
  %11 = icmp sgt i8 %8, 48
  br i1 %11, label %12, label %._crit_edge

12:                                               ; preds = %.lr.ph44
  %13 = mul nsw i32 %.03239, 10
  %.phi.trans.insert = sext i32 %.03040 to i64
  %.phi.trans.insert49 = getelementptr inbounds [2521 x i32], ptr @pos, i64 0, i64 %.phi.trans.insert
  %.pre = load i32, ptr %.phi.trans.insert49, align 4, !tbaa !8
  %14 = srem i32 %13, 2520
  %15 = sext i32 %.pre to i64
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [19 x [49 x [2521 x i64]]], ptr @f, i64 0, i64 %indvars.iv.next, i64 %15, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !10
  %19 = add nsw i64 %18, %.041
  %exitcond.peel.not = icmp eq i32 %10, 1
  br i1 %exitcond.peel.not, label %._crit_edge.thread, label %.peel.next

._crit_edge:                                      ; preds = %.lr.ph44
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %37, label %._crit_edge.thread

.peel.next:                                       ; preds = %12, %.peel.next
  %.137 = phi i64 [ %32, %.peel.next ], [ %19, %12 ]
  %.03136 = phi i32 [ %33, %.peel.next ], [ 1, %12 ]
  %20 = tail call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %.03040, i32 noundef %.03136)
  %21 = sdiv i32 %.03040, %20
  %22 = mul nsw i32 %21, %.03136
  %23 = add nsw i32 %.03136, %13
  %24 = srem i32 %23, 2520
  %25 = sext i32 %22 to i64
  %26 = getelementptr inbounds [2521 x i32], ptr @pos, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !8
  %28 = sext i32 %27 to i64
  %29 = sext i32 %24 to i64
  %30 = getelementptr inbounds [19 x [49 x [2521 x i64]]], ptr @f, i64 0, i64 %indvars.iv.next, i64 %28, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !10
  %32 = add nsw i64 %31, %.137
  %33 = add nuw nsw i32 %.03136, 1
  %exitcond.not = icmp eq i32 %33, %10
  br i1 %exitcond.not, label %._crit_edge.thread, label %.peel.next, !llvm.loop !12

._crit_edge.thread:                               ; preds = %.peel.next, %12, %._crit_edge
  %.1.lcssa56 = phi i64 [ %.041, %._crit_edge ], [ %19, %12 ], [ %32, %.peel.next ]
  %34 = tail call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %.03040, i32 noundef %10)
  %35 = sdiv i32 %.03040, %34
  %36 = mul nsw i32 %35, %10
  br label %37

37:                                               ; preds = %._crit_edge, %._crit_edge.thread
  %.1.lcssa57 = phi i64 [ %.1.lcssa56, %._crit_edge.thread ], [ %.041, %._crit_edge ]
  %38 = phi i32 [ %36, %._crit_edge.thread ], [ %.03040, %._crit_edge ]
  %39 = mul nsw i32 %.03239, 10
  %40 = add nsw i32 %10, %39
  %41 = srem i32 %40, 2520
  %42 = icmp sgt i64 %indvars.iv, 1
  br i1 %42, label %.lr.ph44, label %._crit_edge45, !llvm.loop !15
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPcEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 = { 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 #3 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !6, i64 0}
!12 = distinct !{!12, !13, !14}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.peeled.count", i32 1}
!15 = distinct !{!15, !13}


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