; LLVM IR from tangjz/acm-icpc :: codeforces/complete/756F.ll (Z6nxtSymv)

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

%struct.Number = type { i32, i32, i32 }

@num = external dso_local global %struct.Number, align 4
@typ = external dso_local global i32, align 4
@ptr = external dso_local global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6nxtSymv() #0 {
  %1 = load ptr, ptr @ptr, align 8, !tbaa !5
  %2 = load i8, ptr %1, align 1, !tbaa !9
  %3 = sext i8 %2 to i32
  switch i32 %3, label %17 [
    i32 0, label %4
    i32 43, label %5
    i32 45, label %8
    i32 40, label %11
    i32 41, label %14
  ]

4:                                                ; preds = %0
  store i32 0, ptr @typ, align 4, !tbaa !10
  br label %62

5:                                                ; preds = %0
  store i32 1, ptr @typ, align 4, !tbaa !10
  %6 = load ptr, ptr @ptr, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i32 1
  store ptr %7, ptr @ptr, align 8, !tbaa !5
  br label %62

8:                                                ; preds = %0
  store i32 2, ptr @typ, align 4, !tbaa !10
  %9 = load ptr, ptr @ptr, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i32 1
  store ptr %10, ptr @ptr, align 8, !tbaa !5
  br label %62

11:                                               ; preds = %0
  store i32 3, ptr @typ, align 4, !tbaa !10
  %12 = load ptr, ptr @ptr, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i32 1
  store ptr %13, ptr @ptr, align 8, !tbaa !5
  br label %62

14:                                               ; preds = %0
  store i32 4, ptr @typ, align 4, !tbaa !10
  %15 = load ptr, ptr @ptr, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i32 1
  store ptr %16, ptr @ptr, align 8, !tbaa !5
  br label %62

17:                                               ; preds = %0
  store i32 5, ptr @typ, align 4, !tbaa !10
  store i32 0, ptr getelementptr inbounds (%struct.Number, ptr @num, i32 0, i32 1), align 4, !tbaa !12
  store i32 0, ptr @num, align 4, !tbaa !14
  store i32 1, ptr getelementptr inbounds (%struct.Number, ptr @num, i32 0, i32 2), align 4, !tbaa !15
  br label %18

18:                                               ; preds = %58, %17
  %19 = load ptr, ptr @ptr, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = icmp sge i32 %21, 48
  br i1 %22, label %23, label %28

23:                                               ; preds = %18
  %24 = load ptr, ptr @ptr, align 8, !tbaa !5
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = icmp sle i32 %26, 57
  br label %28

28:                                               ; preds = %23, %18
  %29 = phi i1 [ false, %18 ], [ %27, %23 ]
  br i1 %29, label %30, label %61

30:                                               ; preds = %28
  %31 = load i32, ptr @num, align 4, !tbaa !14
  %32 = sext i32 %31 to i64
  %33 = mul nsw i64 10, %32
  %34 = load ptr, ptr @ptr, align 8, !tbaa !5
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = sub nsw i32 %36, 48
  %38 = sext i32 %37 to i64
  %39 = add nsw i64 %33, %38
  %40 = srem i64 %39, 1000000007
  %41 = trunc i64 %40 to i32
  store i32 %41, ptr @num, align 4, !tbaa !14
  %42 = load i32, ptr getelementptr inbounds (%struct.Number, ptr @num, i32 0, i32 1), align 4, !tbaa !12
  %43 = sext i32 %42 to i64
  %44 = mul nsw i64 10, %43
  %45 = load ptr, ptr @ptr, align 8, !tbaa !5
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = sub nsw i32 %47, 48
  %49 = sext i32 %48 to i64
  %50 = add nsw i64 %44, %49
  %51 = srem i64 %50, 1000000006
  %52 = trunc i64 %51 to i32
  store i32 %52, ptr getelementptr inbounds (%struct.Number, ptr @num, i32 0, i32 1), align 4, !tbaa !12
  %53 = load i32, ptr getelementptr inbounds (%struct.Number, ptr @num, i32 0, i32 2), align 4, !tbaa !15
  %54 = sext i32 %53 to i64
  %55 = mul nsw i64 10, %54
  %56 = srem i64 %55, 1000000007
  %57 = trunc i64 %56 to i32
  store i32 %57, ptr getelementptr inbounds (%struct.Number, ptr @num, i32 0, i32 2), align 4, !tbaa !15
  br label %58

58:                                               ; preds = %30
  %59 = load ptr, ptr @ptr, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i32 1
  store ptr %60, ptr @ptr, align 8, !tbaa !5
  br label %18, !llvm.loop !16

61:                                               ; preds = %28
  br label %62

62:                                               ; preds = %61, %14, %11, %8, %5, %4
  ret void
}

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

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


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

%struct.Number = type { i32, i32, i32 }

@num = external dso_local local_unnamed_addr global %struct.Number, align 4
@typ = external dso_local local_unnamed_addr global i32, align 4
@ptr = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @_Z6nxtSymv() local_unnamed_addr #0 {
  %1 = load ptr, ptr @ptr, align 8, !tbaa !5
  %2 = load i8, ptr %1, align 1, !tbaa !9
  switch i8 %2, label %12 [
    i8 0, label %3
    i8 43, label %4
    i8 45, label %6
    i8 40, label %8
    i8 41, label %10
  ]

3:                                                ; preds = %0
  store i32 0, ptr @typ, align 4, !tbaa !10
  br label %.critedge

4:                                                ; preds = %0
  store i32 1, ptr @typ, align 4, !tbaa !10
  %5 = getelementptr inbounds i8, ptr %1, i64 1
  store ptr %5, ptr @ptr, align 8, !tbaa !5
  br label %.critedge

6:                                                ; preds = %0
  store i32 2, ptr @typ, align 4, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %1, i64 1
  store ptr %7, ptr @ptr, align 8, !tbaa !5
  br label %.critedge

8:                                                ; preds = %0
  store i32 3, ptr @typ, align 4, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %1, i64 1
  store ptr %9, ptr @ptr, align 8, !tbaa !5
  br label %.critedge

10:                                               ; preds = %0
  store i32 4, ptr @typ, align 4, !tbaa !10
  %11 = getelementptr inbounds i8, ptr %1, i64 1
  store ptr %11, ptr @ptr, align 8, !tbaa !5
  br label %.critedge

12:                                               ; preds = %0
  store i32 5, ptr @typ, align 4, !tbaa !10
  store i32 0, ptr getelementptr inbounds (i8, ptr @num, i64 4), align 4, !tbaa !12
  store i32 0, ptr @num, align 4, !tbaa !14
  store i32 1, ptr getelementptr inbounds (i8, ptr @num, i64 8), align 4, !tbaa !15
  %13 = load i8, ptr %1, align 1, !tbaa !9
  %14 = add i8 %13, -48
  %or.cond2 = icmp ult i8 %14, 10
  br i1 %or.cond2, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %12, %.lr.ph
  %15 = phi i8 [ %36, %.lr.ph ], [ %13, %12 ]
  %16 = phi ptr [ %35, %.lr.ph ], [ %1, %12 ]
  %17 = phi i64 [ %23, %.lr.ph ], [ 0, %12 ]
  %18 = phi i64 [ %30, %.lr.ph ], [ 0, %12 ]
  %19 = phi i64 [ %33, %.lr.ph ], [ 1, %12 ]
  %20 = mul nsw i64 %17, 10
  %narrow = add nsw i8 %15, -48
  %21 = zext nneg i8 %narrow to i64
  %22 = add nsw i64 %20, %21
  %23 = srem i64 %22, 1000000007
  %24 = trunc nsw i64 %23 to i32
  store i32 %24, ptr @num, align 4, !tbaa !14
  %25 = mul nsw i64 %18, 10
  %26 = load i8, ptr %16, align 1, !tbaa !9
  %27 = sext i8 %26 to i64
  %28 = add nsw i64 %27, -48
  %29 = add nsw i64 %28, %25
  %30 = srem i64 %29, 1000000006
  %31 = trunc nsw i64 %30 to i32
  store i32 %31, ptr getelementptr inbounds (i8, ptr @num, i64 4), align 4, !tbaa !12
  %32 = mul nsw i64 %19, 10
  %33 = srem i64 %32, 1000000007
  %34 = trunc nsw i64 %33 to i32
  store i32 %34, ptr getelementptr inbounds (i8, ptr @num, i64 8), align 4, !tbaa !15
  %35 = getelementptr inbounds i8, ptr %16, i64 1
  store ptr %35, ptr @ptr, align 8, !tbaa !5
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = add i8 %36, -48
  %or.cond = icmp ult i8 %37, 10
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !16

.critedge:                                        ; preds = %.lr.ph, %12, %10, %8, %6, %4, %3
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 4}
!13 = !{!"_ZTS6Number", !11, i64 0, !11, i64 4, !11, i64 8}
!14 = !{!13, !11, i64 0}
!15 = !{!13, !11, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SimplifyCFGPass