; LLVM IR from tangjz/acm-icpc :: hdu/5527.ll (Z5solvei)

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

@c = external dso_local global [10 x i32], align 16
@_ZL1w = external hidden constant [10 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5solvei(i32 noundef %0) #0 {
  %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
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i32 2000000, ptr %2, align 4
  br label %82

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 9, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %71, %11
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %74

16:                                               ; preds = %12
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 7
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 4
  br i1 %21, label %22, label %48

22:                                               ; preds = %19, %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10 x i32], ptr @_ZL1w, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sdiv i32 %23, %27
  %29 = ashr i32 %28, 1
  store i32 %29, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = ashr i32 %33, 1
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %34)
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = shl i32 %35, 1
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = add nsw i32 %37, %36
  store i32 %38, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10 x i32], ptr @_ZL1w, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = mul nsw i32 %39, %43
  %45 = shl i32 %44, 1
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sub nsw i32 %46, %45
  store i32 %47, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %70

48:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10 x i32], ptr @_ZL1w, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sdiv i32 %49, %53
  store i32 %54, ptr %7, align 4, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %7, i32 noundef %58)
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr %4, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [10 x i32], ptr @_ZL1w, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = mul nsw i32 %62, %66
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = sub nsw i32 %68, %67
  store i32 %69, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %70

70:                                               ; preds = %48, %22
  br label %71

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

74:                                               ; preds = %15
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %78

77:                                               ; preds = %74
  br label %80

78:                                               ; preds = %74
  %79 = load i32, ptr %4, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %78, %77
  %81 = phi i32 [ 2000000, %77 ], [ %79, %78 ]
  store i32 %81, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %82

82:                                               ; preds = %80, %10
  %83 = load i32, ptr %2, align 4
  ret i32 %83
}

; 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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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"}


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

@c = external dso_local local_unnamed_addr global [10 x i32], align 16
@_ZL1w = external hidden local_unnamed_addr constant [10 x i32], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5solvei(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = icmp slt i32 %0, 0
  br i1 %4, label %29, label %.preheader

5:                                                ; preds = %28
  %.not = icmp eq i32 %.123, 0
  %6 = select i1 %.not, i32 %.1, i32 2000000
  br label %29

.preheader:                                       ; preds = %1, %28
  %indvars.iv = phi i64 [ %indvars.iv.next, %28 ], [ 9, %1 ]
  %.02128 = phi i32 [ %.1, %28 ], [ 0, %1 ]
  %.02227 = phi i32 [ %.123, %28 ], [ %0, %1 ]
  %7 = trunc nuw nsw i64 %indvars.iv to i32
  switch i32 %7, label %20 [
    i32 7, label %8
    i32 4, label %8
  ]

8:                                                ; preds = %.preheader, %.preheader
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  %9 = getelementptr inbounds [10 x i32], ptr @_ZL1w, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sdiv i32 %.02227, %10
  %12 = ashr i32 %11, 1
  store i32 %12, ptr %2, align 4, !tbaa !5
  %13 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = ashr i32 %14, 1
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %15)
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = shl i32 %16, 1
  %18 = shl i32 %10, 1
  %19 = mul i32 %18, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  br label %28

20:                                               ; preds = %.preheader
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  %21 = getelementptr inbounds [10 x i32], ptr @_ZL1w, i64 0, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sdiv i32 %.02227, %22
  store i32 %23, ptr %3, align 4, !tbaa !5
  %24 = getelementptr inbounds [10 x i32], ptr @c, i64 0, i64 %indvars.iv
  %25 = load i32, ptr %24, align 4, !tbaa !5
  call void @_Z3updRii(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %25)
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = mul nsw i32 %26, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  br label %28

28:                                               ; preds = %8, %20
  %.pn = phi i32 [ %19, %8 ], [ %27, %20 ]
  %.pn26 = phi i32 [ %17, %8 ], [ %26, %20 ]
  %.1 = add nsw i32 %.pn26, %.02128
  %.123 = sub nsw i32 %.02227, %.pn
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not31 = icmp eq i64 %indvars.iv, 0
  br i1 %.not31, label %5, label %.preheader, !llvm.loop !9

29:                                               ; preds = %1, %5
  %.024 = phi i32 [ %6, %5 ], [ 2000000, %1 ]
  ret i32 %.024
}

; 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

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass