; LLVM IR from AlgoGenesis/C :: Greedy Algorithms/Gale-Shapley Algorithm (Program)

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

@n = external dso_local global i32, align 4
@freeMen = external dso_local global [100 x i8], align 16
@nextProposal = external dso_local global [100 x i32], align 16
@preferenceMen = external dso_local global [100 x [100 x i32]], align 16
@women = external dso_local global [100 x i32], align 16
@men = external dso_local global [100 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @prefers(i32 noundef, i32 noundef, i32 noundef) #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 @stableMarriage() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %18, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %21

11:                                               ; preds = %6
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100 x i8], ptr @freeMen, i64 0, i64 %13
  store i8 1, ptr %14, align 1, !tbaa !9
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100 x i32], ptr @nextProposal, i64 0, i64 %16
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %11
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !11

21:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %22 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %22, ptr %2, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %102, %21
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %103

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %39, %26
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %42

31:                                               ; preds = %27
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100 x i8], ptr @freeMen, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !9, !range !13, !noundef !14
  %36 = trunc i8 %35 to i1
  br i1 %36, label %37, label %38

37:                                               ; preds = %31
  br label %42

38:                                               ; preds = %31
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %3, align 4, !tbaa !5
  br label %27, !llvm.loop !15

42:                                               ; preds = %37, %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100 x [100 x i32]], ptr @preferenceMen, i64 0, i64 %44
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100 x i32], ptr @nextProposal, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100 x i32], ptr %45, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  store i32 %52, ptr %4, align 4, !tbaa !5
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100 x i32], ptr @nextProposal, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %55, align 4, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100 x i32], ptr @women, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = icmp eq i32 %61, -1
  br i1 %62, label %63, label %77

63:                                               ; preds = %42
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100 x i32], ptr @women, i64 0, i64 %66
  store i32 %64, ptr %67, align 4, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100 x i32], ptr @men, i64 0, i64 %70
  store i32 %68, ptr %71, align 4, !tbaa !5
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100 x i8], ptr @freeMen, i64 0, i64 %73
  store i8 0, ptr %74, align 1, !tbaa !9
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = add nsw i32 %75, -1
  store i32 %76, ptr %2, align 4, !tbaa !5
  br label %102

77:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [100 x i32], ptr @women, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  store i32 %81, ptr %5, align 4, !tbaa !5
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = load i32, ptr %3, align 4, !tbaa !5
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = call zeroext i1 @prefers(i32 noundef %82, i32 noundef %83, i32 noundef %84)
  br i1 %85, label %86, label %101

86:                                               ; preds = %77
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = load i32, ptr %4, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [100 x i32], ptr @women, i64 0, i64 %89
  store i32 %87, ptr %90, align 4, !tbaa !5
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [100 x i32], ptr @men, i64 0, i64 %93
  store i32 %91, ptr %94, align 4, !tbaa !5
  %95 = load i32, ptr %3, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [100 x i8], ptr @freeMen, i64 0, i64 %96
  store i8 0, ptr %97, align 1, !tbaa !9
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [100 x i8], ptr @freeMen, i64 0, i64 %99
  store i8 1, ptr %100, align 1, !tbaa !9
  br label %101

101:                                              ; preds = %86, %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %102

102:                                              ; preds = %101, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %23, !llvm.loop !16

103:                                              ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  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, !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 = !{!"_Bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !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"

@n = external dso_local local_unnamed_addr global i32, align 4
@freeMen = external dso_local local_unnamed_addr global [100 x i8], align 16
@nextProposal = external dso_local local_unnamed_addr global [100 x i32], align 16
@preferenceMen = external dso_local local_unnamed_addr global [100 x [100 x i32]], align 16
@women = external dso_local local_unnamed_addr global [100 x i32], align 16
@men = external dso_local local_unnamed_addr global [100 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @prefers(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @stableMarriage() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.preheader.preheader, label %._crit_edge40

.preheader.preheader:                             ; preds = %0
  %3 = zext nneg i32 %1 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @freeMen, i8 1, i64 %3, i1 false), !tbaa !9
  %4 = shl nuw nsw i64 %3, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @nextProposal, i8 0, i64 %4, i1 false), !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %34
  %5 = phi i32 [ %35, %34 ], [ %1, %.preheader.preheader ]
  %.02839 = phi i32 [ %.1, %34 ], [ %1, %.preheader.preheader ]
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph35.preheader, label %._crit_edge

.lr.ph35.preheader:                               ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %5 to i64
  br label %.lr.ph35

.lr.ph35:                                         ; preds = %.lr.ph35.preheader, %10
  %indvars.iv = phi i64 [ 0, %.lr.ph35.preheader ], [ %indvars.iv.next, %10 ]
  %7 = getelementptr inbounds [100 x i8], ptr @freeMen, i64 0, i64 %indvars.iv
  %8 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %._crit_edge.loopexit.split.loop.exit, label %10

10:                                               ; preds = %.lr.ph35
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph35, !llvm.loop !13

._crit_edge.loopexit.split.loop.exit:             ; preds = %.lr.ph35
  %11 = trunc nuw nsw i64 %indvars.iv to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %10, %._crit_edge.loopexit.split.loop.exit, %.preheader
  %.029.lcssa = phi i32 [ 0, %.preheader ], [ %11, %._crit_edge.loopexit.split.loop.exit ], [ %5, %10 ]
  %12 = zext nneg i32 %.029.lcssa to i64
  %13 = getelementptr inbounds [100 x i32], ptr @nextProposal, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100 x [100 x i32]], ptr @preferenceMen, i64 0, i64 %12, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add nsw i32 %14, 1
  store i32 %18, ptr %13, align 4, !tbaa !5
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds [100 x i32], ptr @women, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %27

23:                                               ; preds = %._crit_edge
  store i32 %.029.lcssa, ptr %20, align 4, !tbaa !5
  %24 = getelementptr inbounds [100 x i32], ptr @men, i64 0, i64 %12
  store i32 %17, ptr %24, align 4, !tbaa !5
  %25 = getelementptr inbounds [100 x i8], ptr @freeMen, i64 0, i64 %12
  store i8 0, ptr %25, align 1, !tbaa !9
  %26 = add nsw i32 %.02839, -1
  br label %34

27:                                               ; preds = %._crit_edge
  %28 = tail call zeroext i1 @prefers(i32 noundef %17, i32 noundef %.029.lcssa, i32 noundef %21)
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br i1 %28, label %29, label %34

29:                                               ; preds = %27
  store i32 %.029.lcssa, ptr %20, align 4, !tbaa !5
  %30 = getelementptr inbounds [100 x i32], ptr @men, i64 0, i64 %12
  store i32 %17, ptr %30, align 4, !tbaa !5
  %31 = getelementptr inbounds [100 x i8], ptr @freeMen, i64 0, i64 %12
  store i8 0, ptr %31, align 1, !tbaa !9
  %32 = sext i32 %21 to i64
  %33 = getelementptr inbounds [100 x i8], ptr @freeMen, i64 0, i64 %32
  store i8 1, ptr %33, align 1, !tbaa !9
  br label %34

34:                                               ; preds = %27, %29, %23
  %35 = phi i32 [ %5, %23 ], [ %.pre, %29 ], [ %.pre, %27 ]
  %.1 = phi i32 [ %26, %23 ], [ %.02839, %29 ], [ %.02839, %27 ]
  %36 = icmp sgt i32 %.1, 0
  br i1 %36, label %.preheader, label %._crit_edge40, !llvm.loop !15

._crit_edge40:                                    ; preds = %34, %0
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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 nounwind willreturn memory(argmem: write) }

!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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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