; LLVM IR from chirag-singhal/Coding-Interview-101 :: Miscellaneous/Labs/Lab1/Assignment (seqListOps)

; 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.Location = type { %struct.Job, i32 }
%struct.Job = type { i32, i32, i32, i32 }
%struct.SeqList = type { i32, i32 }

@st = external dso_local global [10 x %struct.Location], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @printJob(i64, i64) #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 void @printlist(i64 %0) #0 {
  %2 = alloca %struct.SeqList, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i64 %0, ptr %2, align 4
  %5 = getelementptr inbounds %struct.SeqList, ptr %2, i32 0, i32 0
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %36

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %10 = getelementptr inbounds %struct.SeqList, ptr %2, i32 0, i32 1
  %11 = load i32, ptr %10, align 4, !tbaa !10
  store i32 %11, ptr %3, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %12 = getelementptr inbounds %struct.SeqList, ptr %2, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !10
  store i32 %13, ptr %4, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %32, %9
  %15 = load i32, ptr %4, align 4, !tbaa !11
  %16 = getelementptr inbounds %struct.SeqList, ptr %2, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !10
  %18 = getelementptr inbounds %struct.SeqList, ptr %2, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %17, %19
  %21 = icmp slt i32 %15, %20
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %14
  %24 = load i32, ptr %4, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10 x %struct.Location], ptr @st, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.Location, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds { i64, i64 }, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 4
  %30 = getelementptr inbounds { i64, i64 }, ptr %27, i32 0, i32 1
  %31 = load i64, ptr %30, align 4
  call void @printJob(i64 %29, i64 %31)
  br label %32

32:                                               ; preds = %23
  %33 = load i32, ptr %4, align 4, !tbaa !11
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %4, align 4, !tbaa !11
  br label %14, !llvm.loop !12

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

36:                                               ; preds = %35, %8
  ret void
}

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


; 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.Location = type { %struct.Job, i32 }
%struct.Job = type { i32, i32, i32, i32 }

@st = external dso_local local_unnamed_addr global [10 x %struct.Location], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @printJob(i64, i64) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @printlist(i64 %0) local_unnamed_addr #0 {
  %.sroa.0.0.extract.trunc = trunc i64 %0 to i32
  %2 = icmp sgt i32 %.sroa.0.0.extract.trunc, 0
  br i1 %2, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %1
  %3 = ashr i64 %0, 32
  %.sroa.3.0.extract.shift8 = mul i64 %0, 4294967297
  %4 = ashr i64 %.sroa.3.0.extract.shift8, 32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %3, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %5 = getelementptr inbounds [10 x %struct.Location], ptr @st, i64 0, i64 %indvars.iv
  %6 = load i64, ptr %5, align 4
  %7 = getelementptr inbounds i8, ptr %5, i64 8
  %8 = load i64, ptr %7, align 4
  tail call void @printJob(i64 %6, i64 %8)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %9 = icmp slt i64 %indvars.iv.next, %4
  br i1 %9, label %.lr.ph, label %.loopexit, !llvm.loop !5

.loopexit:                                        ; preds = %.lr.ph, %1
  ret void
}

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

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


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