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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @compare(i64 %0, i64 %1, i64 %2, i64 %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.Job, align 4
  %7 = alloca %struct.Job, align 4
  %8 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  store i64 %0, ptr %8, align 4
  %9 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  store i64 %1, ptr %9, align 4
  %10 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  store i64 %2, ptr %10, align 4
  %11 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  store i64 %3, ptr %11, align 4
  %12 = getelementptr inbounds %struct.Job, ptr %6, i32 0, i32 3
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds %struct.Job, ptr %7, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %34

18:                                               ; preds = %4
  %19 = getelementptr inbounds %struct.Job, ptr %6, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = getelementptr inbounds %struct.Job, ptr %7, i32 0, i32 3
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp sgt i32 %20, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %18
  store i32 1, ptr %5, align 4
  br label %34

25:                                               ; preds = %18
  %26 = getelementptr inbounds %struct.Job, ptr %6, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = getelementptr inbounds %struct.Job, ptr %7, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp eq i32 %27, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %25
  store i32 2, ptr %5, align 4
  br label %34

32:                                               ; preds = %25
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33, %31, %24, %17
  %35 = load i32, ptr %5, align 4
  ret i32 %35
}

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 = !{!6, !7, i64 12}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i32 @compare(i64 %0, i64 %1, i64 %2, i64 %3) local_unnamed_addr #0 {
  %.sroa.25.8.extract.shift = lshr i64 %1, 32
  %.sroa.25.8.extract.trunc = trunc nuw i64 %.sroa.25.8.extract.shift to i32
  %.sroa.2.8.extract.shift = lshr i64 %3, 32
  %.sroa.2.8.extract.trunc = trunc nuw i64 %.sroa.2.8.extract.shift to i32
  %5 = icmp slt i32 %.sroa.25.8.extract.trunc, %.sroa.2.8.extract.trunc
  %6 = icmp sgt i32 %.sroa.25.8.extract.trunc, %.sroa.2.8.extract.trunc
  %spec.select = select i1 %6, i32 1, i32 2
  %.0 = select i1 %5, i32 0, i32 %spec.select
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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" }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass