; LLVM IR from Tunghohin/Competitive_Coding :: Poj/poj3660.ll (Z5floydi)

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

@G = external dso_local global [110 x [110 x i8]], align 16
@closure = external dso_local global [110 x [110 x i8]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5floydi(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
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 @closure, ptr align 16 @G, i64 12100, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %65, %1
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %68

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

13:                                               ; preds = %61, %12
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %57, %18
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %60

24:                                               ; preds = %19
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %26
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [110 x i8], ptr %27, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !9, !range !11, !noundef !12
  %32 = trunc i8 %31 to i1
  br i1 %32, label %33, label %42

33:                                               ; preds = %24
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %35
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [110 x i8], ptr %36, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9, !range !11, !noundef !12
  %41 = trunc i8 %40 to i1
  br label %42

42:                                               ; preds = %33, %24
  %43 = phi i1 [ false, %24 ], [ %41, %33 ]
  %44 = zext i1 %43 to i32
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %46
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [110 x i8], ptr %47, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !9, !range !11, !noundef !12
  %52 = trunc i8 %51 to i1
  %53 = zext i1 %52 to i32
  %54 = or i32 %53, %44
  %55 = icmp ne i32 %54, 0
  %56 = zext i1 %55 to i8
  store i8 %56, ptr %50, align 1, !tbaa !9
  br label %57

57:                                               ; preds = %42
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !5
  br label %19, !llvm.loop !13

60:                                               ; preds = %23
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !15

64:                                               ; preds = %17
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %3, align 4, !tbaa !5
  br label %7, !llvm.loop !16

68:                                               ; preds = %11
  ret void
}

; 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.start.p0(i64 immarg, ptr nocapture) #2

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

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


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

@G = external dso_local local_unnamed_addr global [110 x [110 x i8]], align 16
@closure = external dso_local local_unnamed_addr global [110 x [110 x i8]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z5floydi(i32 noundef %0) local_unnamed_addr #0 {
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(12100) @closure, ptr noundef nonnull align 16 dereferenceable(12100) @G, i64 12100, i1 false)
  %.not26 = icmp slt i32 %0, 1
  br i1 %.not26, label %._crit_edge28, label %.preheader20.preheader

.preheader20.preheader:                           ; preds = %1
  %2 = add nuw i32 %0, 1
  %wide.trip.count38 = zext i32 %2 to i64
  %3 = zext nneg i32 %0 to i64
  %xtraiter = and i64 %3, 1
  %4 = icmp eq i32 %2, 2
  %unroll_iter = and i64 %3, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader20

.preheader20:                                     ; preds = %.preheader20.preheader, %._crit_edge25.split
  %indvars.iv35 = phi i64 [ 1, %.preheader20.preheader ], [ %indvars.iv.next36, %._crit_edge25.split ]
  br label %.preheader

._crit_edge28:                                    ; preds = %._crit_edge25.split, %1
  ret void

.preheader:                                       ; preds = %.preheader20, %._crit_edge
  %indvars.iv30 = phi i64 [ 1, %.preheader20 ], [ %indvars.iv.next31, %._crit_edge ]
  %5 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %indvars.iv30, i64 %indvars.iv35
  br i1 %4, label %._crit_edge.unr-lcssa, label %.preheader.new

._crit_edge25.split:                              ; preds = %._crit_edge
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %._crit_edge28, label %.preheader20, !llvm.loop !5

._crit_edge.unr-lcssa:                            ; preds = %30, %.preheader
  %indvars.iv.unr = phi i64 [ 1, %.preheader ], [ %indvars.iv.next.1, %30 ]
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.unr-lcssa
  %6 = load i8, ptr %5, align 1, !tbaa !7, !range !11, !noundef !12
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %._crit_edge.epilog-lcssa

8:                                                ; preds = %.epil.preheader
  %9 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %indvars.iv35, i64 %indvars.iv.unr
  %10 = load i8, ptr %9, align 1, !tbaa !7, !range !11, !noundef !12
  br label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %8, %.epil.preheader
  %11 = phi i8 [ 0, %.epil.preheader ], [ %10, %8 ]
  %12 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %indvars.iv30, i64 %indvars.iv.unr
  %13 = load i8, ptr %12, align 1, !tbaa !7, !range !11, !noundef !12
  %14 = or i8 %13, %11
  store i8 %14, ptr %12, align 1, !tbaa !7
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count38
  br i1 %exitcond34.not, label %._crit_edge25.split, label %.preheader, !llvm.loop !13

.preheader.new:                                   ; preds = %.preheader, %30
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %30 ], [ 1, %.preheader ]
  %niter = phi i64 [ %niter.next.1, %30 ], [ 0, %.preheader ]
  %15 = load i8, ptr %5, align 1, !tbaa !7, !range !11, !noundef !12
  %16 = trunc nuw i8 %15 to i1
  br i1 %16, label %17, label %20

17:                                               ; preds = %.preheader.new
  %18 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %indvars.iv35, i64 %indvars.iv
  %19 = load i8, ptr %18, align 1, !tbaa !7, !range !11, !noundef !12
  br label %20

20:                                               ; preds = %17, %.preheader.new
  %21 = phi i8 [ 0, %.preheader.new ], [ %19, %17 ]
  %22 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %indvars.iv30, i64 %indvars.iv
  %23 = load i8, ptr %22, align 1, !tbaa !7, !range !11, !noundef !12
  %24 = or i8 %23, %21
  store i8 %24, ptr %22, align 1, !tbaa !7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i8, ptr %5, align 1, !tbaa !7, !range !11, !noundef !12
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %27, label %30

27:                                               ; preds = %20
  %28 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %indvars.iv35, i64 %indvars.iv.next
  %29 = load i8, ptr %28, align 1, !tbaa !7, !range !11, !noundef !12
  br label %30

30:                                               ; preds = %27, %20
  %31 = phi i8 [ 0, %20 ], [ %29, %27 ]
  %32 = getelementptr inbounds [110 x [110 x i8]], ptr @closure, i64 0, i64 %indvars.iv30, i64 %indvars.iv.next
  %33 = load i8, ptr %32, align 1, !tbaa !7, !range !11, !noundef !12
  %34 = or i8 %33, %31
  store i8 %34, ptr %32, align 1, !tbaa !7
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %.preheader.new, !llvm.loop !14
}

; 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) #1

attributes #0 = { mustprogress nofree norecurse 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 nounwind willreturn memory(argmem: readwrite) }

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


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