; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-03-27/J -  Joining Powers - tjz.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"

@coeff = external dso_local global [60 x i64], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvex(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %11 = load i64, ptr @coeff, align 16, !tbaa !5
  store i64 %11, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %107, %1
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 60
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = sitofp i32 %18 to double
  %20 = fdiv double 1.000000e+00, %19
  %21 = call noundef double @_ZSt3powIxdEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i64 noundef %17, double noundef %20)
  %22 = fptosi double %21 to i64
  store i64 %22, ptr %6, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %60, %16
  br label %24

24:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 1, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %46, %24
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 7, ptr %5, align 4
  br label %49

30:                                               ; preds = %25
  %31 = load i64, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = load i64, ptr %6, align 8, !tbaa !5
  %34 = add nsw i64 %33, 1
  %35 = sdiv i64 %32, %34
  %36 = icmp sle i64 %31, %35
  br i1 %36, label %37, label %42

37:                                               ; preds = %30
  %38 = load i64, ptr %6, align 8, !tbaa !5
  %39 = add nsw i64 %38, 1
  %40 = load i64, ptr %7, align 8, !tbaa !5
  %41 = mul nsw i64 %40, %39
  store i64 %41, ptr %7, align 8, !tbaa !5
  br label %45

42:                                               ; preds = %30
  %43 = load i64, ptr %2, align 8, !tbaa !5
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %7, align 8, !tbaa !5
  store i32 7, ptr %5, align 4
  br label %49

45:                                               ; preds = %37
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !9
  br label %25, !llvm.loop !11

49:                                               ; preds = %42, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %7, align 8, !tbaa !5
  %52 = load i64, ptr %2, align 8, !tbaa !5
  %53 = icmp sgt i64 %51, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %50
  store i32 6, ptr %5, align 4
  br label %58

55:                                               ; preds = %50
  %56 = load i64, ptr %6, align 8, !tbaa !5
  %57 = add nsw i64 %56, 1
  store i64 %57, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %5, align 4
  br label %58

58:                                               ; preds = %55, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %59 = load i32, ptr %5, align 4
  switch i32 %59, label %112 [
    i32 0, label %60
    i32 6, label %61
  ]

60:                                               ; preds = %58
  br label %23, !llvm.loop !13

61:                                               ; preds = %58
  br label %62

62:                                               ; preds = %97, %61
  br label %63

63:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 1, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %83, %63
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = icmp slt i32 %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %64
  store i32 12, ptr %5, align 4
  br label %86

69:                                               ; preds = %64
  %70 = load i64, ptr %9, align 8, !tbaa !5
  %71 = load i64, ptr %2, align 8, !tbaa !5
  %72 = load i64, ptr %6, align 8, !tbaa !5
  %73 = sdiv i64 %71, %72
  %74 = icmp sle i64 %70, %73
  br i1 %74, label %75, label %79

75:                                               ; preds = %69
  %76 = load i64, ptr %6, align 8, !tbaa !5
  %77 = load i64, ptr %9, align 8, !tbaa !5
  %78 = mul nsw i64 %77, %76
  store i64 %78, ptr %9, align 8, !tbaa !5
  br label %82

79:                                               ; preds = %69
  %80 = load i64, ptr %2, align 8, !tbaa !5
  %81 = add nsw i64 %80, 1
  store i64 %81, ptr %9, align 8, !tbaa !5
  store i32 12, ptr %5, align 4
  br label %86

82:                                               ; preds = %75
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %10, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %10, align 4, !tbaa !9
  br label %64, !llvm.loop !14

86:                                               ; preds = %79, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %87

87:                                               ; preds = %86
  %88 = load i64, ptr %9, align 8, !tbaa !5
  %89 = load i64, ptr %2, align 8, !tbaa !5
  %90 = icmp sle i64 %88, %89
  br i1 %90, label %91, label %92

91:                                               ; preds = %87
  store i32 11, ptr %5, align 4
  br label %95

92:                                               ; preds = %87
  %93 = load i64, ptr %6, align 8, !tbaa !5
  %94 = add nsw i64 %93, -1
  store i64 %94, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %5, align 4
  br label %95

95:                                               ; preds = %92, %91
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %96 = load i32, ptr %5, align 4
  switch i32 %96, label %112 [
    i32 0, label %97
    i32 11, label %98
  ]

97:                                               ; preds = %95
  br label %62, !llvm.loop !15

98:                                               ; preds = %95
  %99 = load i64, ptr %6, align 8, !tbaa !5
  %100 = load i32, ptr %4, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [60 x i64], ptr @coeff, i64 0, i64 %101
  %103 = load i64, ptr %102, align 8, !tbaa !5
  %104 = mul nsw i64 %99, %103
  %105 = load i64, ptr %3, align 8, !tbaa !5
  %106 = add nsw i64 %105, %104
  store i64 %106, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %107

107:                                              ; preds = %98
  %108 = load i32, ptr %4, align 4, !tbaa !9
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !16

110:                                              ; preds = %15
  %111 = load i64, ptr %3, align 8, !tbaa !5
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %111

112:                                              ; preds = %95, %58
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3powIxdEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i64 noundef, double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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

@coeff = external dso_local local_unnamed_addr global [60 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5solvex(i64 noundef %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @coeff, align 16, !tbaa !5
  %3 = add nsw i64 %0, 1
  br label %5

4:                                                ; preds = %27
  ret i64 %31

5:                                                ; preds = %1, %27
  %indvars.iv = phi i64 [ 1, %1 ], [ %indvars.iv.next, %27 ]
  %.04353 = phi i64 [ %2, %1 ], [ %31, %27 ]
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  %7 = uitofp nneg i32 %6 to double
  %8 = fdiv double 1.000000e+00, %7
  %9 = tail call noundef double @_ZSt3powIxdEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i64 noundef %0, double noundef %8)
  %10 = fptosi double %9 to i64
  br label %11

11:                                               ; preds = %.loopexit46, %5
  %.038 = phi i64 [ %10, %5 ], [ %12, %.loopexit46 ]
  %12 = add nsw i64 %.038, 1
  %13 = sdiv i64 %0, %12
  br label %14

14:                                               ; preds = %11, %15
  %.03550 = phi i32 [ 0, %11 ], [ %17, %15 ]
  %.03649 = phi i64 [ 1, %11 ], [ %16, %15 ]
  %.not = icmp sgt i64 %.03649, %13
  br i1 %.not, label %.preheader.preheader, label %15

15:                                               ; preds = %14
  %16 = mul nsw i64 %.03649, %12
  %17 = add nuw nsw i32 %.03550, 1
  %18 = zext nneg i32 %17 to i64
  %exitcond.not = icmp eq i64 %indvars.iv, %18
  br i1 %exitcond.not, label %.loopexit46, label %14, !llvm.loop !9

.loopexit46:                                      ; preds = %15
  %19 = icmp sgt i64 %16, %0
  br i1 %19, label %.preheader.preheader, label %11

.preheader.preheader:                             ; preds = %.loopexit46, %14
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit
  %.2 = phi i64 [ %26, %.loopexit ], [ %.038, %.preheader.preheader ]
  %20 = sdiv i64 %0, %.2
  br label %21

21:                                               ; preds = %.preheader, %22
  %.052 = phi i32 [ 0, %.preheader ], [ %24, %22 ]
  %.03451 = phi i64 [ 1, %.preheader ], [ %23, %22 ]
  %.not44 = icmp sgt i64 %.03451, %20
  br i1 %.not44, label %.loopexit, label %22

22:                                               ; preds = %21
  %23 = mul nsw i64 %.03451, %.2
  %24 = add nuw nsw i32 %.052, 1
  %25 = zext nneg i32 %24 to i64
  %exitcond55.not = icmp eq i64 %indvars.iv, %25
  br i1 %exitcond55.not, label %.loopexit, label %21, !llvm.loop !11

.loopexit:                                        ; preds = %22, %21
  %.1 = phi i64 [ %3, %21 ], [ %23, %22 ]
  %.not45 = icmp sgt i64 %.1, %0
  %26 = add nsw i64 %.2, -1
  br i1 %.not45, label %.preheader, label %27

27:                                               ; preds = %.loopexit
  %28 = getelementptr inbounds [60 x i64], ptr @coeff, i64 0, i64 %indvars.iv
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = mul nsw i64 %29, %.2
  %31 = add nsw i64 %30, %.04353
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond57.not = icmp eq i64 %indvars.iv.next, 60
  br i1 %exitcond57.not, label %4, label %5, !llvm.loop !12
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3powIxdEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i64 noundef, double noundef) local_unnamed_addr #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 = { inlinehint 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 = !{!"long long", !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}


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