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

@source_list = external dso_local global ptr, align 8
@sink_list = external dso_local global ptr, align 8
@arc_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_grid_arc = external dso_local global i64, align 8
@n_arc = 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
@initialization.batchfile = external hidden global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@avg_degree = external dso_local global i64, align 8
@n2 = external dso_local global i64, align 8
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@outfile = external dso_local global ptr, 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: nounwind uwtable
define dso_local i64 @initialization(i64 noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [100 x i8], align 16
  %9 = alloca i32, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 100, ptr %8) #4
  %10 = load i64, ptr %5, align 8, !tbaa !5
  %11 = icmp ne i64 %10, 2
  br i1 %11, label %12, label %16

12:                                               ; preds = %3
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = icmp ne i64 %13, 1
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  call void @err(i64 noundef 1)
  br label %16

16:                                               ; preds = %15, %12, %3
  %17 = load ptr, ptr @initialization.batchfile, align 8, !tbaa !9
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %34

19:                                               ; preds = %16
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = icmp eq i64 %20, 2
  br i1 %21, label %22, label %34

22:                                               ; preds = %19
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = getelementptr inbounds ptr, ptr %23, i64 1
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = call noalias ptr @fopen(ptr noundef %25, ptr noundef @.str.6)
  store ptr %26, ptr @initialization.batchfile, align 8, !tbaa !9
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  call void @err(i64 noundef 2)
  br label %29

29:                                               ; preds = %28, %22
  %30 = load ptr, ptr @initialization.batchfile, align 8, !tbaa !9
  %31 = call i64 @int_reader(ptr noundef %30)
  %32 = sub nsw i64 %31, 1
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  store i64 %32, ptr %33, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %29, %19, %16
  %35 = load ptr, ptr @initialization.batchfile, align 8, !tbaa !9
  %36 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  call void @input(ptr noundef %35, ptr noundef %36)
  %37 = load i64, ptr @n_node, align 8, !tbaa !5
  %38 = load i64, ptr @avg_degree, align 8, !tbaa !5
  %39 = mul nsw i64 %37, %38
  store i64 %39, ptr @n_arc, align 8, !tbaa !5
  %40 = load i64, ptr @two_way, align 8, !tbaa !5
  %41 = add nsw i64 %40, 1
  %42 = load i64, ptr @n1, align 8, !tbaa !5
  %43 = sub nsw i64 %42, 1
  %44 = load i64, ptr @n2, align 8, !tbaa !5
  %45 = mul nsw i64 %43, %44
  %46 = load i64, ptr @n2, align 8, !tbaa !5
  %47 = sub nsw i64 %46, 1
  %48 = load i64, ptr @n1, align 8, !tbaa !5
  %49 = mul nsw i64 %47, %48
  %50 = add nsw i64 %45, %49
  %51 = mul nsw i64 %41, %50
  %52 = load i64, ptr @n_source, align 8, !tbaa !5
  %53 = add nsw i64 %51, %52
  %54 = load i64, ptr @n_sink, align 8, !tbaa !5
  %55 = add nsw i64 %53, %54
  store i64 %55, ptr @n_grid_arc, align 8, !tbaa !5
  %56 = load i64, ptr @n_grid_arc, align 8, !tbaa !5
  %57 = load i64, ptr @n_arc, align 8, !tbaa !5
  %58 = icmp sgt i64 %56, %57
  br i1 %58, label %59, label %61

59:                                               ; preds = %34
  %60 = load i64, ptr @n_grid_arc, align 8, !tbaa !5
  store i64 %60, ptr @n_arc, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %59, %34
  %62 = load i64, ptr @n_arc, align 8, !tbaa !5
  %63 = mul i64 %62, 32
  %64 = call noalias ptr @malloc(i64 noundef %63) #5
  store ptr %64, ptr @arc_list, align 8, !tbaa !9
  %65 = icmp eq ptr %64, null
  br i1 %65, label %76, label %66

66:                                               ; preds = %61
  %67 = load i64, ptr @n_source, align 8, !tbaa !5
  %68 = mul i64 %67, 16
  %69 = call noalias ptr @malloc(i64 noundef %68) #5
  store ptr %69, ptr @source_list, align 8, !tbaa !9
  %70 = icmp eq ptr %69, null
  br i1 %70, label %76, label %71

71:                                               ; preds = %66
  %72 = load i64, ptr @n_sink, align 8, !tbaa !5
  %73 = mul i64 %72, 16
  %74 = call noalias ptr @malloc(i64 noundef %73) #5
  store ptr %74, ptr @sink_list, align 8, !tbaa !9
  %75 = icmp eq ptr %74, null
  br i1 %75, label %76, label %77

76:                                               ; preds = %71, %66, %61
  call void @err(i64 noundef 4)
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %87

77:                                               ; preds = %71
  %78 = load i64, ptr %5, align 8, !tbaa !5
  %79 = icmp eq i64 %78, 2
  br i1 %79, label %80, label %86

80:                                               ; preds = %77
  %81 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  %82 = call noalias ptr @fopen(ptr noundef %81, ptr noundef @.str.7)
  store ptr %82, ptr @outfile, align 8, !tbaa !9
  %83 = icmp eq ptr %82, null
  br i1 %83, label %84, label %85

84:                                               ; preds = %80
  call void @err(i64 noundef 3)
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %87

85:                                               ; preds = %80
  store i64 1, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %87

86:                                               ; preds = %77
  store ptr null, ptr @outfile, align 8, !tbaa !9
  store i64 1, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %87

87:                                               ; preds = %86, %85, %84, %76
  call void @llvm.lifetime.end.p0(i64 100, ptr %8) #4
  %88 = load i64, ptr %4, align 8
  ret i64 %88
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @int_reader(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 = { "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 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 #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 = !{!"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}


; 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
@arc_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_grid_arc = external dso_local local_unnamed_addr global i64, align 8
@n_arc = 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
@initialization.batchfile = external hidden local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@avg_degree = external dso_local local_unnamed_addr global i64, align 8
@n2 = external dso_local local_unnamed_addr global i64, align 8
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@outfile = external dso_local local_unnamed_addr global ptr, 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: nounwind uwtable
define dso_local range(i64 0, 2) i64 @initialization(i64 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = alloca [100 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %4) #4
  %5 = add i64 %0, -3
  %or.cond = icmp ult i64 %5, -2
  br i1 %or.cond, label %.thread, label %6

.thread:                                          ; preds = %3
  tail call void @err(i64 noundef 1)
  br label %20

6:                                                ; preds = %3
  %7 = load ptr, ptr @initialization.batchfile, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  %9 = icmp eq i64 %0, 2
  %or.cond3 = and i1 %9, %8
  br i1 %or.cond3, label %10, label %20

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = tail call noalias ptr @fopen(ptr noundef %12, ptr noundef nonnull @.str.6)
  store ptr %13, ptr @initialization.batchfile, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %10
  tail call void @err(i64 noundef 2)
  %.pre = load ptr, ptr @initialization.batchfile, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %15, %10
  %17 = phi ptr [ %.pre, %15 ], [ %13, %10 ]
  %18 = tail call i64 @int_reader(ptr noundef %17)
  %19 = add nsw i64 %18, -1
  store i64 %19, ptr %2, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %.thread, %16, %6
  %21 = phi i1 [ false, %.thread ], [ true, %16 ], [ %9, %6 ]
  %22 = load ptr, ptr @initialization.batchfile, align 8, !tbaa !5
  call void @input(ptr noundef %22, ptr noundef nonnull %4)
  %23 = load i64, ptr @n_node, align 8, !tbaa !9
  %24 = load i64, ptr @avg_degree, align 8, !tbaa !9
  %25 = mul nsw i64 %24, %23
  store i64 %25, ptr @n_arc, align 8, !tbaa !9
  %26 = load i64, ptr @two_way, align 8, !tbaa !9
  %27 = add nsw i64 %26, 1
  %28 = load i64, ptr @n1, align 8, !tbaa !9
  %29 = add nsw i64 %28, -1
  %30 = load i64, ptr @n2, align 8, !tbaa !9
  %31 = mul nsw i64 %29, %30
  %32 = add nsw i64 %30, -1
  %33 = mul nsw i64 %32, %28
  %34 = add nsw i64 %33, %31
  %35 = mul nsw i64 %34, %27
  %36 = load i64, ptr @n_source, align 8, !tbaa !9
  %37 = load i64, ptr @n_sink, align 8, !tbaa !9
  %38 = add i64 %37, %36
  %39 = add i64 %38, %35
  store i64 %39, ptr @n_grid_arc, align 8, !tbaa !9
  %40 = icmp sgt i64 %39, %25
  br i1 %40, label %41, label %42

41:                                               ; preds = %20
  store i64 %39, ptr @n_arc, align 8, !tbaa !9
  br label %42

42:                                               ; preds = %41, %20
  %43 = phi i64 [ %39, %41 ], [ %25, %20 ]
  %44 = shl i64 %43, 5
  %45 = call noalias ptr @malloc(i64 noundef %44) #5
  store ptr %45, ptr @arc_list, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %55, label %47

47:                                               ; preds = %42
  %48 = shl i64 %36, 4
  %49 = call noalias ptr @malloc(i64 noundef %48) #5
  store ptr %49, ptr @source_list, align 8, !tbaa !5
  %50 = icmp eq ptr %49, null
  br i1 %50, label %55, label %51

51:                                               ; preds = %47
  %52 = shl i64 %37, 4
  %53 = call noalias ptr @malloc(i64 noundef %52) #5
  store ptr %53, ptr @sink_list, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %55, label %56

55:                                               ; preds = %51, %47, %42
  call void @err(i64 noundef 4)
  br label %62

56:                                               ; preds = %51
  br i1 %21, label %57, label %61

57:                                               ; preds = %56
  %58 = call noalias ptr @fopen(ptr noundef nonnull %4, ptr noundef nonnull @.str.7)
  store ptr %58, ptr @outfile, align 8, !tbaa !5
  %59 = icmp eq ptr %58, null
  br i1 %59, label %60, label %62

60:                                               ; preds = %57
  call void @err(i64 noundef 3)
  br label %62

61:                                               ; preds = %56
  store ptr null, ptr @outfile, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %57, %61, %60, %55
  %.0 = phi i64 [ 0, %55 ], [ 0, %60 ], [ 1, %61 ], [ 1, %57 ]
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %4) #4
  ret i64 %.0
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @int_reader(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 = { 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass