; LLVM IR from kenjin/Awesome-LC-C-Cracker :: leetcode-c-sol/0287_Find-the-Duplicate-Number (op)

; 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: nounwind uwtable
define dso_local i32 @findDuplicate(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %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
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %57, %2
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 32
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %60

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = shl i32 1, %17
  store i32 %18, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %45, %16
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %25, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = and i32 %29, %30
  %32 = icmp ne i32 %31, 0
  %33 = zext i1 %32 to i64
  %34 = select i1 %32, i32 1, i32 0
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = add nsw i32 %35, %34
  store i32 %36, ptr %9, align 4, !tbaa !9
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = and i32 %37, %38
  %40 = icmp ne i32 %39, 0
  %41 = zext i1 %40 to i64
  %42 = select i1 %40, i32 1, i32 0
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %10, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %24
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %11, align 4, !tbaa !9
  br label %19, !llvm.loop !11

48:                                               ; preds = %23
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = icmp sgt i32 %49, %50
  br i1 %51, label %52, label %56

52:                                               ; preds = %48
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = or i32 %54, %53
  store i32 %55, ptr %5, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %52, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %57

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

60:                                               ; preds = %15
  %61 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %61
}

; 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

attributes #0 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i32 @findDuplicate(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 0
  br i1 %3, label %.lr.ph.us.preheader, label %.split28.us

.lr.ph.us.preheader:                              ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 8
  %n.vec = and i64 %wide.trip.count, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.01926.us = phi i32 [ %spec.select.us, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %.02025.us = phi i32 [ %33, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %.02025.us, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %16, %vector.body ]
  %vec.phi35 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %17, %vector.body ]
  %vec.phi36 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %10, %vector.body ]
  %vec.phi37 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %11, %vector.body ]
  %vec.ind = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4>
  %4 = getelementptr inbounds i32, ptr %0, i64 %index
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %wide.load = load <4 x i32>, ptr %4, align 4, !tbaa !5
  %wide.load39 = load <4 x i32>, ptr %5, align 4, !tbaa !5
  %6 = lshr <4 x i32> %wide.load, %broadcast.splat
  %7 = lshr <4 x i32> %wide.load39, %broadcast.splat
  %8 = and <4 x i32> %6, <i32 1, i32 1, i32 1, i32 1>
  %9 = and <4 x i32> %7, <i32 1, i32 1, i32 1, i32 1>
  %10 = add <4 x i32> %8, %vec.phi36
  %11 = add <4 x i32> %9, %vec.phi37
  %12 = lshr <4 x i32> %vec.ind, %broadcast.splat
  %13 = lshr <4 x i32> %step.add, %broadcast.splat
  %14 = and <4 x i32> %12, <i32 1, i32 1, i32 1, i32 1>
  %15 = and <4 x i32> %13, <i32 1, i32 1, i32 1, i32 1>
  %16 = add <4 x i32> %14, %vec.phi
  %17 = add <4 x i32> %15, %vec.phi35
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i32> %vec.ind, <i32 8, i32 8, i32 8, i32 8>
  %18 = icmp eq i64 %index.next, %n.vec
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %17, %16
  %19 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %bin.rdx40 = add <4 x i32> %11, %10
  %20 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx40)
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph.us
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  %.01722.us.ph = phi i32 [ 0, %.lr.ph.us ], [ %19, %middle.block ]
  %.01821.us.ph = phi i32 [ 0, %.lr.ph.us ], [ %20, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.01722.us = phi i32 [ %29, %scalar.ph ], [ %.01722.us.ph, %scalar.ph.preheader ]
  %.01821.us = phi i32 [ %25, %scalar.ph ], [ %.01821.us.ph, %scalar.ph.preheader ]
  %21 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = lshr i32 %22, %.02025.us
  %24 = and i32 %23, 1
  %25 = add nuw nsw i32 %24, %.01821.us
  %26 = trunc nuw nsw i64 %indvars.iv to i32
  %27 = lshr i32 %26, %.02025.us
  %28 = and i32 %27, 1
  %29 = add nuw nsw i32 %28, %.01722.us
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !13

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %.lcssa34 = phi i32 [ %20, %middle.block ], [ %25, %scalar.ph ]
  %.lcssa = phi i32 [ %19, %middle.block ], [ %29, %scalar.ph ]
  %30 = shl nuw i32 1, %.02025.us
  %31 = icmp ugt i32 %.lcssa34, %.lcssa
  %32 = select i1 %31, i32 %30, i32 0
  %spec.select.us = or i32 %32, %.01926.us
  %33 = add nuw nsw i32 %.02025.us, 1
  %exitcond32.not = icmp eq i32 %33, 32
  br i1 %exitcond32.not, label %.split28.us, label %.lr.ph.us, !llvm.loop !14

.split28.us:                                      ; preds = %._crit_edge.us, %2
  %.us-phi = phi i32 [ 0, %2 ], [ %spec.select.us, %._crit_edge.us ]
  ret i32 %.us-phi
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10}


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