; LLVM IR from tangjz/acm-icpc :: lydsy (1308)

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

@_ZZ4mainE6table1 = external hidden constant [5 x i32], align 16
@_ZZ4mainE6table2 = external hidden constant [4 x i32], align 16
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4initRiPi(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) #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 nounwind uwtable
declare dso_local noundef i32 @_Z4div5RiPi(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [127 x i32], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 508, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  br label %6

6:                                                ; preds = %61, %0
  %7 = getelementptr inbounds [127 x i32], ptr %3, i64 0, i64 0
  %8 = call noundef zeroext i1 @_Z4initRiPi(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef %7)
  br i1 %8, label %9, label %64

9:                                                ; preds = %6
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %58, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %18

13:                                               ; preds = %10
  %14 = getelementptr inbounds [127 x i32], ptr %3, i64 0, i64 0
  %15 = load i32, ptr %14, align 16, !tbaa !5
  %16 = icmp ne i32 %15, 0
  %17 = xor i1 %16, true
  br label %18

18:                                               ; preds = %13, %10
  %19 = phi i1 [ false, %10 ], [ %17, %13 ]
  %20 = xor i1 %19, true
  br i1 %20, label %21, label %61

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %22 = getelementptr inbounds [127 x i32], ptr %3, i64 0, i64 0
  %23 = call noundef i32 @_Z4div5RiPi(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef %22)
  store i32 %23, ptr %5, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [5 x i32], ptr @_ZZ4mainE6table1, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %35

30:                                               ; preds = %21
  %31 = getelementptr inbounds [127 x i32], ptr %3, i64 0, i64 0
  %32 = load i32, ptr %31, align 16, !tbaa !5
  %33 = and i32 %32, 1
  %34 = icmp ne i32 %33, 0
  br label %35

35:                                               ; preds = %30, %21
  %36 = phi i1 [ false, %21 ], [ %34, %30 ]
  %37 = zext i1 %36 to i64
  %38 = select i1 %36, i32 5, i32 0
  %39 = add nsw i32 %27, %38
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = mul nsw i32 %40, %39
  store i32 %41, ptr %4, align 4, !tbaa !5
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %44, label %48

44:                                               ; preds = %35
  %45 = getelementptr inbounds [127 x i32], ptr %3, i64 0, i64 0
  %46 = load i32, ptr %45, align 16, !tbaa !5
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %57

48:                                               ; preds = %44, %35
  %49 = getelementptr inbounds [127 x i32], ptr %3, i64 0, i64 0
  %50 = load i32, ptr %49, align 16, !tbaa !5
  %51 = and i32 %50, 3
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [4 x i32], ptr @_ZZ4mainE6table2, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = mul nsw i32 %55, %54
  store i32 %56, ptr %4, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %48, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = srem i32 %59, 10
  store i32 %60, ptr %4, align 4, !tbaa !5
  br label %10, !llvm.loop !9

61:                                               ; preds = %18
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %62)
  br label %6, !llvm.loop !11

64:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 508, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

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 = { 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 #3 = { 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 #4 = { "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 = !{!"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}


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

@_ZZ4mainE6table1 = external hidden local_unnamed_addr constant [5 x i32], align 16
@_ZZ4mainE6table2 = external hidden local_unnamed_addr constant [4 x i32], align 16
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4initRiPi(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4div5RiPi(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca [127 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 508, ptr nonnull %2) #5
  %3 = call noundef zeroext i1 @_Z4initRiPi(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull %2)
  br i1 %3, label %.preheader, label %._crit_edge13

.preheader:                                       ; preds = %0, %._crit_edge
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 1
  %6 = load i32, ptr %2, align 16
  %.not10 = icmp ne i32 %6, 0
  %.not911 = select i1 %5, i1 true, i1 %.not10
  br i1 %.not911, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %22
  %.012 = phi i32 [ %28, %22 ], [ 1, %.preheader ]
  %7 = call noundef i32 @_Z4div5RiPi(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull %2)
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [5 x i32], ptr @_ZZ4mainE6table1, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %7, 1
  %12 = load i32, ptr %2, align 16
  %13 = and i32 %12, 1
  %14 = icmp ne i32 %13, 0
  %15 = select i1 %11, i1 %14, i1 false
  %16 = select i1 %15, i32 5, i32 0
  %17 = add nsw i32 %16, %10
  %18 = mul nsw i32 %17, %.012
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = icmp ne i32 %19, 1
  %21 = icmp ne i32 %12, 0
  %or.cond = select i1 %20, i1 true, i1 %21
  br i1 %or.cond, label %22, label %._crit_edge.loopexit

22:                                               ; preds = %.lr.ph
  %23 = and i32 %12, 3
  %24 = zext nneg i32 %23 to i64
  %25 = getelementptr inbounds [4 x i32], ptr @_ZZ4mainE6table2, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = mul nsw i32 %26, %18
  %28 = srem i32 %27, 10
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %29 = srem i32 %18, 10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.0.lcssa = phi i32 [ 1, %.preheader ], [ %29, %._crit_edge.loopexit ]
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.0.lcssa)
  %31 = call noundef zeroext i1 @_Z4initRiPi(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull %2)
  br i1 %31, label %.preheader, label %._crit_edge13, !llvm.loop !9

._crit_edge13:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 508, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0
}

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass