; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (1854)

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

16:                                               ; preds = %66, %3
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %69

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %22, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds i32, ptr %26, i64 0
  %28 = load i32, ptr %27, align 4, !tbaa !9
  store i32 %28, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %29, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds i32, ptr %33, i64 1
  %35 = load i32, ptr %34, align 4, !tbaa !9
  store i32 %35, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = sub nsw i32 %36, 1950
  store i32 %37, ptr %13, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %62, %21
  %39 = load i32, ptr %13, align 4, !tbaa !9
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = sub nsw i32 %40, 1950
  %42 = icmp slt i32 %39, %41
  br i1 %42, label %44, label %43

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

44:                                               ; preds = %38
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [101 x i32], ptr %7, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %47, align 4, !tbaa !9
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [101 x i32], ptr %7, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = icmp slt i32 %50, %54
  br i1 %55, label %56, label %61

56:                                               ; preds = %44
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [101 x i32], ptr %7, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !9
  store i32 %60, ptr %8, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %56, %44
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %13, align 4, !tbaa !9
  br label %38, !llvm.loop !11

65:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %9, align 4, !tbaa !9
  br label %16, !llvm.loop !13

69:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %84, %69
  %71 = load i32, ptr %15, align 4, !tbaa !9
  %72 = icmp slt i32 %71, 101
  br i1 %72, label %74, label %73

73:                                               ; preds = %70
  store i32 8, ptr %10, align 4
  br label %87

74:                                               ; preds = %70
  %75 = load i32, ptr %15, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [101 x i32], ptr %7, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !9
  %79 = load i32, ptr %8, align 4, !tbaa !9
  %80 = icmp eq i32 %78, %79
  br i1 %80, label %81, label %83

81:                                               ; preds = %74
  %82 = load i32, ptr %15, align 4, !tbaa !9
  store i32 %82, ptr %14, align 4, !tbaa !9
  store i32 8, ptr %10, align 4
  br label %87

83:                                               ; preds = %74
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %15, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %15, align 4, !tbaa !9
  br label %70, !llvm.loop !14

87:                                               ; preds = %81, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %14, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1950
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 404, ptr %7) #3
  ret i32 %90
}

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

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 -2147481698, -2147483648) i32 @maximumPopulation(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readnone %2) local_unnamed_addr #0 {
  %4 = alloca [101 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 404, ptr nonnull %4) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(404) %4, i8 0, i64 404, i1 false)
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph31.preheader, label %.preheader

.lr.ph31.preheader:                               ; preds = %3
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph31

.preheader:                                       ; preds = %._crit_edge, %3
  %.022.lcssa = phi i32 [ 0, %3 ], [ %.1.lcssa, %._crit_edge ]
  br label %20

.lr.ph31:                                         ; preds = %.lr.ph31.preheader, %._crit_edge
  %indvars.iv36 = phi i64 [ 0, %.lr.ph31.preheader ], [ %indvars.iv.next37, %._crit_edge ]
  %.02229 = phi i32 [ 0, %.lr.ph31.preheader ], [ %.1.lcssa, %._crit_edge ]
  %6 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv36
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %7, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp slt i32 %8, %10
  br i1 %11, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph31
  %12 = add nsw i32 %10, -1950
  %13 = add i32 %8, -1950
  %14 = sext i32 %13 to i64
  %15 = sext i32 %12 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph31
  %.1.lcssa = phi i32 [ %.02229, %.lr.ph31 ], [ %spec.select, %.lr.ph ]
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph31, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %14, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.126 = phi i32 [ %.02229, %.lr.ph.preheader ], [ %spec.select, %.lr.ph ]
  %16 = getelementptr inbounds [101 x i32], ptr %4, i64 0, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %16, align 4, !tbaa !9
  %.not = icmp sgt i32 %.126, %17
  %spec.select = select i1 %.not, i32 %.126, i32 %18
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %19 = icmp slt i64 %indvars.iv.next, %15
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !13

20:                                               ; preds = %40, %.preheader
  %indvars.iv39 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next40.3, %40 ]
  %21 = getelementptr inbounds [101 x i32], ptr %4, i64 0, i64 %indvars.iv39
  %22 = load i32, ptr %21, align 16, !tbaa !9
  %23 = icmp eq i32 %22, %.022.lcssa
  br i1 %23, label %24, label %27

24:                                               ; preds = %36, %32, %28, %20
  %indvars.iv39.lcssa = phi i64 [ %indvars.iv39, %20 ], [ %indvars.iv.next40, %28 ], [ %indvars.iv.next40.1, %32 ], [ %indvars.iv.next40.2, %36 ]
  %25 = trunc nuw nsw i64 %indvars.iv39.lcssa to i32
  %26 = add nuw nsw i32 %25, 1950
  br label %.loopexit

27:                                               ; preds = %20
  %exitcond42.not = icmp eq i64 %indvars.iv39, 100
  br i1 %exitcond42.not, label %.loopexit, label %28, !llvm.loop !14

28:                                               ; preds = %27
  %indvars.iv.next40 = or disjoint i64 %indvars.iv39, 1
  %29 = getelementptr inbounds [101 x i32], ptr %4, i64 0, i64 %indvars.iv.next40
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp eq i32 %30, %.022.lcssa
  br i1 %31, label %24, label %32

32:                                               ; preds = %28
  %indvars.iv.next40.1 = or disjoint i64 %indvars.iv39, 2
  %33 = getelementptr inbounds [101 x i32], ptr %4, i64 0, i64 %indvars.iv.next40.1
  %34 = load i32, ptr %33, align 8, !tbaa !9
  %35 = icmp eq i32 %34, %.022.lcssa
  br i1 %35, label %24, label %36

36:                                               ; preds = %32
  %indvars.iv.next40.2 = or disjoint i64 %indvars.iv39, 3
  %37 = getelementptr inbounds [101 x i32], ptr %4, i64 0, i64 %indvars.iv.next40.2
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = icmp eq i32 %38, %.022.lcssa
  br i1 %39, label %24, label %40

40:                                               ; preds = %36
  %indvars.iv.next40.3 = add nuw nsw i64 %indvars.iv39, 4
  br label %20

.loopexit:                                        ; preds = %27, %24
  %.020 = phi i32 [ %26, %24 ], [ 1950, %27 ]
  call void @llvm.lifetime.end.p0(i64 404, ptr nonnull %4) #3
  ret i32 %.020
}

; 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

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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}
!14 = distinct !{!14, !12}


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