; LLVM IR from tangjz/acm-icpc :: hackerrank/xor-subsequence.ll (Z3FWTPxii)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11FWT_iteratePxii(ptr noundef, i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3FWTPxii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %26

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

13:                                               ; preds = %22, %12
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %25

18:                                               ; preds = %13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  call void @_Z11FWT_iteratePxii(ptr noundef %19, i32 noundef %20, i32 noundef %21)
  br label %22

22:                                               ; preds = %18
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = shl i32 %23, 1
  store i32 %24, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !11

25:                                               ; preds = %17
  br label %59

26:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = ashr i32 %27, 1
  store i32 %28, ptr %8, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %37, %26
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %40

33:                                               ; preds = %29
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z11FWT_iteratePxii(ptr noundef %34, i32 noundef %35, i32 noundef %36)
  br label %37

37:                                               ; preds = %33
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = ashr i32 %38, 1
  store i32 %39, ptr %8, align 4, !tbaa !9
  br label %29, !llvm.loop !13

40:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %55, %40
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %58

46:                                               ; preds = %41
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i64, ptr %49, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !14
  %54 = sdiv i64 %53, %48
  store i64 %54, ptr %52, align 8, !tbaa !14
  br label %55

55:                                               ; preds = %46
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %9, align 4, !tbaa !9
  br label %41, !llvm.loop !16

58:                                               ; preds = %45
  br label %59

59:                                               ; preds = %58, %25
  ret void
}

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"any pointer", !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 = !{!15, !15, i64 0}
!15 = !{!"long long", !7, i64 0}
!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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11FWT_iteratePxii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3FWTPxii(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.preheader, label %8

.preheader:                                       ; preds = %3
  %5 = icmp sgt i32 %1, 1
  br i1 %5, label %.lr.ph27, label %.loopexit

.lr.ph27:                                         ; preds = %.preheader, %.lr.ph27
  %.01926 = phi i32 [ %6, %.lr.ph27 ], [ 1, %.preheader ]
  tail call void @_Z11FWT_iteratePxii(ptr noundef %0, i32 noundef %1, i32 noundef %.01926)
  %6 = shl i32 %.01926, 1
  %7 = icmp slt i32 %6, %1
  br i1 %7, label %.lr.ph27, label %.loopexit, !llvm.loop !5

8:                                                ; preds = %3
  %9 = ashr i32 %1, 1
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %.preheader21

.preheader21:                                     ; preds = %.lr.ph, %8
  %11 = icmp sgt i32 %1, 0
  br i1 %11, label %.lr.ph25, label %.loopexit

.lr.ph25:                                         ; preds = %.preheader21
  %12 = zext nneg i32 %1 to i64
  %xtraiter = and i64 %12, 1
  %13 = icmp eq i32 %1, 1
  br i1 %13, label %.loopexit.loopexit32.unr-lcssa, label %.lr.ph25.new

.lr.ph25.new:                                     ; preds = %.lr.ph25
  %unroll_iter = and i64 %12, 2147483646
  br label %15

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.01823 = phi i32 [ %14, %.lr.ph ], [ %9, %8 ]
  tail call void @_Z11FWT_iteratePxii(ptr noundef %0, i32 noundef %1, i32 noundef %.01823)
  %14 = lshr i32 %.01823, 1
  %.not = icmp ult i32 %.01823, 2
  br i1 %.not, label %.preheader21, label %.lr.ph, !llvm.loop !7

15:                                               ; preds = %15, %.lr.ph25.new
  %indvars.iv = phi i64 [ 0, %.lr.ph25.new ], [ %indvars.iv.next.1, %15 ]
  %niter = phi i64 [ 0, %.lr.ph25.new ], [ %niter.next.1, %15 ]
  %16 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv
  %17 = load i64, ptr %16, align 8, !tbaa !8
  %18 = sdiv i64 %17, %12
  store i64 %18, ptr %16, align 8, !tbaa !8
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %19 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv.next
  %20 = load i64, ptr %19, align 8, !tbaa !8
  %21 = sdiv i64 %20, %12
  store i64 %21, ptr %19, align 8, !tbaa !8
  %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 %.loopexit.loopexit32.unr-lcssa, label %15, !llvm.loop !12

.loopexit.loopexit32.unr-lcssa:                   ; preds = %15, %.lr.ph25
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph25 ], [ %indvars.iv.next.1, %15 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit32.epilog-lcssa

.loopexit.loopexit32.epilog-lcssa:                ; preds = %.loopexit.loopexit32.unr-lcssa
  %22 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv.unr
  %23 = load i64, ptr %22, align 8, !tbaa !8
  %24 = sdiv i64 %23, %12
  store i64 %24, ptr %22, align 8, !tbaa !8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit32.epilog-lcssa, %.loopexit.loopexit32.unr-lcssa, %.lr.ph27, %.preheader21, %.preheader
  ret void
}

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

!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 = distinct !{!7, !6}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = distinct !{!12, !6}


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