; LLVM IR from lolosssss/leetcode :: c (56_merge_intervals)

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

%struct.Interval = type { i32, i32 }

@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @merge(ptr noundef, i32 noundef, ptr 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: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [4 x %struct.Interval], align 16
  %3 = alloca [2 x %struct.Interval], align 16
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  %8 = getelementptr inbounds [4 x %struct.Interval], ptr %2, i64 0, i64 0
  %9 = getelementptr inbounds %struct.Interval, ptr %8, i32 0, i32 0
  store i32 1, ptr %9, align 16, !tbaa !9
  %10 = getelementptr inbounds [4 x %struct.Interval], ptr %2, i64 0, i64 0
  %11 = getelementptr inbounds %struct.Interval, ptr %10, i32 0, i32 1
  store i32 3, ptr %11, align 4, !tbaa !11
  %12 = getelementptr inbounds [4 x %struct.Interval], ptr %2, i64 0, i64 1
  %13 = getelementptr inbounds %struct.Interval, ptr %12, i32 0, i32 0
  store i32 2, ptr %13, align 8, !tbaa !9
  %14 = getelementptr inbounds [4 x %struct.Interval], ptr %2, i64 0, i64 1
  %15 = getelementptr inbounds %struct.Interval, ptr %14, i32 0, i32 1
  store i32 6, ptr %15, align 4, !tbaa !11
  %16 = getelementptr inbounds [4 x %struct.Interval], ptr %2, i64 0, i64 2
  %17 = getelementptr inbounds %struct.Interval, ptr %16, i32 0, i32 0
  store i32 8, ptr %17, align 16, !tbaa !9
  %18 = getelementptr inbounds [4 x %struct.Interval], ptr %2, i64 0, i64 2
  %19 = getelementptr inbounds %struct.Interval, ptr %18, i32 0, i32 1
  store i32 10, ptr %19, align 4, !tbaa !11
  %20 = getelementptr inbounds [4 x %struct.Interval], ptr %2, i64 0, i64 3
  %21 = getelementptr inbounds %struct.Interval, ptr %20, i32 0, i32 0
  store i32 15, ptr %21, align 8, !tbaa !9
  %22 = getelementptr inbounds [4 x %struct.Interval], ptr %2, i64 0, i64 3
  %23 = getelementptr inbounds %struct.Interval, ptr %22, i32 0, i32 1
  store i32 18, ptr %23, align 4, !tbaa !11
  %24 = getelementptr inbounds [2 x %struct.Interval], ptr %3, i64 0, i64 0
  %25 = getelementptr inbounds %struct.Interval, ptr %24, i32 0, i32 0
  store i32 1, ptr %25, align 16, !tbaa !9
  %26 = getelementptr inbounds [2 x %struct.Interval], ptr %3, i64 0, i64 0
  %27 = getelementptr inbounds %struct.Interval, ptr %26, i32 0, i32 1
  store i32 4, ptr %27, align 4, !tbaa !11
  %28 = getelementptr inbounds [2 x %struct.Interval], ptr %3, i64 0, i64 1
  %29 = getelementptr inbounds %struct.Interval, ptr %28, i32 0, i32 0
  store i32 2, ptr %29, align 8, !tbaa !9
  %30 = getelementptr inbounds [2 x %struct.Interval], ptr %3, i64 0, i64 1
  %31 = getelementptr inbounds %struct.Interval, ptr %30, i32 0, i32 1
  store i32 5, ptr %31, align 4, !tbaa !11
  %32 = getelementptr inbounds [4 x %struct.Interval], ptr %2, i64 0, i64 0
  %33 = call ptr @merge(ptr noundef %32, i32 noundef 4, ptr noundef %5)
  store ptr %33, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %53, %0
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %56

39:                                               ; preds = %34
  %40 = load ptr, ptr %4, align 8, !tbaa !12
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.Interval, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct.Interval, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !12
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %struct.Interval, ptr %46, i64 %48
  %50 = getelementptr inbounds %struct.Interval, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %45, i32 noundef %51)
  br label %53

53:                                               ; preds = %39
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %6, align 4, !tbaa !5
  br label %34, !llvm.loop !14

56:                                               ; preds = %38
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %58 = load ptr, ptr %4, align 8, !tbaa !12
  call void @free(ptr noundef %58) #4
  %59 = getelementptr inbounds [2 x %struct.Interval], ptr %3, i64 0, i64 0
  %60 = call ptr @merge(ptr noundef %59, i32 noundef 2, ptr noundef %5)
  store ptr %60, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %80, %56
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %83

66:                                               ; preds = %61
  %67 = load ptr, ptr %4, align 8, !tbaa !12
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %struct.Interval, ptr %67, i64 %69
  %71 = getelementptr inbounds %struct.Interval, ptr %70, i32 0, i32 0
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = load ptr, ptr %4, align 8, !tbaa !12
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds %struct.Interval, ptr %73, i64 %75
  %77 = getelementptr inbounds %struct.Interval, ptr %76, i32 0, i32 1
  %78 = load i32, ptr %77, align 4, !tbaa !11
  %79 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %72, i32 noundef %78)
  br label %80

80:                                               ; preds = %66
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %7, align 4, !tbaa !5
  br label %61, !llvm.loop !16

83:                                               ; preds = %65
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %85 = load ptr, ptr %4, align 8, !tbaa !12
  call void @free(ptr noundef %85) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %2) #4
  ret i32 0
}

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

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


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

%struct.Interval = type { i32, i32 }

@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [4 x %struct.Interval], align 16
  %2 = alloca [2 x %struct.Interval], align 16
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  store <4 x i32> <i32 1, i32 3, i32 2, i32 6>, ptr %1, align 16, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  store <4 x i32> <i32 8, i32 10, i32 15, i32 18>, ptr %4, align 16, !tbaa !5
  store <4 x i32> <i32 1, i32 4, i32 2, i32 5>, ptr %2, align 16, !tbaa !5
  %5 = call ptr @merge(ptr noundef nonnull %1, i32 noundef 4, ptr noundef nonnull %3)
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @free(ptr noundef %5) #4
  %9 = call ptr @merge(ptr noundef nonnull %2, i32 noundef 2, ptr noundef nonnull %3)
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph17, label %._crit_edge18

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %12 = getelementptr inbounds %struct.Interval, ptr %5, i64 %indvars.iv
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %12, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %13, i32 noundef %15)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge18:                                    ; preds = %.lr.ph17, %._crit_edge
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @free(ptr noundef %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #4
  ret i32 0

.lr.ph17:                                         ; preds = %._crit_edge, %.lr.ph17
  %indvars.iv20 = phi i64 [ %indvars.iv.next21, %.lr.ph17 ], [ 0, %._crit_edge ]
  %21 = getelementptr inbounds %struct.Interval, ptr %9, i64 %indvars.iv20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %21, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %22, i32 noundef %24)
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next21, %27
  br i1 %28, label %.lr.ph17, label %._crit_edge18, !llvm.loop !14
}

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

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 = { 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 nounwind willreturn allockind("free") memory(argmem: readwrite, 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 }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass