; LLVM IR from tangjz/acm-icpc :: self_training/2015-03-03/P.ll (Z3dfsi)

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

@deg = external dso_local global [10001 x i32], align 16
@pre = external dso_local global [10001 x i32], align 16
@nxt = external dso_local global [20002 x i32], align 16
@to = external dso_local global [20002 x i32], align 16
@k = external dso_local global [10001 x double], align 16
@e = external dso_local global [10001 x double], align 16
@f = external dso_local global [10001 x double], align 16
@g = external dso_local global [10001 x double], align 16
@h = external dso_local global [10001 x double], align 16
@vis = external dso_local global [10001 x i8], 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 void @_Z3dfsi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %8
  store i8 1, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store double 0.000000e+00, ptr %3, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [10001 x i32], ptr @pre, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %13, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %62, %1
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [20002 x i32], ptr @to, i64 0, i64 %20
  store ptr %21, ptr %6, align 8, !tbaa !13
  %22 = load ptr, ptr %6, align 8, !tbaa !13
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9, !range !15, !noundef !16
  %27 = trunc i8 %26 to i1
  br i1 %27, label %28, label %29

28:                                               ; preds = %18
  store i32 4, ptr %5, align 4
  br label %59

29:                                               ; preds = %18
  %30 = load ptr, ptr %6, align 8, !tbaa !13
  %31 = load i32, ptr %30, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %31)
  %32 = load ptr, ptr %6, align 8, !tbaa !13
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [10001 x double], ptr @f, i64 0, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !11
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [10001 x double], ptr @f, i64 0, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = fadd double %40, %36
  store double %41, ptr %39, align 8, !tbaa !11
  %42 = load ptr, ptr %6, align 8, !tbaa !13
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [10001 x double], ptr @h, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !11
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [10001 x double], ptr @h, i64 0, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = fadd double %50, %46
  store double %51, ptr %49, align 8, !tbaa !11
  %52 = load ptr, ptr %6, align 8, !tbaa !13
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [10001 x double], ptr @g, i64 0, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !11
  %57 = load double, ptr %3, align 8, !tbaa !11
  %58 = fadd double %57, %56
  store double %58, ptr %3, align 8, !tbaa !11
  store i32 0, ptr %5, align 4
  br label %59

59:                                               ; preds = %29, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %60 = load i32, ptr %5, align 4
  switch i32 %60, label %144 [
    i32 0, label %61
    i32 4, label %62
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61, %59
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [20002 x i32], ptr @nxt, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  store i32 %66, ptr %4, align 4, !tbaa !5
  br label %14, !llvm.loop !17

67:                                               ; preds = %17
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [10001 x double], ptr @k, i64 0, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !11
  %72 = fsub double 1.000000e+00, %71
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [10001 x double], ptr @e, i64 0, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !11
  %77 = fsub double %72, %76
  %78 = load i32, ptr %2, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [10001 x i32], ptr @deg, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = sitofp i32 %81 to double
  %83 = fdiv double %77, %82
  %84 = load i32, ptr %2, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [10001 x double], ptr @g, i64 0, i64 %85
  store double %83, ptr %86, align 8, !tbaa !11
  %87 = load i32, ptr %2, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [10001 x double], ptr @g, i64 0, i64 %88
  %90 = load double, ptr %89, align 8, !tbaa !11
  %91 = load double, ptr %3, align 8, !tbaa !11
  %92 = fmul double %91, %90
  store double %92, ptr %3, align 8, !tbaa !11
  %93 = load i32, ptr %2, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [10001 x double], ptr @k, i64 0, i64 %94
  %96 = load double, ptr %95, align 8, !tbaa !11
  %97 = load i32, ptr %2, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [10001 x double], ptr @g, i64 0, i64 %98
  %100 = load double, ptr %99, align 8, !tbaa !11
  %101 = load i32, ptr %2, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [10001 x double], ptr @f, i64 0, i64 %102
  %104 = load double, ptr %103, align 8, !tbaa !11
  %105 = call double @llvm.fmuladd.f64(double %100, double %104, double %96)
  %106 = load double, ptr %3, align 8, !tbaa !11
  %107 = fsub double 1.000000e+00, %106
  %108 = fdiv double %105, %107
  %109 = load i32, ptr %2, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [10001 x double], ptr @f, i64 0, i64 %110
  store double %108, ptr %111, align 8, !tbaa !11
  %112 = load i32, ptr %2, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [10001 x double], ptr @k, i64 0, i64 %113
  %115 = load double, ptr %114, align 8, !tbaa !11
  %116 = fsub double 1.000000e+00, %115
  %117 = load i32, ptr %2, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [10001 x double], ptr @e, i64 0, i64 %118
  %120 = load double, ptr %119, align 8, !tbaa !11
  %121 = fsub double %116, %120
  %122 = load i32, ptr %2, align 4, !tbaa !5
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [10001 x double], ptr @g, i64 0, i64 %123
  %125 = load double, ptr %124, align 8, !tbaa !11
  %126 = load i32, ptr %2, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [10001 x double], ptr @h, i64 0, i64 %127
  %129 = load double, ptr %128, align 8, !tbaa !11
  %130 = call double @llvm.fmuladd.f64(double %125, double %129, double %121)
  %131 = load double, ptr %3, align 8, !tbaa !11
  %132 = fsub double 1.000000e+00, %131
  %133 = fdiv double %130, %132
  %134 = load i32, ptr %2, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [10001 x double], ptr @h, i64 0, i64 %135
  store double %133, ptr %136, align 8, !tbaa !11
  %137 = load double, ptr %3, align 8, !tbaa !11
  %138 = fsub double 1.000000e+00, %137
  %139 = load i32, ptr %2, align 4, !tbaa !5
  %140 = sext i32 %139 to i64
  %141 = getelementptr inbounds [10001 x double], ptr @g, i64 0, i64 %140
  %142 = load double, ptr %141, align 8, !tbaa !11
  %143 = fdiv double %142, %138
  store double %143, ptr %141, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void

144:                                              ; preds = %59
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@deg = external dso_local local_unnamed_addr global [10001 x i32], align 16
@pre = external dso_local local_unnamed_addr global [10001 x i32], align 16
@nxt = external dso_local local_unnamed_addr global [20002 x i32], align 16
@to = external dso_local local_unnamed_addr global [20002 x i32], align 16
@k = external dso_local local_unnamed_addr global [10001 x double], align 16
@e = external dso_local local_unnamed_addr global [10001 x double], align 16
@f = external dso_local local_unnamed_addr global [10001 x double], align 16
@g = external dso_local local_unnamed_addr global [10001 x double], align 16
@h = external dso_local local_unnamed_addr global [10001 x double], align 16
@vis = external dso_local local_unnamed_addr global [10001 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %2
  store i8 1, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds [10001 x i32], ptr @pre, i64 0, i64 %2
  %.03132 = load i32, ptr %4, align 4, !tbaa !9
  %.not33 = icmp eq i32 %.03132, 0
  br i1 %.not33, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds [10001 x double], ptr @f, i64 0, i64 %2
  %6 = getelementptr inbounds [10001 x double], ptr @h, i64 0, i64 %2
  br label %29

._crit_edge:                                      ; preds = %51, %1
  %.0.lcssa = phi double [ 0.000000e+00, %1 ], [ %.1, %51 ]
  %7 = getelementptr inbounds [10001 x double], ptr @k, i64 0, i64 %2
  %8 = load double, ptr %7, align 8, !tbaa !11
  %9 = fsub double 1.000000e+00, %8
  %10 = getelementptr inbounds [10001 x double], ptr @e, i64 0, i64 %2
  %11 = load double, ptr %10, align 8, !tbaa !11
  %12 = fsub double %9, %11
  %13 = getelementptr inbounds [10001 x i32], ptr @deg, i64 0, i64 %2
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = sitofp i32 %14 to double
  %16 = fdiv double %12, %15
  %17 = getelementptr inbounds [10001 x double], ptr @g, i64 0, i64 %2
  %18 = fmul double %.0.lcssa, %16
  %19 = getelementptr inbounds [10001 x double], ptr @f, i64 0, i64 %2
  %20 = load double, ptr %19, align 8, !tbaa !11
  %21 = tail call double @llvm.fmuladd.f64(double %16, double %20, double %8)
  %22 = fsub double 1.000000e+00, %18
  %23 = fdiv double %21, %22
  store double %23, ptr %19, align 8, !tbaa !11
  %24 = getelementptr inbounds [10001 x double], ptr @h, i64 0, i64 %2
  %25 = load double, ptr %24, align 8, !tbaa !11
  %26 = tail call double @llvm.fmuladd.f64(double %16, double %25, double %12)
  %27 = fdiv double %26, %22
  store double %27, ptr %24, align 8, !tbaa !11
  %28 = fdiv double %16, %22
  store double %28, ptr %17, align 8, !tbaa !11
  ret void

29:                                               ; preds = %.lr.ph, %51
  %.03135 = phi i32 [ %.03132, %.lr.ph ], [ %.031, %51 ]
  %.034 = phi double [ 0.000000e+00, %.lr.ph ], [ %.1, %51 ]
  %30 = sext i32 %.03135 to i64
  %31 = getelementptr inbounds [20002 x i32], ptr @to, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10001 x i8], ptr @vis, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !5, !range !13, !noundef !14
  %36 = trunc nuw i8 %35 to i1
  br i1 %36, label %51, label %37

37:                                               ; preds = %29
  tail call void @_Z3dfsi(i32 noundef %32)
  %38 = load i32, ptr %31, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10001 x double], ptr @f, i64 0, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = load double, ptr %5, align 8, !tbaa !11
  %43 = fadd double %41, %42
  store double %43, ptr %5, align 8, !tbaa !11
  %44 = getelementptr inbounds [10001 x double], ptr @h, i64 0, i64 %39
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = load double, ptr %6, align 8, !tbaa !11
  %47 = fadd double %45, %46
  store double %47, ptr %6, align 8, !tbaa !11
  %48 = getelementptr inbounds [10001 x double], ptr @g, i64 0, i64 %39
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fadd double %.034, %49
  br label %51

51:                                               ; preds = %29, %37
  %.1 = phi double [ %50, %37 ], [ %.034, %29 ]
  %52 = getelementptr inbounds [20002 x i32], ptr @nxt, i64 0, i64 %30
  %.031 = load i32, ptr %52, align 4, !tbaa !9
  %.not = icmp eq i32 %.031, 0
  br i1 %.not, label %._crit_edge, label %29, !llvm.loop !15
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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