; LLVM IR from haytham-hammioui/CS50x-2024 :: Week 5 Data Structures/Problem set 5/inheritance (inheritance)

; 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.person = type { [2 x ptr], [2 x i8] }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [46 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @print_family(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  br label %93

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %19, %10
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = mul nsw i32 %13, 4
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %11
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %19

19:                                               ; preds = %17
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %5, align 4, !tbaa !9
  br label %11, !llvm.loop !11

22:                                               ; preds = %16
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %38

25:                                               ; preds = %22
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.person, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [2 x i8], ptr %28, i64 0, i64 0
  %30 = load i8, ptr %29, align 8, !tbaa !13
  %31 = sext i8 %30 to i32
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.person, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds [2 x i8], ptr %33, i64 0, i64 1
  %35 = load i8, ptr %34, align 1, !tbaa !13
  %36 = sext i8 %35 to i32
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %26, i32 noundef %31, i32 noundef %36)
  br label %80

38:                                               ; preds = %22
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %54

41:                                               ; preds = %38
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.person, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds [2 x i8], ptr %44, i64 0, i64 0
  %46 = load i8, ptr %45, align 8, !tbaa !13
  %47 = sext i8 %46 to i32
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.person, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds [2 x i8], ptr %49, i64 0, i64 1
  %51 = load i8, ptr %50, align 1, !tbaa !13
  %52 = sext i8 %51 to i32
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %42, i32 noundef %47, i32 noundef %52)
  br label %79

54:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %63, %54
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = sub nsw i32 %57, 2
  %59 = icmp slt i32 %56, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %66

61:                                               ; preds = %55
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %63

63:                                               ; preds = %61
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %6, align 4, !tbaa !9
  br label %55, !llvm.loop !14

66:                                               ; preds = %60
  %67 = load i32, ptr %4, align 4, !tbaa !9
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.person, ptr %68, i32 0, i32 1
  %70 = getelementptr inbounds [2 x i8], ptr %69, i64 0, i64 0
  %71 = load i8, ptr %70, align 8, !tbaa !13
  %72 = sext i8 %71 to i32
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.person, ptr %73, i32 0, i32 1
  %75 = getelementptr inbounds [2 x i8], ptr %74, i64 0, i64 1
  %76 = load i8, ptr %75, align 1, !tbaa !13
  %77 = sext i8 %76 to i32
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %67, i32 noundef %72, i32 noundef %77)
  br label %79

79:                                               ; preds = %66, %41
  br label %80

80:                                               ; preds = %79, %25
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.person, ptr %81, i32 0, i32 0
  %83 = getelementptr inbounds [2 x ptr], ptr %82, i64 0, i64 0
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  %85 = load i32, ptr %4, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  call void @print_family(ptr noundef %84, i32 noundef %86)
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.person, ptr %87, i32 0, i32 0
  %89 = getelementptr inbounds [2 x ptr], ptr %88, i64 0, i64 1
  %90 = load ptr, ptr %89, align 8, !tbaa !5
  %91 = load i32, ptr %4, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  call void @print_family(ptr noundef %90, i32 noundef %92)
  br label %93

93:                                               ; preds = %80, %9
  ret void
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 }

!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 = !{!7, !7, i64 0}
!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 [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @print_family(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %tailrecurse._crit_edge, label %.preheader25.preheader

.preheader25.preheader:                           ; preds = %2
  %4 = shl i32 %1, 2
  %5 = add i32 %1, -2
  br label %.preheader25

.preheader25:                                     ; preds = %.preheader25.preheader, %tailrecurse
  %indvars.iv32 = phi i32 [ %5, %.preheader25.preheader ], [ %indvars.iv.next33, %tailrecurse ]
  %indvars.iv = phi i32 [ %4, %.preheader25.preheader ], [ %indvars.iv.next, %tailrecurse ]
  %.tr2431 = phi i32 [ %1, %.preheader25.preheader ], [ %36, %tailrecurse ]
  %.tr30 = phi ptr [ %0, %.preheader25.preheader ], [ %38, %tailrecurse ]
  %smax = tail call i32 @llvm.smax.i32(i32 %indvars.iv, i32 1)
  %6 = icmp sgt i32 %.tr2431, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.preheader25
  switch i32 %.tr2431, label %.preheader [
    i32 0, label %10
    i32 1, label %18
  ]

.preheader:                                       ; preds = %._crit_edge
  %7 = icmp sgt i32 %.tr2431, 2
  br i1 %7, label %.lr.ph28, label %._crit_edge29

.lr.ph:                                           ; preds = %.preheader25, %.lr.ph
  %.02126 = phi i32 [ %9, %.lr.ph ], [ 0, %.preheader25 ]
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %9 = add nuw nsw i32 %.02126, 1
  %exitcond.not = icmp eq i32 %9, %smax
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

10:                                               ; preds = %._crit_edge
  %11 = getelementptr inbounds i8, ptr %.tr30, i64 16
  %12 = load i8, ptr %11, align 8, !tbaa !7
  %13 = sext i8 %12 to i32
  %14 = getelementptr inbounds i8, ptr %.tr30, i64 17
  %15 = load i8, ptr %14, align 1, !tbaa !7
  %16 = sext i8 %15 to i32
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef 0, i32 noundef %13, i32 noundef %16)
  br label %tailrecurse

18:                                               ; preds = %._crit_edge
  %19 = getelementptr inbounds i8, ptr %.tr30, i64 16
  %20 = load i8, ptr %19, align 8, !tbaa !7
  %21 = sext i8 %20 to i32
  %22 = getelementptr inbounds i8, ptr %.tr30, i64 17
  %23 = load i8, ptr %22, align 1, !tbaa !7
  %24 = sext i8 %23 to i32
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef 1, i32 noundef %21, i32 noundef %24)
  br label %tailrecurse

._crit_edge29:                                    ; preds = %.lr.ph28, %.preheader
  %26 = getelementptr inbounds i8, ptr %.tr30, i64 16
  %27 = load i8, ptr %26, align 8, !tbaa !7
  %28 = sext i8 %27 to i32
  %29 = getelementptr inbounds i8, ptr %.tr30, i64 17
  %30 = load i8, ptr %29, align 1, !tbaa !7
  %31 = sext i8 %30 to i32
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %.tr2431, i32 noundef %28, i32 noundef %31)
  br label %tailrecurse

.lr.ph28:                                         ; preds = %.preheader, %.lr.ph28
  %.027 = phi i32 [ %34, %.lr.ph28 ], [ 0, %.preheader ]
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %34 = add nuw nsw i32 %.027, 1
  %exitcond34.not = icmp eq i32 %34, %indvars.iv32
  br i1 %exitcond34.not, label %._crit_edge29, label %.lr.ph28, !llvm.loop !10

tailrecurse:                                      ; preds = %18, %._crit_edge29, %10
  %35 = load ptr, ptr %.tr30, align 8, !tbaa !11
  %36 = add nsw i32 %.tr2431, 1
  tail call void @print_family(ptr noundef %35, i32 noundef %36)
  %37 = getelementptr inbounds i8, ptr %.tr30, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = icmp eq ptr %38, null
  %indvars.iv.next = add i32 %indvars.iv, 4
  %indvars.iv.next33 = add i32 %indvars.iv32, 1
  br i1 %39, label %tailrecurse._crit_edge, label %.preheader25

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  ret void
}

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

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

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 = { 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 #2 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !6}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}


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