; 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.stat_para = type { i64, [5 x float] }

@parameters = external dso_local global [3 x i64], align 16
@arc_costs = external dso_local global %struct.stat_para, align 8
@n_source = external dso_local global i64, align 8
@n_sink = external dso_local global i64, align 8
@capacities = external dso_local global %struct.stat_para, align 8
@supply = external dso_local global i64, align 8
@n_node = external dso_local global i64, align 8
@two_way = external dso_local global i64, align 8
@n1 = external dso_local global i64, align 8
@avg_degree = external dso_local global i64, align 8
@n2 = external dso_local global i64, align 8
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@seed = external dso_local global i32, align 4
@seed_original = 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 float @float_reader(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @__isoc99_sscanf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local void @input(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca [100 x i8], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 100, ptr %7) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %16

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds [100 x i8], ptr %7, i64 0, i64 0
  %13 = call ptr @read_line(ptr noundef %11, ptr noundef %12)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %13, ptr noundef @.str.8, ptr noundef %14) #3
  br label %16

16:                                               ; preds = %10, %2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call i64 @int_reader(ptr noundef %17)
  store i64 %18, ptr @two_way, align 8, !tbaa !9
  %19 = load i64, ptr @two_way, align 8, !tbaa !9
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i64 1, ptr @two_way, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %21, %16
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call i64 @int_reader(ptr noundef %23)
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr @seed, align 4, !tbaa !11
  %26 = sext i32 %25 to i64
  store i64 %26, ptr @seed_original, align 8, !tbaa !9
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call i64 @int_reader(ptr noundef %27)
  store i64 %28, ptr @n_node, align 8, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call i64 @int_reader(ptr noundef %29)
  store i64 %30, ptr %5, align 8, !tbaa !9
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = call i64 @int_reader(ptr noundef %31)
  store i64 %32, ptr @n_source, align 8, !tbaa !9
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = call i64 @int_reader(ptr noundef %33)
  store i64 %34, ptr @n_sink, align 8, !tbaa !9
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = call i64 @int_reader(ptr noundef %35)
  store i64 %36, ptr @avg_degree, align 8, !tbaa !9
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = call i64 @int_reader(ptr noundef %37)
  store i64 %38, ptr @supply, align 8, !tbaa !9
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = call i64 @int_reader(ptr noundef %39)
  store i64 %40, ptr @arc_costs, align 8, !tbaa !13
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %52, %22
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = load i64, ptr @arc_costs, align 8, !tbaa !13
  %44 = getelementptr inbounds [3 x i64], ptr @parameters, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = icmp slt i64 %42, %45
  br i1 %46, label %47, label %55

47:                                               ; preds = %41
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = call float @float_reader(ptr noundef %48)
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = getelementptr inbounds float, ptr getelementptr inbounds (%struct.stat_para, ptr @arc_costs, i32 0, i32 1), i64 %50
  store float %49, ptr %51, align 4, !tbaa !15
  br label %52

52:                                               ; preds = %47
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %6, align 8, !tbaa !9
  br label %41, !llvm.loop !17

55:                                               ; preds = %41
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = call i64 @int_reader(ptr noundef %56)
  store i64 %57, ptr @capacities, align 8, !tbaa !13
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %69, %55
  %59 = load i64, ptr %6, align 8, !tbaa !9
  %60 = load i64, ptr @capacities, align 8, !tbaa !13
  %61 = getelementptr inbounds [3 x i64], ptr @parameters, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !9
  %63 = icmp slt i64 %59, %62
  br i1 %63, label %64, label %72

64:                                               ; preds = %58
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = call float @float_reader(ptr noundef %65)
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = getelementptr inbounds float, ptr getelementptr inbounds (%struct.stat_para, ptr @capacities, i32 0, i32 1), i64 %67
  store float %66, ptr %68, align 4, !tbaa !15
  br label %69

69:                                               ; preds = %64
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = add nsw i64 %70, 1
  store i64 %71, ptr %6, align 8, !tbaa !9
  br label %58, !llvm.loop !19

72:                                               ; preds = %58
  %73 = load i64, ptr %5, align 8, !tbaa !9
  %74 = load i64, ptr %5, align 8, !tbaa !9
  %75 = mul nsw i64 %73, %74
  %76 = load i64, ptr @n_node, align 8, !tbaa !9
  %77 = icmp sge i64 %75, %76
  br i1 %77, label %78, label %88

78:                                               ; preds = %72
  %79 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %79, ptr @n1, align 8, !tbaa !9
  %80 = load i64, ptr @n_node, align 8, !tbaa !9
  %81 = sitofp i64 %80 to float
  %82 = load i64, ptr %5, align 8, !tbaa !9
  %83 = sitofp i64 %82 to float
  %84 = fdiv float %81, %83
  %85 = fpext float %84 to double
  %86 = fadd double %85, 5.000000e-01
  %87 = fptosi double %86 to i64
  store i64 %87, ptr @n2, align 8, !tbaa !9
  br label %98

88:                                               ; preds = %72
  %89 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %89, ptr @n2, align 8, !tbaa !9
  %90 = load i64, ptr @n_node, align 8, !tbaa !9
  %91 = sitofp i64 %90 to float
  %92 = load i64, ptr %5, align 8, !tbaa !9
  %93 = sitofp i64 %92 to float
  %94 = fdiv float %91, %93
  %95 = fpext float %94 to double
  %96 = fadd double %95, 5.000000e-01
  %97 = fptosi double %96 to i64
  store i64 %97, ptr @n1, align 8, !tbaa !9
  br label %98

98:                                               ; preds = %88, %78
  %99 = load i64, ptr @n1, align 8, !tbaa !9
  %100 = load i64, ptr @n2, align 8, !tbaa !9
  %101 = mul nsw i64 %99, %100
  %102 = add nsw i64 %101, 1
  store i64 %102, ptr @n_node, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 100, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @read_line(ptr noundef, 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 = { 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 }

!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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"stat_para", !10, i64 0, !7, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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.stat_para = type { i64, [5 x float] }

@parameters = external dso_local local_unnamed_addr global [3 x i64], align 16
@arc_costs = external dso_local local_unnamed_addr global %struct.stat_para, 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
@capacities = external dso_local local_unnamed_addr global %struct.stat_para, align 8
@supply = external dso_local local_unnamed_addr global i64, align 8
@n_node = external dso_local local_unnamed_addr global i64, align 8
@two_way = external dso_local local_unnamed_addr global i64, align 8
@n1 = external dso_local local_unnamed_addr global i64, align 8
@avg_degree = external dso_local local_unnamed_addr global i64, align 8
@n2 = external dso_local local_unnamed_addr global i64, align 8
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@seed = external dso_local local_unnamed_addr global i32, align 4
@seed_original = 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 float @float_reader(ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_sscanf(ptr nocapture noundef readonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @input(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [100 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %3) #3
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %4

4:                                                ; preds = %2
  %5 = call ptr @read_line(ptr noundef nonnull %0, ptr noundef nonnull %3)
  %6 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %5, ptr noundef nonnull @.str.8, ptr noundef %1) #3
  br label %7

7:                                                ; preds = %4, %2
  %8 = call i64 @int_reader(ptr noundef %0)
  %.not27 = icmp ne i64 %8, 0
  %spec.store.select = zext i1 %.not27 to i64
  store i64 %spec.store.select, ptr @two_way, align 8
  %9 = call i64 @int_reader(ptr noundef %0)
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr @seed, align 4, !tbaa !5
  %sext = shl i64 %9, 32
  %11 = ashr exact i64 %sext, 32
  store i64 %11, ptr @seed_original, align 8, !tbaa !9
  %12 = call i64 @int_reader(ptr noundef %0)
  store i64 %12, ptr @n_node, align 8, !tbaa !9
  %13 = call i64 @int_reader(ptr noundef %0)
  %14 = call i64 @int_reader(ptr noundef %0)
  store i64 %14, ptr @n_source, align 8, !tbaa !9
  %15 = call i64 @int_reader(ptr noundef %0)
  store i64 %15, ptr @n_sink, align 8, !tbaa !9
  %16 = call i64 @int_reader(ptr noundef %0)
  store i64 %16, ptr @avg_degree, align 8, !tbaa !9
  %17 = call i64 @int_reader(ptr noundef %0)
  store i64 %17, ptr @supply, align 8, !tbaa !9
  %18 = call i64 @int_reader(ptr noundef %0)
  store i64 %18, ptr @arc_costs, align 8, !tbaa !11
  %19 = getelementptr inbounds [3 x i64], ptr @parameters, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = icmp sgt i64 %20, 0
  br i1 %21, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.029 = phi i64 [ %24, %.lr.ph ], [ 0, %7 ]
  %22 = call float @float_reader(ptr noundef %0)
  %23 = getelementptr inbounds float, ptr getelementptr inbounds (i8, ptr @arc_costs, i64 8), i64 %.029
  store float %22, ptr %23, align 4, !tbaa !13
  %24 = add nuw nsw i64 %.029, 1
  %25 = load i64, ptr @arc_costs, align 8, !tbaa !11
  %26 = getelementptr inbounds [3 x i64], ptr @parameters, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = icmp slt i64 %24, %27
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %7
  %29 = call i64 @int_reader(ptr noundef %0)
  store i64 %29, ptr @capacities, align 8, !tbaa !11
  %30 = getelementptr inbounds [3 x i64], ptr @parameters, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = icmp sgt i64 %31, 0
  br i1 %32, label %.lr.ph32, label %._crit_edge33

.lr.ph32:                                         ; preds = %._crit_edge, %.lr.ph32
  %.130 = phi i64 [ %35, %.lr.ph32 ], [ 0, %._crit_edge ]
  %33 = call float @float_reader(ptr noundef %0)
  %34 = getelementptr inbounds float, ptr getelementptr inbounds (i8, ptr @capacities, i64 8), i64 %.130
  store float %33, ptr %34, align 4, !tbaa !13
  %35 = add nuw nsw i64 %.130, 1
  %36 = load i64, ptr @capacities, align 8, !tbaa !11
  %37 = getelementptr inbounds [3 x i64], ptr @parameters, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = icmp slt i64 %35, %38
  br i1 %39, label %.lr.ph32, label %._crit_edge33, !llvm.loop !17

._crit_edge33:                                    ; preds = %.lr.ph32, %._crit_edge
  %40 = mul nsw i64 %13, %13
  %41 = load i64, ptr @n_node, align 8, !tbaa !9
  %.not28 = icmp slt i64 %40, %41
  %42 = sitofp i64 %41 to float
  %43 = sitofp i64 %13 to float
  %44 = fdiv float %42, %43
  %45 = fpext float %44 to double
  %46 = fadd double %45, 5.000000e-01
  %47 = fptosi double %46 to i64
  %. = select i1 %.not28, i64 %13, i64 %47
  %.35 = select i1 %.not28, i64 %47, i64 %13
  store i64 %., ptr @n2, align 8
  store i64 %.35, ptr @n1, align 8
  %48 = mul nsw i64 %13, %47
  %49 = add nsw i64 %48, 1
  store i64 %49, ptr @n_node, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %3) #3
  ret void
}

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

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

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 = { nofree 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 }

!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", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"stat_para", !10, i64 0, !7, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,ReassociatePass,SROAPass,SimplifyCFGPass