; LLVM IR from tangjz/acm-icpc :: codeforces/gym/101471J.ll (Z5diniciie)

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

@N = external dso_local global i32, align 4
@S = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@lnk = external dso_local global [201 x i32], align 16
@cur = external dso_local global [201 x i32], 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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
declare dso_local noundef zeroext i1 @_Z3bfsv() #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z3sgne(x86_fp80 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef x86_fp80 @_Z3dfsie(i32 noundef, x86_fp80 noundef) #2

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

11:                                               ; preds = %46, %3
  %12 = call noundef zeroext i1 @_Z3bfsv()
  br i1 %12, label %13, label %19

13:                                               ; preds = %11
  %14 = load x86_fp80, ptr %6, align 16, !tbaa !9
  %15 = load x86_fp80, ptr %7, align 16, !tbaa !9
  %16 = fsub x86_fp80 %14, %15
  %17 = call noundef i32 @_Z3sgne(x86_fp80 noundef %16)
  %18 = icmp sgt i32 %17, 0
  br label %19

19:                                               ; preds = %13, %11
  %20 = phi i1 [ false, %11 ], [ %18, %13 ]
  br i1 %20, label %21, label %47

21:                                               ; preds = %19
  %22 = load i32, ptr @N, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = mul i64 %23, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @cur, ptr align 16 @lnk, i64 %24, i1 false)
  br label %25

25:                                               ; preds = %42, %21
  %26 = load x86_fp80, ptr %6, align 16, !tbaa !9
  %27 = load x86_fp80, ptr %7, align 16, !tbaa !9
  %28 = fsub x86_fp80 %26, %27
  %29 = call noundef i32 @_Z3sgne(x86_fp80 noundef %28)
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %31, label %39

31:                                               ; preds = %25
  %32 = load i32, ptr @S, align 4, !tbaa !5
  %33 = load x86_fp80, ptr %6, align 16, !tbaa !9
  %34 = load x86_fp80, ptr %7, align 16, !tbaa !9
  %35 = fsub x86_fp80 %33, %34
  %36 = call noundef x86_fp80 @_Z3dfsie(i32 noundef %32, x86_fp80 noundef %35)
  store x86_fp80 %36, ptr %8, align 16, !tbaa !9
  %37 = call noundef i32 @_Z3sgne(x86_fp80 noundef %36)
  %38 = icmp sgt i32 %37, 0
  br label %39

39:                                               ; preds = %31, %25
  %40 = phi i1 [ false, %25 ], [ %38, %31 ]
  br i1 %40, label %41, label %46

41:                                               ; preds = %39
  br label %42

42:                                               ; preds = %41
  %43 = load x86_fp80, ptr %8, align 16, !tbaa !9
  %44 = load x86_fp80, ptr %7, align 16, !tbaa !9
  %45 = fadd x86_fp80 %44, %43
  store x86_fp80 %45, ptr %7, align 16, !tbaa !9
  br label %25, !llvm.loop !11

46:                                               ; preds = %39
  br label %11, !llvm.loop !13

47:                                               ; preds = %19
  %48 = load x86_fp80, ptr %7, align 16, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  ret x86_fp80 %48
}

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

@N = external dso_local local_unnamed_addr global i32, align 4
@S = external dso_local local_unnamed_addr global i32, align 4
@T = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [201 x i32], align 16
@cur = external dso_local local_unnamed_addr global [201 x i32], align 16

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z3bfsv() local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z3sgne(x86_fp80 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef x86_fp80 @_Z3dfsie(i32 noundef, x86_fp80 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef x86_fp80 @_Z5diniciie(i32 noundef %0, i32 noundef %1, x86_fp80 noundef %2) local_unnamed_addr #1 {
  store i32 %0, ptr @S, align 4, !tbaa !5
  store i32 %1, ptr @T, align 4, !tbaa !5
  %4 = tail call noundef zeroext i1 @_Z3bfsv()
  br i1 %4, label %.lr.ph16, label %.critedge

.lr.ph16:                                         ; preds = %3, %.critedge2
  %.015 = phi x86_fp80 [ %.1.lcssa, %.critedge2 ], [ 0xK00000000000000000000, %3 ]
  %5 = fsub x86_fp80 %2, %.015
  %6 = tail call noundef i32 @_Z3sgne(x86_fp80 noundef %5)
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %8, label %.critedge

8:                                                ; preds = %.lr.ph16
  %9 = load i32, ptr @N, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = shl nsw i64 %10, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @cur, ptr nonnull align 16 @lnk, i64 %11, i1 false)
  %12 = tail call noundef i32 @_Z3sgne(x86_fp80 noundef %5)
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph, label %.critedge2

.lr.ph:                                           ; preds = %8, %19
  %14 = phi x86_fp80 [ %21, %19 ], [ %5, %8 ]
  %.112 = phi x86_fp80 [ %20, %19 ], [ %.015, %8 ]
  %15 = load i32, ptr @S, align 4, !tbaa !5
  %16 = tail call noundef x86_fp80 @_Z3dfsie(i32 noundef %15, x86_fp80 noundef %14)
  %17 = tail call noundef i32 @_Z3sgne(x86_fp80 noundef %16)
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %19, label %.critedge2

19:                                               ; preds = %.lr.ph
  %20 = fadd x86_fp80 %.112, %16
  %21 = fsub x86_fp80 %2, %20
  %22 = tail call noundef i32 @_Z3sgne(x86_fp80 noundef %21)
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph, label %.critedge2, !llvm.loop !9

.critedge2:                                       ; preds = %.lr.ph, %19, %8
  %.1.lcssa = phi x86_fp80 [ %.015, %8 ], [ %20, %19 ], [ %.112, %.lr.ph ]
  %24 = tail call noundef zeroext i1 @_Z3bfsv()
  br i1 %24, label %.lr.ph16, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %.lr.ph16, %.critedge2, %3
  %.0.lcssa = phi x86_fp80 [ 0xK00000000000000000000, %3 ], [ %.1.lcssa, %.critedge2 ], [ %.015, %.lr.ph16 ]
  ret x86_fp80 %.0.lcssa
}

attributes #0 = { mustprogress nocallback nofree 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 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 = !{!"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}


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