; LLVM IR from berquist/rchem :: libpyquante2 (cints)

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @ijkl2intindex(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %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
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %4
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = call i32 @ijkl2intindex(i32 noundef %18, i32 noundef %19, i32 noundef %20, i32 noundef %21)
  store i32 %22, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %63

23:                                               ; preds = %4
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %33

27:                                               ; preds = %23
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = call i32 @ijkl2intindex(i32 noundef %28, i32 noundef %29, i32 noundef %30, i32 noundef %31)
  store i32 %32, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %63

33:                                               ; preds = %23
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  %37 = mul nsw i32 %34, %36
  %38 = sdiv i32 %37, 2
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  store i32 %40, ptr %11, align 4, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = mul nsw i32 %41, %43
  %45 = sdiv i32 %44, 2
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  store i32 %47, ptr %12, align 4, !tbaa !5
  %48 = load i32, ptr %11, align 4, !tbaa !5
  %49 = load i32, ptr %12, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %55

51:                                               ; preds = %33
  %52 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %52, ptr %10, align 4, !tbaa !5
  %53 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %53, ptr %11, align 4, !tbaa !5
  %54 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %54, ptr %12, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %51, %33
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = load i32, ptr %11, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  %59 = mul nsw i32 %56, %58
  %60 = sdiv i32 %59, 2
  %61 = load i32, ptr %12, align 4, !tbaa !5
  %62 = add nsw i32 %60, %61
  store i32 %62, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %63

63:                                               ; preds = %55, %27, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %64 = load i32, ptr %5, align 4
  ret i32 %64
}

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


; 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(none) uwtable
define dso_local i32 @ijkl2intindex(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %tailrecurse.outer, %4
  %.tr.ph = phi i32 [ %0, %4 ], [ %.tr41.ph, %tailrecurse.outer ]
  %.tr41.ph = phi i32 [ %1, %4 ], [ %.tr.ph, %tailrecurse.outer ]
  %5 = icmp slt i32 %.tr.ph, %.tr41.ph
  br i1 %5, label %tailrecurse.outer, label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %tailrecurse
  %.tr42 = phi i32 [ %.tr43, %tailrecurse ], [ %2, %tailrecurse.outer ]
  %.tr43 = phi i32 [ %.tr42, %tailrecurse ], [ %3, %tailrecurse.outer ]
  %6 = icmp slt i32 %.tr42, %.tr43
  br i1 %6, label %tailrecurse, label %7

7:                                                ; preds = %tailrecurse
  %8 = add nsw i32 %.tr.ph, 1
  %9 = mul nsw i32 %8, %.tr.ph
  %10 = sdiv i32 %9, 2
  %11 = add nsw i32 %10, %.tr41.ph
  %12 = add nsw i32 %.tr42, 1
  %13 = mul nsw i32 %12, %.tr42
  %14 = sdiv i32 %13, 2
  %15 = add nsw i32 %14, %.tr43
  %spec.select = tail call i32 @llvm.smax.i32(i32 %11, i32 %15)
  %spec.select40 = tail call i32 @llvm.smin.i32(i32 %11, i32 %15)
  %16 = add nsw i32 %spec.select, 1
  %17 = mul nsw i32 %16, %spec.select
  %18 = sdiv i32 %17, 2
  %19 = add nsw i32 %18, %spec.select40
  ret i32 %19
}

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

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

attributes #0 = { nofree norecurse nosync nounwind 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" }
attributes #1 = { 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)"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass