; LLVM IR from scemama/slaterlib :: src (test)

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

@.str.8 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @random_int() #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
declare dso_local i64 @random_det(i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

declare i32 @to_orbital_list(i32 noundef, ptr noundef, ptr noundef) #3

declare void @of_orbital_list(i32 noundef, i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) #4

declare i32 @exc_degree(i32 noundef, ptr noundef, ptr noundef) #3

declare void @debug_det(i32 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @test_to_of_list(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = zext i32 %12 to i64
  %14 = call ptr @llvm.stacksave.p0()
  store ptr %14, ptr %5, align 8
  %15 = alloca i64, i64 %13, align 16
  store i64 %13, ptr %6, align 8
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = alloca i64, i64 %17, align 16
  store i64 %17, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = mul i32 %19, 64
  %21 = zext i32 %20 to i64
  %22 = alloca i32, i64 %21, align 16
  store i64 %21, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %63, %1
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = icmp ult i32 %24, 10000
  br i1 %25, label %26, label %66

26:                                               ; preds = %23
  %27 = call i32 @random_int()
  store i32 %27, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp ult i32 %28, 4
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  br label %34

31:                                               ; preds = %26
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sub i32 %32, 2
  br label %34

34:                                               ; preds = %31, %30
  %35 = phi i32 [ 4, %30 ], [ %33, %31 ]
  store i32 %35, ptr %4, align 4, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %46, %34
  %37 = load i32, ptr %10, align 4, !tbaa !5
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = icmp ult i32 %37, %38
  br i1 %39, label %40, label %49

40:                                               ; preds = %36
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = call i64 @random_det(i32 noundef %41)
  %43 = load i32, ptr %10, align 4, !tbaa !5
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds i64, ptr %15, i64 %44
  store i64 %42, ptr %45, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %40
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = add i32 %47, 1
  store i32 %48, ptr %10, align 4, !tbaa !5
  br label %36, !llvm.loop !11

49:                                               ; preds = %36
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = call i32 @to_orbital_list(i32 noundef %50, ptr noundef %15, ptr noundef %22)
  store i32 %51, ptr %8, align 4, !tbaa !5
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  call void @of_orbital_list(i32 noundef %52, i32 noundef %53, ptr noundef %18, ptr noundef %22)
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = call i32 @exc_degree(i32 noundef %54, ptr noundef %15, ptr noundef %18)
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %62

57:                                               ; preds = %49
  %58 = load i32, ptr %2, align 4, !tbaa !5
  call void @debug_det(i32 noundef %58, ptr noundef %15)
  %59 = load i32, ptr %2, align 4, !tbaa !5
  call void @debug_det(i32 noundef %59, ptr noundef %18)
  store i32 10000, ptr %3, align 4, !tbaa !5
  store i32 -1, ptr %11, align 4, !tbaa !5
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = call i32 @exc_degree(i32 noundef %60, ptr noundef %15, ptr noundef %18)
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.8, i32 noundef %61) #6
  unreachable

62:                                               ; preds = %49
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = add i32 %64, 1
  store i32 %65, ptr %3, align 4, !tbaa !5
  br label %23, !llvm.loop !13

66:                                               ; preds = %23
  %67 = load i32, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %68 = load ptr, ptr %5, align 8
  call void @llvm.stackrestore.p0(ptr %68)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret i32 %67
}

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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { "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 = { noreturn "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 #5 = { nounwind }
attributes #6 = { noreturn }

!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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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.8 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @random_int() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @random_det(i32 noundef) local_unnamed_addr #0

declare i32 @to_orbital_list(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @of_orbital_list(i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) local_unnamed_addr #2

declare i32 @exc_degree(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @debug_det(i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @test_to_of_list(i32 noundef %0) local_unnamed_addr #0 {
  %2 = zext i32 %0 to i64
  %3 = alloca i64, i64 %2, align 16
  %4 = alloca i64, i64 %2, align 16
  %5 = shl i32 %0, 6
  %6 = zext i32 %5 to i64
  %7 = alloca i32, i64 %6, align 16
  %.not28 = icmp eq i32 %0, 0
  br i1 %.not28, label %.split, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %1, %12
  %.02023.us = phi i32 [ %13, %12 ], [ 0, %1 ]
  %8 = call i32 @random_int()
  %9 = icmp ult i32 %8, 4
  %10 = add i32 %8, -2
  %11 = select i1 %9, i32 4, i32 %10
  br label %14

12:                                               ; preds = %._crit_edge.us
  %13 = add nuw nsw i32 %.02023.us, 1
  %exitcond32.not = icmp eq i32 %13, 10000
  br i1 %exitcond32.not, label %.split25.us, label %.lr.ph.us, !llvm.loop !5

14:                                               ; preds = %.lr.ph.us, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next, %14 ]
  %15 = call i64 @random_det(i32 noundef %11)
  %16 = getelementptr inbounds i64, ptr %3, i64 %indvars.iv
  store i64 %15, ptr %16, align 8, !tbaa !7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %14, !llvm.loop !11

._crit_edge.us:                                   ; preds = %14
  %17 = call i32 @to_orbital_list(i32 noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %7) #3
  call void @of_orbital_list(i32 noundef %0, i32 noundef %17, ptr noundef nonnull %4, ptr noundef nonnull %7) #3
  %18 = call i32 @exc_degree(i32 noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %4) #3
  %.not.us = icmp eq i32 %18, 0
  br i1 %.not.us, label %12, label %.split27.us

19:                                               ; preds = %.split
  %20 = add nuw nsw i32 %.02023, 1
  %exitcond33.not = icmp eq i32 %20, 10000
  br i1 %exitcond33.not, label %.split25.us, label %.split, !llvm.loop !5

.split:                                           ; preds = %1, %19
  %.02023 = phi i32 [ %20, %19 ], [ 0, %1 ]
  %21 = call i32 @random_int()
  %22 = call i32 @to_orbital_list(i32 noundef 0, ptr noundef nonnull %3, ptr noundef nonnull %7) #3
  call void @of_orbital_list(i32 noundef 0, i32 noundef %22, ptr noundef nonnull %4, ptr noundef nonnull %7) #3
  %23 = call i32 @exc_degree(i32 noundef 0, ptr noundef nonnull %3, ptr noundef nonnull %4) #3
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %19, label %.split27.us

.split27.us:                                      ; preds = %._crit_edge.us, %.split
  call void @debug_det(i32 noundef %0, ptr noundef nonnull %3) #3
  call void @debug_det(i32 noundef %0, ptr noundef nonnull %4) #3
  %24 = call i32 @exc_degree(i32 noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %4) #3
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.8, i32 noundef %24) #4
  unreachable

.split25.us:                                      ; preds = %12, %19
  ret i32 0
}

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


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