; LLVM IR from tangjz/acm-icpc :: hdu/4754.ll (Z3dfsid)

; 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.Edge = type { i32, i32, double }

@T = external dso_local global i32, align 4
@lev = external dso_local global [303 x i32], align 16
@cur = external dso_local global [303 x i32], align 16
@e = external dso_local global [181203 x %struct.Edge], 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sgnd(double noundef) #1

; 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 double @_Z3dfsid(i32 noundef %0, double noundef %1) #2 {
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr @T, align 4, !tbaa !5
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %2
  %15 = load double, ptr %5, align 8, !tbaa !9
  store double %15, ptr %3, align 8
  br label %119

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [303 x i32], ptr @cur, i64 0, i64 %18
  store ptr %19, ptr %8, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %100, %16
  %21 = load ptr, ptr %8, align 8, !tbaa !11
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp ne i32 %22, -1
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 2, ptr %9, align 4
  br label %108

25:                                               ; preds = %20
  %26 = load ptr, ptr %8, align 8, !tbaa !11
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.Edge, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [303 x i32], ptr @lev, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [303 x i32], ptr @lev, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = icmp eq i32 %34, %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  br i1 %40, label %41, label %70

41:                                               ; preds = %25
  %42 = load ptr, ptr %8, align 8, !tbaa !11
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.Edge, ptr %45, i32 0, i32 2
  %47 = load double, ptr %46, align 8, !tbaa !15
  %48 = call noundef i32 @_Z3sgnd(double noundef %47)
  %49 = icmp sgt i32 %48, 0
  br i1 %49, label %50, label %70

50:                                               ; preds = %41
  %51 = load ptr, ptr %8, align 8, !tbaa !11
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.Edge, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !13
  %57 = load double, ptr %5, align 8, !tbaa !9
  %58 = load double, ptr %6, align 8, !tbaa !9
  %59 = fsub double %57, %58
  store double %59, ptr %10, align 8, !tbaa !9
  %60 = load ptr, ptr %8, align 8, !tbaa !11
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.Edge, ptr %63, i32 0, i32 2
  %65 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef nonnull align 8 dereferenceable(8) %64)
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = call noundef double @_Z3dfsid(i32 noundef %56, double noundef %66)
  store double %67, ptr %7, align 8, !tbaa !9
  %68 = call noundef i32 @_Z3sgnd(double noundef %67)
  %69 = icmp sgt i32 %68, 0
  br label %70

70:                                               ; preds = %50, %41, %25
  %71 = phi i1 [ false, %41 ], [ false, %25 ], [ %69, %50 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br i1 %71, label %72, label %99

72:                                               ; preds = %70
  %73 = load double, ptr %7, align 8, !tbaa !9
  %74 = load ptr, ptr %8, align 8, !tbaa !11
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.Edge, ptr %77, i32 0, i32 2
  %79 = load double, ptr %78, align 8, !tbaa !15
  %80 = fsub double %79, %73
  store double %80, ptr %78, align 8, !tbaa !15
  %81 = load double, ptr %7, align 8, !tbaa !9
  %82 = load ptr, ptr %8, align 8, !tbaa !11
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = xor i32 %83, 1
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %85
  %87 = getelementptr inbounds %struct.Edge, ptr %86, i32 0, i32 2
  %88 = load double, ptr %87, align 8, !tbaa !15
  %89 = fadd double %88, %81
  store double %89, ptr %87, align 8, !tbaa !15
  %90 = load double, ptr %7, align 8, !tbaa !9
  %91 = load double, ptr %6, align 8, !tbaa !9
  %92 = fadd double %91, %90
  store double %92, ptr %6, align 8, !tbaa !9
  %93 = load double, ptr %5, align 8, !tbaa !9
  %94 = fsub double %92, %93
  %95 = call noundef i32 @_Z3sgnd(double noundef %94)
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %98, label %97

97:                                               ; preds = %72
  store i32 2, ptr %9, align 4
  br label %108

98:                                               ; preds = %72
  br label %99

99:                                               ; preds = %98, %70
  br label %100

100:                                              ; preds = %99
  %101 = load ptr, ptr %8, align 8, !tbaa !11
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %103
  %105 = getelementptr inbounds %struct.Edge, ptr %104, i32 0, i32 0
  %106 = load i32, ptr %105, align 16, !tbaa !16
  %107 = load ptr, ptr %8, align 8, !tbaa !11
  store i32 %106, ptr %107, align 4, !tbaa !5
  br label %20, !llvm.loop !17

108:                                              ; preds = %97, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %109

109:                                              ; preds = %108
  %110 = load double, ptr %6, align 8, !tbaa !9
  %111 = call noundef i32 @_Z3sgnd(double noundef %110)
  %112 = icmp ne i32 %111, 0
  br i1 %112, label %117, label %113

113:                                              ; preds = %109
  %114 = load i32, ptr %4, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [303 x i32], ptr @lev, i64 0, i64 %115
  store i32 -1, ptr %116, align 4, !tbaa !5
  br label %117

117:                                              ; preds = %113, %109
  %118 = load double, ptr %6, align 8, !tbaa !9
  store double %118, ptr %3, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %119

119:                                              ; preds = %117, %14
  %120 = load double, ptr %3, align 8
  ret double %120
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 4}
!14 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !6, i64 0}
!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"

%struct.Edge = type { i32, i32, double }

@T = external dso_local local_unnamed_addr global i32, align 4
@lev = external dso_local local_unnamed_addr global [303 x i32], align 16
@cur = external dso_local local_unnamed_addr global [303 x i32], align 16
@e = external dso_local global [181203 x %struct.Edge], align 16

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sgnd(double noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z3dfsid(i32 noundef %0, double noundef %1) local_unnamed_addr #2 {
  %3 = alloca double, align 8
  %4 = load i32, ptr @T, align 4, !tbaa !5
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %60, label %6

6:                                                ; preds = %2
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [303 x i32], ptr @cur, i64 0, i64 %7
  %.pr = load i32, ptr %8, align 4, !tbaa !5
  %.not28 = icmp eq i32 %.pr, -1
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %9 = getelementptr inbounds [303 x i32], ptr @lev, i64 0, i64 %7
  br label %10

10:                                               ; preds = %.lr.ph, %52
  %.02329 = phi double [ 0.000000e+00, %.lr.ph ], [ %.1, %52 ]
  %11 = phi i32 [ %.pr, %.lr.ph ], [ %56, %52 ]
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %12, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [303 x i32], ptr @lev, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = icmp eq i32 %17, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  br i1 %20, label %21, label %.critedge

21:                                               ; preds = %10
  %22 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %12, i32 2
  %23 = load double, ptr %22, align 8, !tbaa !12
  %24 = call noundef i32 @_Z3sgnd(double noundef %23)
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %.critedge

26:                                               ; preds = %21
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %28, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = fsub double %1, %.02329
  store double %31, ptr %3, align 8, !tbaa !13
  %32 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %28, i32 2
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %32)
  %34 = load double, ptr %33, align 8, !tbaa !13
  %35 = call noundef double @_Z3dfsid(i32 noundef %30, double noundef %34)
  %36 = call noundef i32 @_Z3sgnd(double noundef %35)
  %37 = icmp sgt i32 %36, 0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br i1 %37, label %38, label %52

38:                                               ; preds = %26
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %40, i32 2
  %42 = load double, ptr %41, align 8, !tbaa !12
  %43 = fsub double %42, %35
  store double %43, ptr %41, align 8, !tbaa !12
  %44 = xor i32 %39, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %45, i32 2
  %47 = load double, ptr %46, align 8, !tbaa !12
  %48 = fadd double %35, %47
  store double %48, ptr %46, align 8, !tbaa !12
  %49 = fadd double %.02329, %35
  %50 = fsub double %49, %1
  %51 = call noundef i32 @_Z3sgnd(double noundef %50)
  %.not26 = icmp eq i32 %51, 0
  br i1 %.not26, label %._crit_edge, label %52

.critedge:                                        ; preds = %10, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %52

52:                                               ; preds = %26, %.critedge, %38
  %.1 = phi double [ %49, %38 ], [ %.02329, %26 ], [ %.02329, %.critedge ]
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [181203 x %struct.Edge], ptr @e, i64 0, i64 %54
  %56 = load i32, ptr %55, align 16, !tbaa !14
  store i32 %56, ptr %8, align 4, !tbaa !5
  %.not = icmp eq i32 %56, -1
  br i1 %.not, label %._crit_edge, label %10, !llvm.loop !15

._crit_edge:                                      ; preds = %52, %38, %6
  %.2 = phi double [ 0.000000e+00, %6 ], [ %49, %38 ], [ %.1, %52 ]
  %57 = call noundef i32 @_Z3sgnd(double noundef %.2)
  %.not27 = icmp eq i32 %57, 0
  br i1 %.not27, label %58, label %60

58:                                               ; preds = %._crit_edge
  %59 = getelementptr inbounds [303 x i32], ptr @lev, i64 0, i64 %7
  store i32 -1, ptr %59, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %._crit_edge, %58, %2
  %.0 = phi double [ %1, %2 ], [ %.2, %58 ], [ %.2, %._crit_edge ]
  ret double %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIdERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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, !6, i64 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !11, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass