; 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
@supply = 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
define dso_local void @assign_imbalance() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca float, align 4
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %5 = load i64, ptr @supply, align 8, !tbaa !5
  %6 = sitofp i64 %5 to double
  %7 = fmul double 2.000000e+00, %6
  %8 = load i64, ptr @n_source, align 8, !tbaa !5
  %9 = sitofp i64 %8 to double
  %10 = fdiv double %7, %9
  %11 = fptrunc double %10 to float
  store float %11, ptr %3, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %43, %0
  store i64 1, ptr %2, align 8, !tbaa !5
  %13 = load i64, ptr @supply, align 8, !tbaa !5
  store i64 %13, ptr %1, align 8, !tbaa !5
  %14 = load ptr, ptr @source_list, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.imbalance, ptr %14, i64 1
  store ptr %15, ptr %4, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %34, %12
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = load i64, ptr @n_source, align 8, !tbaa !5
  %19 = icmp slt i64 %17, %18
  br i1 %19, label %20, label %39

20:                                               ; preds = %16
  %21 = call float @randy()
  %22 = load float, ptr %3, align 4, !tbaa !9
  %23 = fmul float %21, %22
  %24 = fpext float %23 to double
  %25 = fadd double %24, 5.000000e-01
  %26 = fptosi double %25 to i64
  %27 = load ptr, ptr %4, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.imbalance, ptr %27, i32 0, i32 1
  store i64 %26, ptr %28, align 8, !tbaa !13
  %29 = load ptr, ptr %4, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.imbalance, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !13
  %32 = load i64, ptr %1, align 8, !tbaa !5
  %33 = sub nsw i64 %32, %31
  store i64 %33, ptr %1, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %20
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %2, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.imbalance, ptr %37, i32 1
  store ptr %38, ptr %4, align 8, !tbaa !11
  br label %16, !llvm.loop !15

39:                                               ; preds = %16
  %40 = load i64, ptr %1, align 8, !tbaa !5
  %41 = load ptr, ptr @source_list, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.imbalance, ptr %41, i32 0, i32 1
  store i64 %40, ptr %42, align 8, !tbaa !13
  br label %43

43:                                               ; preds = %39
  %44 = load i64, ptr %1, align 8, !tbaa !5
  %45 = icmp sle i64 %44, 0
  br i1 %45, label %12, label %46, !llvm.loop !17

46:                                               ; preds = %43
  %47 = load i64, ptr @supply, align 8, !tbaa !5
  %48 = sitofp i64 %47 to double
  %49 = fmul double -2.000000e+00, %48
  %50 = load i64, ptr @n_sink, align 8, !tbaa !5
  %51 = sitofp i64 %50 to double
  %52 = fdiv double %49, %51
  %53 = fptrunc double %52 to float
  store float %53, ptr %3, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %86, %46
  store i64 1, ptr %2, align 8, !tbaa !5
  %55 = load i64, ptr @supply, align 8, !tbaa !5
  store i64 %55, ptr %1, align 8, !tbaa !5
  %56 = load ptr, ptr @sink_list, align 8, !tbaa !11
  %57 = getelementptr inbounds %struct.imbalance, ptr %56, i64 1
  store ptr %57, ptr %4, align 8, !tbaa !11
  br label %58

58:                                               ; preds = %76, %54
  %59 = load i64, ptr %2, align 8, !tbaa !5
  %60 = load i64, ptr @n_sink, align 8, !tbaa !5
  %61 = icmp slt i64 %59, %60
  br i1 %61, label %62, label %81

62:                                               ; preds = %58
  %63 = call float @randy()
  %64 = load float, ptr %3, align 4, !tbaa !9
  %65 = fmul float %63, %64
  %66 = fpext float %65 to double
  %67 = fsub double %66, 5.000000e-01
  %68 = fptosi double %67 to i64
  %69 = load ptr, ptr %4, align 8, !tbaa !11
  %70 = getelementptr inbounds %struct.imbalance, ptr %69, i32 0, i32 1
  store i64 %68, ptr %70, align 8, !tbaa !13
  %71 = load ptr, ptr %4, align 8, !tbaa !11
  %72 = getelementptr inbounds %struct.imbalance, ptr %71, i32 0, i32 1
  %73 = load i64, ptr %72, align 8, !tbaa !13
  %74 = load i64, ptr %1, align 8, !tbaa !5
  %75 = add nsw i64 %74, %73
  store i64 %75, ptr %1, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %62
  %77 = load i64, ptr %2, align 8, !tbaa !5
  %78 = add nsw i64 %77, 1
  store i64 %78, ptr %2, align 8, !tbaa !5
  %79 = load ptr, ptr %4, align 8, !tbaa !11
  %80 = getelementptr inbounds %struct.imbalance, ptr %79, i32 1
  store ptr %80, ptr %4, align 8, !tbaa !11
  br label %58, !llvm.loop !18

81:                                               ; preds = %58
  %82 = load i64, ptr %1, align 8, !tbaa !5
  %83 = sub nsw i64 0, %82
  %84 = load ptr, ptr @sink_list, align 8, !tbaa !11
  %85 = getelementptr inbounds %struct.imbalance, ptr %84, i32 0, i32 1
  store i64 %83, ptr %85, align 8, !tbaa !13
  br label %86

86:                                               ; preds = %81
  %87 = load i64, ptr %1, align 8, !tbaa !5
  %88 = icmp sle i64 %87, 0
  br i1 %88, label %54, label %89, !llvm.loop !19

89:                                               ; preds = %86
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local float @randy() #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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"imbalance", !6, i64 0, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}


; 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
@supply = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local void @assign_imbalance() local_unnamed_addr #0 {
  %1 = load i64, ptr @supply, align 8, !tbaa !5
  %2 = sitofp i64 %1 to double
  %3 = fmul double %2, 2.000000e+00
  %4 = load i64, ptr @n_source, align 8, !tbaa !5
  %5 = sitofp i64 %4 to double
  %6 = fdiv double %3, %5
  %7 = fptrunc double %6 to float
  %8 = icmp sgt i64 %4, 1
  %.pre = load ptr, ptr @source_list, align 8, !tbaa !9
  br i1 %8, label %.split, label %.split.us

.split.us:                                        ; preds = %0
  %9 = getelementptr inbounds i8, ptr %.pre, i64 8
  store i64 %1, ptr %9, align 8, !tbaa !11
  %10 = icmp slt i64 %1, 1
  br i1 %10, label %.split.us.split, label %.split26.us, !llvm.loop !13

.split.us.split:                                  ; preds = %.split.us, %.split.us.split
  br label %.split.us.split

.split:                                           ; preds = %0, %._crit_edge
  %11 = phi ptr [ %25, %._crit_edge ], [ %.pre, %0 ]
  %12 = phi i64 [ %26, %._crit_edge ], [ %4, %0 ]
  %13 = load i64, ptr @supply, align 8, !tbaa !5
  %14 = icmp sgt i64 %12, 1
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.split, %.lr.ph
  %.pn2124 = phi ptr [ %.0, %.lr.ph ], [ %11, %.split ]
  %.01723 = phi i64 [ %22, %.lr.ph ], [ 1, %.split ]
  %.01922 = phi i64 [ %21, %.lr.ph ], [ %13, %.split ]
  %.0 = getelementptr inbounds i8, ptr %.pn2124, i64 16
  %15 = tail call float @randy()
  %16 = fmul float %15, %7
  %17 = fpext float %16 to double
  %18 = fadd double %17, 5.000000e-01
  %19 = fptosi double %18 to i64
  %20 = getelementptr inbounds i8, ptr %.pn2124, i64 24
  store i64 %19, ptr %20, align 8, !tbaa !11
  %21 = sub nsw i64 %.01922, %19
  %22 = add nuw nsw i64 %.01723, 1
  %23 = load i64, ptr @n_source, align 8, !tbaa !5
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre38 = load ptr, ptr @source_list, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.split
  %25 = phi ptr [ %11, %.split ], [ %.pre38, %._crit_edge.loopexit ]
  %26 = phi i64 [ %12, %.split ], [ %23, %._crit_edge.loopexit ]
  %.019.lcssa = phi i64 [ %13, %.split ], [ %21, %._crit_edge.loopexit ]
  %27 = getelementptr inbounds i8, ptr %25, i64 8
  store i64 %.019.lcssa, ptr %27, align 8, !tbaa !11
  %28 = icmp slt i64 %.019.lcssa, 1
  br i1 %28, label %.split, label %.split26.us.loopexit, !llvm.loop !16

.split26.us.loopexit:                             ; preds = %._crit_edge
  %.pre39 = load i64, ptr @supply, align 8, !tbaa !5
  %.pre42 = sitofp i64 %.pre39 to double
  br label %.split26.us

.split26.us:                                      ; preds = %.split26.us.loopexit, %.split.us
  %.pre-phi = phi double [ %.pre42, %.split26.us.loopexit ], [ %2, %.split.us ]
  %29 = phi i64 [ %.pre39, %.split26.us.loopexit ], [ %1, %.split.us ]
  %30 = fmul double %.pre-phi, -2.000000e+00
  %31 = load i64, ptr @n_sink, align 8, !tbaa !5
  %32 = sitofp i64 %31 to double
  %33 = fdiv double %30, %32
  %34 = fptrunc double %33 to float
  %35 = icmp sgt i64 %31, 1
  br i1 %35, label %.split34.preheader, label %.split34.us

.split34.preheader:                               ; preds = %.split26.us
  %.pre40 = load ptr, ptr @sink_list, align 8, !tbaa !9
  br label %.split34

.split34.us:                                      ; preds = %.split26.us
  %36 = sub nsw i64 0, %29
  %37 = load ptr, ptr @sink_list, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %37, i64 8
  store i64 %36, ptr %38, align 8, !tbaa !11
  %39 = icmp slt i64 %29, 1
  br i1 %39, label %.split34.us.split, label %.split36.us, !llvm.loop !18

.split34.us.split:                                ; preds = %.split34.us, %.split34.us.split
  br label %.split34.us.split

.split34:                                         ; preds = %.split34.preheader, %._crit_edge32
  %40 = phi ptr [ %.pre40, %.split34.preheader ], [ %54, %._crit_edge32 ]
  %41 = phi i64 [ %31, %.split34.preheader ], [ %55, %._crit_edge32 ]
  %42 = load i64, ptr @supply, align 8, !tbaa !5
  %43 = icmp sgt i64 %41, 1
  br i1 %43, label %.lr.ph31, label %._crit_edge32

.lr.ph31:                                         ; preds = %.split34, %.lr.ph31
  %.pn29 = phi ptr [ %.1, %.lr.ph31 ], [ %40, %.split34 ]
  %.11828 = phi i64 [ %51, %.lr.ph31 ], [ 1, %.split34 ]
  %.12027 = phi i64 [ %50, %.lr.ph31 ], [ %42, %.split34 ]
  %.1 = getelementptr inbounds i8, ptr %.pn29, i64 16
  %44 = tail call float @randy()
  %45 = fmul float %44, %34
  %46 = fpext float %45 to double
  %47 = fadd double %46, -5.000000e-01
  %48 = fptosi double %47 to i64
  %49 = getelementptr inbounds i8, ptr %.pn29, i64 24
  store i64 %48, ptr %49, align 8, !tbaa !11
  %50 = add nsw i64 %.12027, %48
  %51 = add nuw nsw i64 %.11828, 1
  %52 = load i64, ptr @n_sink, align 8, !tbaa !5
  %53 = icmp slt i64 %51, %52
  br i1 %53, label %.lr.ph31, label %._crit_edge32.loopexit, !llvm.loop !19

._crit_edge32.loopexit:                           ; preds = %.lr.ph31
  %.pre41 = load ptr, ptr @sink_list, align 8, !tbaa !9
  br label %._crit_edge32

._crit_edge32:                                    ; preds = %._crit_edge32.loopexit, %.split34
  %54 = phi ptr [ %40, %.split34 ], [ %.pre41, %._crit_edge32.loopexit ]
  %55 = phi i64 [ %41, %.split34 ], [ %52, %._crit_edge32.loopexit ]
  %.120.lcssa = phi i64 [ %42, %.split34 ], [ %50, %._crit_edge32.loopexit ]
  %56 = sub nsw i64 0, %.120.lcssa
  %57 = getelementptr inbounds i8, ptr %54, i64 8
  store i64 %56, ptr %57, align 8, !tbaa !11
  %58 = icmp slt i64 %.120.lcssa, 1
  br i1 %58, label %.split34, label %.split36.us, !llvm.loop !20

.split36.us:                                      ; preds = %._crit_edge32, %.split34.us
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local float @randy() local_unnamed_addr #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" }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"imbalance", !6, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14, !17}
!17 = !{!"llvm.loop.unswitch.partial.disable"}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}
!20 = distinct !{!20, !14, !17}


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