; LLVM IR from MakeContributions/DSA :: algorithms/C/arrays (unique-elements-in-an-array)

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

@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = mul i64 4, %12
  %14 = call noalias ptr @malloc(i64 noundef %13) #5
  store ptr %14, ptr %3, align 8, !tbaa !9
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %0
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = mul nsw i32 %18, -1
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %17, %0
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %33, %20
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %36

27:                                               ; preds = %22
  %28 = load ptr, ptr %3, align 8, !tbaa !9
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %31)
  br label %33

33:                                               ; preds = %27
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %4, align 4, !tbaa !5
  br label %22, !llvm.loop !11

36:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %83, %36
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %86

43:                                               ; preds = %38
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %69, %43
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = icmp sle i32 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %72

49:                                               ; preds = %44
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = icmp ne i32 %50, %51
  br i1 %52, label %53, label %68

53:                                               ; preds = %49
  %54 = load ptr, ptr %3, align 8, !tbaa !9
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = load ptr, ptr %3, align 8, !tbaa !9
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %59, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = icmp eq i32 %58, %63
  br i1 %64, label %65, label %68

65:                                               ; preds = %53
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %5, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %65, %53, %49
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %8, align 4, !tbaa !5
  br label %44, !llvm.loop !13

72:                                               ; preds = %48
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %82

75:                                               ; preds = %72
  %76 = load ptr, ptr %3, align 8, !tbaa !9
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i32, ptr %76, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %80)
  br label %82

82:                                               ; preds = %75, %72
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %6, align 4, !tbaa !5
  br label %38, !llvm.loop !14

86:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %87 = load i32, ptr %1, align 4
  ret i32 %87
}

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

declare i32 @printf(ptr noundef, ...) #2

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; 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 = { "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 = { nounwind allocsize(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 }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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"

@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = shl nsw i64 %5, 2
  %7 = call noalias ptr @malloc(i64 noundef %6) #5
  %8 = icmp slt i32 %4, 0
  br i1 %8, label %9, label %11

9:                                                ; preds = %0
  %10 = sub nsw i32 0, %4
  store i32 %10, ptr %1, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %9, %0
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %11
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.preheader, label %._crit_edge30

.lr.ph:                                           ; preds = %11, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %11 ]
  %18 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef %18)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = icmp slt i64 %indvars.iv.next, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %._crit_edge, %52
  %23 = phi i32 [ %53, %52 ], [ %16, %._crit_edge ]
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %52 ], [ 0, %._crit_edge ]
  %.not24 = icmp slt i32 %23, 0
  br i1 %.not24, label %._crit_edge28.thread, label %.lr.ph27

.lr.ph27:                                         ; preds = %.preheader
  %24 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv35
  %25 = add nuw i32 %23, 1
  %wide.trip.count = zext i32 %25 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %26 = icmp eq i32 %23, 0
  br i1 %26, label %._crit_edge28.unr-lcssa, label %.lr.ph27.new

.lr.ph27.new:                                     ; preds = %.lr.ph27
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %34

._crit_edge30:                                    ; preds = %52, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0

._crit_edge28.unr-lcssa:                          ; preds = %48, %.lr.ph27
  %.1.lcssa.ph = phi i32 [ poison, %.lr.ph27 ], [ %.1.1, %48 ]
  %indvars.iv32.unr = phi i64 [ 0, %.lr.ph27 ], [ %indvars.iv.next33.1, %48 ]
  %.01925.unr = phi i32 [ 0, %.lr.ph27 ], [ %.1.1, %48 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge28, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge28.unr-lcssa
  %.not22.epil = icmp eq i64 %indvars.iv35, %indvars.iv32.unr
  br i1 %.not22.epil, label %._crit_edge28, label %27

27:                                               ; preds = %.epil.preheader
  %28 = load i32, ptr %24, align 4, !tbaa !5
  %29 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv32.unr
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = icmp eq i32 %28, %30
  %32 = zext i1 %31 to i32
  %spec.select.epil = add nsw i32 %.01925.unr, %32
  br label %._crit_edge28

._crit_edge28:                                    ; preds = %.epil.preheader, %27, %._crit_edge28.unr-lcssa
  %.1.lcssa = phi i32 [ %.1.lcssa.ph, %._crit_edge28.unr-lcssa ], [ %.01925.unr, %.epil.preheader ], [ %spec.select.epil, %27 ]
  %33 = icmp eq i32 %.1.lcssa, 0
  br i1 %33, label %._crit_edge28.thread, label %52

34:                                               ; preds = %48, %.lr.ph27.new
  %indvars.iv32 = phi i64 [ 0, %.lr.ph27.new ], [ %indvars.iv.next33.1, %48 ]
  %.01925 = phi i32 [ 0, %.lr.ph27.new ], [ %.1.1, %48 ]
  %niter = phi i64 [ 0, %.lr.ph27.new ], [ %niter.next.1, %48 ]
  %.not22 = icmp eq i64 %indvars.iv35, %indvars.iv32
  br i1 %.not22, label %41, label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %24, align 4, !tbaa !5
  %37 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv32
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp eq i32 %36, %38
  %40 = zext i1 %39 to i32
  %spec.select = add nsw i32 %.01925, %40
  br label %41

41:                                               ; preds = %35, %34
  %.1 = phi i32 [ %.01925, %34 ], [ %spec.select, %35 ]
  %indvars.iv.next33 = or disjoint i64 %indvars.iv32, 1
  %.not22.1 = icmp eq i64 %indvars.iv35, %indvars.iv.next33
  br i1 %.not22.1, label %48, label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %24, align 4, !tbaa !5
  %44 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.next33
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp eq i32 %43, %45
  %47 = zext i1 %46 to i32
  %spec.select.1 = add nsw i32 %.1, %47
  br label %48

48:                                               ; preds = %42, %41
  %.1.1 = phi i32 [ %.1, %41 ], [ %spec.select.1, %42 ]
  %indvars.iv.next33.1 = add nuw nsw i64 %indvars.iv32, 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_edge28.unr-lcssa, label %34, !llvm.loop !11

._crit_edge28.thread:                             ; preds = %.preheader, %._crit_edge28
  %49 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv35
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %50)
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %._crit_edge28, %._crit_edge28.thread
  %53 = phi i32 [ %23, %._crit_edge28 ], [ %.pre, %._crit_edge28.thread ]
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %54 = sext i32 %53 to i64
  %55 = icmp slt i64 %indvars.iv.next36, %54
  br i1 %55, label %.preheader, label %._crit_edge30, !llvm.loop !12
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

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

attributes #0 = { nofree 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #5 = { nounwind allocsize(0) }

!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}
!12 = distinct !{!12, !10}


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