; LLVM IR from kenjin/Awesome-LC-C-Cracker :: leetcode-c-sol/1133_largest-unique-number (1133_largest-unique-number)

; 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 @largestUniqueNumber(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [1001 x i32], align 16
  %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
  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 4004, ptr %5) #3
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 4004, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 -1, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1001, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %11

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

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %63

16:                                               ; preds = %11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr %17, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1001 x i32], ptr %5, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !9
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %27, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = icmp sgt i32 %26, %31
  br i1 %32, label %33, label %35

33:                                               ; preds = %16
  %34 = load i32, ptr %6, align 4, !tbaa !9
  br label %41

35:                                               ; preds = %16
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %36, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %35, %33
  %42 = phi i32 [ %34, %33 ], [ %40, %35 ]
  store i32 %42, ptr %6, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = icmp slt i32 %43, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %41
  %51 = load i32, ptr %7, align 4, !tbaa !9
  br label %58

52:                                               ; preds = %41
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %52, %50
  %59 = phi i32 [ %51, %50 ], [ %57, %52 ]
  store i32 %59, ptr %7, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %58
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %8, align 4, !tbaa !9
  br label %11, !llvm.loop !11

63:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 -1, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %64 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %64, ptr %10, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %77, %63
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = icmp sge i32 %66, %67
  br i1 %68, label %69, label %80

69:                                               ; preds = %65
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [1001 x i32], ptr %5, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = icmp eq i32 %73, 1
  br i1 %74, label %75, label %77

75:                                               ; preds = %69
  %76 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %76, ptr %9, align 4, !tbaa !9
  br label %80

77:                                               ; preds = %69
  %78 = load i32, ptr %10, align 4, !tbaa !9
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr %10, align 4, !tbaa !9
  br label %65, !llvm.loop !13

80:                                               ; preds = %75, %65
  %81 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4004, ptr %5) #3
  ret i32 %81
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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 @largestUniqueNumber(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [1001 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4004, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4004) %3, i8 0, i64 4004, i1 false)
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %5 = icmp eq i32 %1, 1
  br i1 %5, label %.lr.ph35.preheader.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph

.lr.ph35.preheader.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %.026..lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %.026..1, %.lr.ph ]
  %.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %28, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.02530.unr = phi i32 [ 1001, %.lr.ph.preheader ], [ %28, %.lr.ph ]
  %.02629.unr = phi i32 [ -1, %.lr.ph.preheader ], [ %.026..1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph35.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.lr.ph35.preheader.unr-lcssa
  %6 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.unr
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [1001 x i32], ptr %3, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr %9, align 4, !tbaa !5
  %.026..epil = tail call i32 @llvm.smax.i32(i32 %.02629.unr, i32 %7)
  %12 = tail call i32 @llvm.smin.i32(i32 %.02530.unr, i32 %7)
  br label %.lr.ph35.preheader

.lr.ph35.preheader:                               ; preds = %.lr.ph35.preheader.unr-lcssa, %.lr.ph.epil
  %.026..lcssa = phi i32 [ %.026..lcssa.ph, %.lr.ph35.preheader.unr-lcssa ], [ %.026..epil, %.lr.ph.epil ]
  %.lcssa = phi i32 [ %.lcssa.ph, %.lr.ph35.preheader.unr-lcssa ], [ %12, %.lr.ph.epil ]
  %13 = sext i32 %.026..lcssa to i64
  %14 = sext i32 %.lcssa to i64
  br label %.lr.ph35

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.02530 = phi i32 [ 1001, %.lr.ph.preheader.new ], [ %28, %.lr.ph ]
  %.02629 = phi i32 [ -1, %.lr.ph.preheader.new ], [ %.026..1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %15 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1001 x i32], ptr %3, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !5
  %.026. = tail call i32 @llvm.smax.i32(i32 %.02629, i32 %16)
  %21 = tail call i32 @llvm.smin.i32(i32 %.02530, i32 %16)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %22 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1001 x i32], ptr %3, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 4, !tbaa !5
  %.026..1 = tail call i32 @llvm.smax.i32(i32 %.026., i32 %23)
  %28 = tail call i32 @llvm.smin.i32(i32 %21, i32 %23)
  %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 %.lr.ph35.preheader.unr-lcssa, label %.lr.ph, !llvm.loop !9

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %32
  %indvars.iv40 = phi i64 [ %13, %.lr.ph35.preheader ], [ %indvars.iv.next41, %32 ]
  %29 = getelementptr inbounds [1001 x i32], ptr %3, i64 0, i64 %indvars.iv40
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %._crit_edge.loopexit.split.loop.exit, label %32

32:                                               ; preds = %.lr.ph35
  %indvars.iv.next41 = add nsw i64 %indvars.iv40, -1
  %.not.not = icmp sgt i64 %indvars.iv40, %14
  br i1 %.not.not, label %.lr.ph35, label %._crit_edge, !llvm.loop !11

._crit_edge.loopexit.split.loop.exit:             ; preds = %.lr.ph35
  %33 = trunc nsw i64 %indvars.iv40 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %32, %._crit_edge.loopexit.split.loop.exit, %2
  %.023 = phi i32 [ -1, %2 ], [ %33, %._crit_edge.loopexit.split.loop.exit ], [ -1, %32 ]
  call void @llvm.lifetime.end.p0(i64 4004, ptr nonnull %3) #4
  ret i32 %.023
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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