; LLVM IR from gokcehan/pns :: generators/gridgen-patched (gridgen)

; 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.imbalance = type { i64, i64 }

@source_list = external dso_local global ptr, align 8
@sink_list = external dso_local global ptr, align 8
@n_source = external dso_local global i64, align 8
@n_sink = external dso_local global i64, align 8
@n_node = external dso_local global i64, 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 uwtable
declare dso_local void @err(i64 noundef) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @select_source_sinks() #1 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [2 x float], align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %6 = getelementptr inbounds [2 x float], ptr %5, i64 0, i64 0
  store float 0x3FECCCCCC0000000, ptr %6, align 4, !tbaa !5
  %7 = load i64, ptr @n_node, align 8, !tbaa !9
  %8 = sitofp i64 %7 to double
  %9 = fsub double %8, 0x3FEFAE147AE147AE
  %10 = fptrunc double %9 to float
  %11 = getelementptr inbounds [2 x float], ptr %5, i64 0, i64 1
  store float %10, ptr %11, align 4, !tbaa !5
  %12 = load i64, ptr @n_node, align 8, !tbaa !9
  %13 = mul i64 %12, 8
  %14 = call noalias ptr @malloc(i64 noundef %13) #6
  store ptr %14, ptr %3, align 8, !tbaa !11
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %0
  call void @err(i64 noundef 4)
  call void @exit(i32 noundef 1) #7
  unreachable

17:                                               ; preds = %0
  store i64 0, ptr %1, align 8, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !11
  store ptr %18, ptr %2, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %25, %17
  %20 = load i64, ptr %1, align 8, !tbaa !9
  %21 = load i64, ptr @n_node, align 8, !tbaa !9
  %22 = icmp slt i64 %20, %21
  br i1 %22, label %23, label %30

23:                                               ; preds = %19
  %24 = load ptr, ptr %2, align 8, !tbaa !11
  store i64 0, ptr %24, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %23
  %26 = load i64, ptr %1, align 8, !tbaa !9
  %27 = add nsw i64 %26, 1
  store i64 %27, ptr %1, align 8, !tbaa !9
  %28 = load ptr, ptr %2, align 8, !tbaa !11
  %29 = getelementptr inbounds i64, ptr %28, i32 1
  store ptr %29, ptr %2, align 8, !tbaa !11
  br label %19, !llvm.loop !13

30:                                               ; preds = %19
  store i64 0, ptr %1, align 8, !tbaa !9
  %31 = load ptr, ptr @source_list, align 8, !tbaa !11
  store ptr %31, ptr %4, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %60, %30
  %33 = load i64, ptr %1, align 8, !tbaa !9
  %34 = load i64, ptr @n_source, align 8, !tbaa !9
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %36, label %65

36:                                               ; preds = %32
  %37 = getelementptr inbounds [2 x float], ptr %5, i64 0, i64 0
  %38 = call i64 @uniform(ptr noundef %37)
  %39 = load ptr, ptr %4, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.imbalance, ptr %39, i32 0, i32 0
  store i64 %38, ptr %40, align 8, !tbaa !15
  %41 = load ptr, ptr %3, align 8, !tbaa !11
  %42 = load ptr, ptr %4, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.imbalance, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !15
  %45 = getelementptr inbounds i64, ptr %41, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = icmp eq i64 %46, 1
  br i1 %47, label %48, label %53

48:                                               ; preds = %36
  %49 = load ptr, ptr %4, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct.imbalance, ptr %49, i32 -1
  store ptr %50, ptr %4, align 8, !tbaa !11
  %51 = load i64, ptr %1, align 8, !tbaa !9
  %52 = add nsw i64 %51, -1
  store i64 %52, ptr %1, align 8, !tbaa !9
  br label %59

53:                                               ; preds = %36
  %54 = load ptr, ptr %3, align 8, !tbaa !11
  %55 = load ptr, ptr %4, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.imbalance, ptr %55, i32 0, i32 0
  %57 = load i64, ptr %56, align 8, !tbaa !15
  %58 = getelementptr inbounds i64, ptr %54, i64 %57
  store i64 1, ptr %58, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %53, %48
  br label %60

60:                                               ; preds = %59
  %61 = load i64, ptr %1, align 8, !tbaa !9
  %62 = add nsw i64 %61, 1
  store i64 %62, ptr %1, align 8, !tbaa !9
  %63 = load ptr, ptr %4, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.imbalance, ptr %63, i32 1
  store ptr %64, ptr %4, align 8, !tbaa !11
  br label %32, !llvm.loop !17

65:                                               ; preds = %32
  store i64 0, ptr %1, align 8, !tbaa !9
  %66 = load ptr, ptr @sink_list, align 8, !tbaa !11
  store ptr %66, ptr %4, align 8, !tbaa !11
  br label %67

67:                                               ; preds = %95, %65
  %68 = load i64, ptr %1, align 8, !tbaa !9
  %69 = load i64, ptr @n_sink, align 8, !tbaa !9
  %70 = icmp slt i64 %68, %69
  br i1 %70, label %71, label %100

71:                                               ; preds = %67
  %72 = getelementptr inbounds [2 x float], ptr %5, i64 0, i64 0
  %73 = call i64 @uniform(ptr noundef %72)
  %74 = load ptr, ptr %4, align 8, !tbaa !11
  %75 = getelementptr inbounds %struct.imbalance, ptr %74, i32 0, i32 0
  store i64 %73, ptr %75, align 8, !tbaa !15
  %76 = load ptr, ptr %3, align 8, !tbaa !11
  %77 = load ptr, ptr %4, align 8, !tbaa !11
  %78 = getelementptr inbounds %struct.imbalance, ptr %77, i32 0, i32 0
  %79 = load i64, ptr %78, align 8, !tbaa !15
  %80 = getelementptr inbounds i64, ptr %76, i64 %79
  %81 = load i64, ptr %80, align 8, !tbaa !9
  %82 = icmp eq i64 %81, 1
  br i1 %82, label %83, label %88

83:                                               ; preds = %71
  %84 = load ptr, ptr %4, align 8, !tbaa !11
  %85 = getelementptr inbounds %struct.imbalance, ptr %84, i32 -1
  store ptr %85, ptr %4, align 8, !tbaa !11
  %86 = load i64, ptr %1, align 8, !tbaa !9
  %87 = add nsw i64 %86, -1
  store i64 %87, ptr %1, align 8, !tbaa !9
  br label %94

88:                                               ; preds = %71
  %89 = load ptr, ptr %3, align 8, !tbaa !11
  %90 = load ptr, ptr %4, align 8, !tbaa !11
  %91 = getelementptr inbounds %struct.imbalance, ptr %90, i32 0, i32 0
  %92 = load i64, ptr %91, align 8, !tbaa !15
  %93 = getelementptr inbounds i64, ptr %89, i64 %92
  store i64 1, ptr %93, align 8, !tbaa !9
  br label %94

94:                                               ; preds = %88, %83
  br label %95

95:                                               ; preds = %94
  %96 = load i64, ptr %1, align 8, !tbaa !9
  %97 = add nsw i64 %96, 1
  store i64 %97, ptr %1, align 8, !tbaa !9
  %98 = load ptr, ptr %4, align 8, !tbaa !11
  %99 = getelementptr inbounds %struct.imbalance, ptr %98, i32 1
  store ptr %99, ptr %4, align 8, !tbaa !11
  br label %67, !llvm.loop !18

100:                                              ; preds = %67
  %101 = load ptr, ptr %3, align 8, !tbaa !11
  call void @free(ptr noundef %101) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @uniform(ptr noundef) #1

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 = { noreturn nounwind "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 "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 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { 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 = !{!6, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 0}
!16 = !{!"imbalance", !10, i64 0, !10, i64 8}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


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

@source_list = external dso_local local_unnamed_addr global ptr, align 8
@sink_list = external dso_local local_unnamed_addr global ptr, align 8
@n_source = external dso_local local_unnamed_addr global i64, align 8
@n_sink = external dso_local local_unnamed_addr global i64, align 8
@n_node = external dso_local local_unnamed_addr global i64, align 8

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @err(i64 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local void @select_source_sinks() local_unnamed_addr #1 {
  %1 = alloca [2 x float], align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #6
  store float 0x3FECCCCCC0000000, ptr %1, align 4, !tbaa !5
  %2 = load i64, ptr @n_node, align 8, !tbaa !9
  %3 = sitofp i64 %2 to double
  %4 = fadd double %3, 0xBFEFAE147AE147AE
  %5 = fptrunc double %4 to float
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  store float %5, ptr %6, align 4, !tbaa !5
  %7 = shl i64 %2, 3
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #7
  %9 = icmp eq ptr %8, null
  br i1 %9, label %11, label %.preheader

.preheader:                                       ; preds = %0
  %10 = icmp sgt i64 %2, 0
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %8, i8 0, i64 %7, i1 false), !tbaa !9
  br label %._crit_edge

11:                                               ; preds = %0
  tail call void @err(i64 noundef 4)
  tail call void @exit(i32 noundef 1) #8
  unreachable

._crit_edge:                                      ; preds = %.lr.ph.preheader, %.preheader
  %12 = load i64, ptr @n_source, align 8, !tbaa !9
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %.lr.ph36.preheader, label %._crit_edge37

.lr.ph36.preheader:                               ; preds = %._crit_edge
  %14 = load ptr, ptr @source_list, align 8, !tbaa !11
  br label %.lr.ph36

.lr.ph36:                                         ; preds = %.lr.ph36.preheader, %23
  %.034 = phi ptr [ %25, %23 ], [ %14, %.lr.ph36.preheader ]
  %.12633 = phi i64 [ %24, %23 ], [ 0, %.lr.ph36.preheader ]
  %15 = call i64 @uniform(ptr noundef nonnull %1)
  store i64 %15, ptr %.034, align 8, !tbaa !13
  %16 = getelementptr inbounds i64, ptr %8, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 1
  br i1 %18, label %19, label %22

19:                                               ; preds = %.lr.ph36
  %20 = getelementptr inbounds i8, ptr %.034, i64 -16
  %21 = add nsw i64 %.12633, -1
  br label %23

22:                                               ; preds = %.lr.ph36
  store i64 1, ptr %16, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %19, %22
  %.227 = phi i64 [ %21, %19 ], [ %.12633, %22 ]
  %.1 = phi ptr [ %20, %19 ], [ %.034, %22 ]
  %24 = add nsw i64 %.227, 1
  %25 = getelementptr inbounds i8, ptr %.1, i64 16
  %26 = load i64, ptr @n_source, align 8, !tbaa !9
  %27 = icmp slt i64 %24, %26
  br i1 %27, label %.lr.ph36, label %._crit_edge37, !llvm.loop !15

._crit_edge37:                                    ; preds = %23, %._crit_edge
  %28 = load i64, ptr @n_sink, align 8, !tbaa !9
  %29 = icmp sgt i64 %28, 0
  br i1 %29, label %.lr.ph41.preheader, label %._crit_edge42

.lr.ph41.preheader:                               ; preds = %._crit_edge37
  %30 = load ptr, ptr @sink_list, align 8, !tbaa !11
  br label %.lr.ph41

.lr.ph41:                                         ; preds = %.lr.ph41.preheader, %39
  %.239 = phi ptr [ %41, %39 ], [ %30, %.lr.ph41.preheader ]
  %.32838 = phi i64 [ %40, %39 ], [ 0, %.lr.ph41.preheader ]
  %31 = call i64 @uniform(ptr noundef nonnull %1)
  store i64 %31, ptr %.239, align 8, !tbaa !13
  %32 = getelementptr inbounds i64, ptr %8, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = icmp eq i64 %33, 1
  br i1 %34, label %35, label %38

35:                                               ; preds = %.lr.ph41
  %36 = getelementptr inbounds i8, ptr %.239, i64 -16
  %37 = add nsw i64 %.32838, -1
  br label %39

38:                                               ; preds = %.lr.ph41
  store i64 1, ptr %32, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %35, %38
  %.4 = phi i64 [ %37, %35 ], [ %.32838, %38 ]
  %.3 = phi ptr [ %36, %35 ], [ %.239, %38 ]
  %40 = add nsw i64 %.4, 1
  %41 = getelementptr inbounds i8, ptr %.3, i64 16
  %42 = load i64, ptr @n_sink, align 8, !tbaa !9
  %43 = icmp slt i64 %40, %42
  br i1 %43, label %.lr.ph41, label %._crit_edge42, !llvm.loop !17

._crit_edge42:                                    ; preds = %39, %._crit_edge37
  call void @free(ptr noundef nonnull %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @uniform(ptr noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress 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 = { noreturn nounwind "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { 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 = !{!6, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"imbalance", !10, i64 0, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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