; LLVM IR from totte174/minesolve :: src (permutations)

; 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.EquationSet = type { [1024 x %struct.Equation], i32, [192 x i32], [192 x i32], i32, %struct.Mask, %struct.Mask }
%struct.Equation = type { %struct.Mask, i32 }
%struct.Mask = type { [3 x i64] }
%struct.PermutationSet = type { ptr, i32, i32, i8, [192 x i32], [192 x i32], i32 }

@get_permutation_set.equation_set = external hidden global %struct.EquationSet, align 8

; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_permutations_from_split(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @get_permutation_set(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.PermutationSet, ptr %13, i32 0, i32 3
  store i8 0, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = call i32 @get_equation_set(ptr noundef %15, ptr noundef %16, ptr noundef @get_permutation_set.equation_set, ptr noundef %17)
  store i32 %18, ptr %10, align 4, !tbaa !13
  %19 = load i32, ptr %10, align 4, !tbaa !13
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %4
  %22 = load i32, ptr %10, align 4, !tbaa !13
  store i32 %22, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %62

23:                                               ; preds = %4
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.PermutationSet, ptr %24, i32 0, i32 1
  store i32 4194304, ptr %25, align 8, !tbaa !14
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.PermutationSet, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = sext i32 %28 to i64
  %30 = mul i64 24, %29
  %31 = call noalias ptr @malloc(i64 noundef %30) #5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.PermutationSet, ptr %32, i32 0, i32 0
  store ptr %31, ptr %33, align 8, !tbaa !15
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.PermutationSet, ptr %34, i32 0, i32 2
  store i32 0, ptr %35, align 4, !tbaa !16
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PermutationSet, ptr %36, i32 0, i32 3
  store i8 1, ptr %37, align 8, !tbaa !9
  %38 = load i32, ptr getelementptr inbounds (%struct.EquationSet, ptr @get_permutation_set.equation_set, i32 0, i32 4), align 4, !tbaa !17
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.PermutationSet, ptr %39, i32 0, i32 6
  store i32 %38, ptr %40, align 4, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !13
  br label %41

41:                                               ; preds = %55, %23
  %42 = load i32, ptr %12, align 4, !tbaa !13
  %43 = load i32, ptr getelementptr inbounds (%struct.EquationSet, ptr @get_permutation_set.equation_set, i32 0, i32 4), align 4, !tbaa !17
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 2, ptr %11, align 4
  br label %58

46:                                               ; preds = %41
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !13
  %49 = call i32 @get_permutations_from_split(ptr noundef %47, ptr noundef @get_permutation_set.equation_set, i32 noundef %48)
  store i32 %49, ptr %10, align 4, !tbaa !13
  %50 = load i32, ptr %10, align 4, !tbaa !13
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %46
  %53 = load i32, ptr %10, align 4, !tbaa !13
  store i32 %53, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %58

54:                                               ; preds = %46
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %12, align 4, !tbaa !13
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %12, align 4, !tbaa !13
  br label %41, !llvm.loop !21

58:                                               ; preds = %52, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %59 = load i32, ptr %11, align 4
  switch i32 %59, label %62 [
    i32 2, label %60
  ]

60:                                               ; preds = %58
  %61 = load i32, ptr %10, align 4, !tbaa !13
  store i32 %61, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %62

62:                                               ; preds = %60, %58, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %63 = load i32, ptr %5, align 4
  ret i32 %63
}

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

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

!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, !12, i64 16}
!10 = !{!"PermutationSet", !6, i64 0, !11, i64 8, !11, i64 12, !12, i64 16, !7, i64 20, !7, i64 788, !11, i64 1556}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !6, i64 0}
!16 = !{!10, !11, i64 12}
!17 = !{!18, !11, i64 34308}
!18 = !{!"EquationSet", !7, i64 0, !11, i64 32768, !7, i64 32772, !7, i64 33540, !11, i64 34308, !19, i64 34312, !19, i64 34336}
!19 = !{!"Mask", !7, i64 0}
!20 = !{!10, !11, i64 1556}
!21 = distinct !{!21, !22}
!22 = !{!"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.EquationSet = type { [1024 x %struct.Equation], i32, [192 x i32], [192 x i32], i32, %struct.Mask, %struct.Mask }
%struct.Equation = type { %struct.Mask, i32 }
%struct.Mask = type { [3 x i64] }

@get_permutation_set.equation_set = external hidden global %struct.EquationSet, align 8

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_permutations_from_split(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @get_permutation_set(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %2, i64 16
  store i8 0, ptr %5, align 8, !tbaa !5
  %6 = tail call i32 @get_equation_set(ptr noundef %0, ptr noundef %1, ptr noundef nonnull @get_permutation_set.equation_set, ptr noundef %3) #3
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %.loopexit

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 4194304, ptr %8, align 8, !tbaa !12
  %9 = tail call noalias dereferenceable_or_null(100663296) ptr @malloc(i64 noundef 100663296) #4
  store ptr %9, ptr %2, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %2, i64 12
  store i32 0, ptr %10, align 4, !tbaa !14
  store i8 1, ptr %5, align 8, !tbaa !5
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @get_permutation_set.equation_set, i64 34308), align 4, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %2, i64 1556
  store i32 %11, ptr %12, align 4, !tbaa !18
  %.not2930 = icmp sgt i32 %11, 0
  br i1 %.not2930, label %.lr.ph, label %.loopexit

13:                                               ; preds = %.lr.ph
  %14 = add nuw nsw i32 %.031, 1
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @get_permutation_set.equation_set, i64 34308), align 4, !tbaa !15
  %.not29 = icmp slt i32 %14, %15
  br i1 %.not29, label %.lr.ph, label %.loopexit, !llvm.loop !19

.lr.ph:                                           ; preds = %7, %13
  %.031 = phi i32 [ %14, %13 ], [ 0, %7 ]
  %16 = tail call i32 @get_permutations_from_split(ptr noundef nonnull %2, ptr noundef nonnull @get_permutation_set.equation_set, i32 noundef %.031)
  %.not28 = icmp eq i32 %16, 0
  br i1 %.not28, label %13, label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %13, %7, %4
  %.123 = phi i32 [ %6, %4 ], [ 0, %7 ], [ %16, %.lr.ph ], [ 0, %13 ]
  ret i32 %.123
}

declare i32 @get_equation_set(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 }
attributes #4 = { nounwind allocsize(0) }

!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, !11, i64 16}
!6 = !{!"PermutationSet", !7, i64 0, !10, i64 8, !10, i64 12, !11, i64 16, !8, i64 20, !8, i64 788, !10, i64 1556}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 12}
!15 = !{!16, !10, i64 34308}
!16 = !{!"EquationSet", !8, i64 0, !10, i64 32768, !8, i64 32772, !8, i64 33540, !10, i64 34308, !17, i64 34312, !17, i64 34336}
!17 = !{!"Mask", !8, i64 0}
!18 = !{!6, !10, i64 1556}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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