; LLVM IR from NaokiHori/VerySimpleNSSolver :: src (main)

; 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.schedule_t = type { double, double }
%struct.domain_t = type { double, double, i64, i64, double, double }
%struct.flow_field_t = type { ptr, ptr, ptr, ptr }
%struct.flow_solver_t = type { ptr, ptr, ptr, %struct.poisson_solver_t }
%struct.poisson_solver_t = type { ptr, ptr, ptr, ptr, double, ptr, ptr, ptr, ptr, ptr }

@__const.main.rate = external hidden unnamed_addr constant %struct.schedule_t, align 8
@__const.main.next = external hidden unnamed_addr constant %struct.schedule_t, align 8
@main.step = external hidden global i64, align 8
@main.id = external hidden global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.domain_t, align 8
  %3 = alloca %struct.flow_field_t, align 8
  %4 = alloca %struct.flow_solver_t, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca %struct.schedule_t, align 8
  %8 = alloca %struct.schedule_t, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 48, ptr %2) #5
  call void @llvm.memset.p0.i64(ptr align 8 %2, i8 0, i64 48, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #5
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 104, ptr %4) #5
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 104, i1 false)
  %11 = call i32 @domain_init(ptr noundef %2)
  %12 = icmp ne i32 0, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %0
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %83

14:                                               ; preds = %0
  %15 = call i32 @flow_field_init(ptr noundef %2, ptr noundef %3)
  %16 = icmp ne i32 0, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %83

18:                                               ; preds = %14
  %19 = call i32 @flow_solver_init(ptr noundef %2, ptr noundef %4)
  %20 = icmp ne i32 0, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %83

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store double 5.000000e+00, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 @__const.main.rate, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 @__const.main.next, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store double 0.000000e+00, ptr %9, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %71, %22
  %24 = load double, ptr %9, align 8, !tbaa !5
  %25 = fcmp olt double %24, 5.000000e+00
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 2, ptr %5, align 4
  br label %72

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store double 0.000000e+00, ptr %10, align 8, !tbaa !5
  %28 = call i32 @integrate(ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %10)
  %29 = icmp ne i32 0, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i32 2, ptr %5, align 4
  br label %69

31:                                               ; preds = %27
  %32 = load i64, ptr @main.step, align 8, !tbaa !9
  %33 = add i64 %32, 1
  store i64 %33, ptr @main.step, align 8, !tbaa !9
  %34 = load double, ptr %10, align 8, !tbaa !5
  %35 = load double, ptr %9, align 8, !tbaa !5
  %36 = fadd double %35, %34
  store double %36, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.schedule_t, ptr %8, i32 0, i32 0
  %38 = load double, ptr %37, align 8, !tbaa !11
  %39 = load double, ptr %9, align 8, !tbaa !5
  %40 = fcmp olt double %38, %39
  br i1 %40, label %41, label %51

41:                                               ; preds = %31
  %42 = load i64, ptr @main.step, align 8, !tbaa !9
  %43 = load double, ptr %9, align 8, !tbaa !5
  %44 = load double, ptr %10, align 8, !tbaa !5
  %45 = call i32 @monitor(i64 noundef %42, double noundef %43, double noundef %44, ptr noundef %2, ptr noundef %3)
  %46 = getelementptr inbounds %struct.schedule_t, ptr %7, i32 0, i32 0
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = getelementptr inbounds %struct.schedule_t, ptr %8, i32 0, i32 0
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fadd double %49, %47
  store double %50, ptr %48, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %41, %31
  %52 = getelementptr inbounds %struct.schedule_t, ptr %8, i32 0, i32 1
  %53 = load double, ptr %52, align 8, !tbaa !13
  %54 = load double, ptr %9, align 8, !tbaa !5
  %55 = fcmp olt double %53, %54
  br i1 %55, label %56, label %68

56:                                               ; preds = %51
  %57 = load i64, ptr @main.id, align 8, !tbaa !9
  %58 = load i64, ptr @main.step, align 8, !tbaa !9
  %59 = load double, ptr %9, align 8, !tbaa !5
  %60 = call i32 @save(i64 noundef %57, i64 noundef %58, double noundef %59, ptr noundef %2, ptr noundef %3)
  %61 = load i64, ptr @main.id, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr @main.id, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.schedule_t, ptr %7, i32 0, i32 1
  %64 = load double, ptr %63, align 8, !tbaa !13
  %65 = getelementptr inbounds %struct.schedule_t, ptr %8, i32 0, i32 1
  %66 = load double, ptr %65, align 8, !tbaa !13
  %67 = fadd double %66, %64
  store double %67, ptr %65, align 8, !tbaa !13
  br label %68

68:                                               ; preds = %56, %51
  store i32 0, ptr %5, align 4
  br label %69

69:                                               ; preds = %68, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %70 = load i32, ptr %5, align 4
  switch i32 %70, label %72 [
    i32 0, label %71
  ]

71:                                               ; preds = %69
  br label %23, !llvm.loop !14

72:                                               ; preds = %69, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %73

73:                                               ; preds = %72
  %74 = call i32 @flow_field_finalize(ptr noundef %3)
  %75 = icmp ne i32 0, %74
  br i1 %75, label %76, label %77

76:                                               ; preds = %73
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %82

77:                                               ; preds = %73
  %78 = call i32 @flow_solver_finalize(ptr noundef %4)
  %79 = icmp ne i32 0, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %77
  store i32 1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %82

81:                                               ; preds = %77
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %82

82:                                               ; preds = %81, %80, %76
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %83

83:                                               ; preds = %82, %21, %17, %13
  call void @llvm.lifetime.end.p0(i64 104, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %2) #5
  %84 = load i32, ptr %1, align 4
  ret i32 %84
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @domain_init(ptr noundef) #3

declare i32 @flow_field_init(ptr noundef, ptr noundef) #3

declare i32 @flow_solver_init(ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

declare i32 @integrate(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @monitor(i64 noundef, double noundef, double noundef, ptr noundef, ptr noundef) #3

declare i32 @save(i64 noundef, i64 noundef, double noundef, ptr noundef, ptr noundef) #3

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

declare i32 @flow_field_finalize(ptr noundef) #3

declare i32 @flow_solver_finalize(ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!"double", !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, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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.schedule_t = type { double, double }
%struct.domain_t = type { double, double, i64, i64, double, double }
%struct.flow_field_t = type { ptr, ptr, ptr, ptr }
%struct.flow_solver_t = type { ptr, ptr, ptr, %struct.poisson_solver_t }
%struct.poisson_solver_t = type { ptr, ptr, ptr, ptr, double, ptr, ptr, ptr, ptr, ptr }

@__const.main.rate = external hidden unnamed_addr constant %struct.schedule_t, align 8
@__const.main.next = external hidden unnamed_addr constant %struct.schedule_t, align 8
@main.step = external hidden local_unnamed_addr global i64, align 8
@main.id = external hidden local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.domain_t, align 8
  %2 = alloca %struct.flow_field_t, align 8
  %3 = alloca %struct.flow_solver_t, align 8
  %4 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %1, i8 0, i64 48, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %2, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(104) %3, i8 0, i64 104, i1 false)
  %5 = call i32 @domain_init(ptr noundef nonnull %1) #4
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %36

6:                                                ; preds = %0
  %7 = call i32 @flow_field_init(ptr noundef nonnull %1, ptr noundef nonnull %2) #4
  %.not15 = icmp eq i32 %7, 0
  br i1 %.not15, label %8, label %36

8:                                                ; preds = %6
  %9 = call i32 @flow_solver_init(ptr noundef nonnull %1, ptr noundef nonnull %3) #4
  %.not16 = icmp eq i32 %9, 0
  br i1 %.not16, label %10, label %36

10:                                               ; preds = %8
  %.sroa.08.0.copyload = load double, ptr @__const.main.rate, align 8
  %.sroa.4.0.copyload = load double, ptr getelementptr inbounds (i8, ptr @__const.main.rate, i64 8), align 8
  %.sroa.0.0.copyload = load double, ptr @__const.main.next, align 8
  %.sroa.6.0.copyload = load double, ptr getelementptr inbounds (i8, ptr @__const.main.next, i64 8), align 8
  br label %11

11:                                               ; preds = %10, %31
  %.025 = phi double [ 0.000000e+00, %10 ], [ %17, %31 ]
  %.sroa.0.024 = phi double [ %.sroa.0.0.copyload, %10 ], [ %.sroa.0.1, %31 ]
  %.sroa.6.023 = phi double [ %.sroa.6.0.copyload, %10 ], [ %.sroa.6.2, %31 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store double 0.000000e+00, ptr %4, align 8, !tbaa !5
  %12 = call i32 @integrate(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4) #4
  %.not17 = icmp eq i32 %12, 0
  br i1 %.not17, label %13, label %.thread

.thread:                                          ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %.loopexit

13:                                               ; preds = %11
  %14 = load i64, ptr @main.step, align 8, !tbaa !9
  %15 = add i64 %14, 1
  store i64 %15, ptr @main.step, align 8, !tbaa !9
  %16 = load double, ptr %4, align 8, !tbaa !5
  %17 = fadd double %.025, %16
  %18 = fcmp olt double %.sroa.0.024, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %13
  %20 = call i32 @monitor(i64 noundef %15, double noundef %17, double noundef %16, ptr noundef nonnull %1, ptr noundef nonnull %2) #4
  %21 = fadd double %.sroa.08.0.copyload, %.sroa.0.024
  br label %22

22:                                               ; preds = %19, %13
  %.sroa.0.1 = phi double [ %21, %19 ], [ %.sroa.0.024, %13 ]
  %23 = fcmp olt double %.sroa.6.023, %17
  br i1 %23, label %24, label %31

24:                                               ; preds = %22
  %25 = load i64, ptr @main.id, align 8, !tbaa !9
  %26 = load i64, ptr @main.step, align 8, !tbaa !9
  %27 = call i32 @save(i64 noundef %25, i64 noundef %26, double noundef %17, ptr noundef nonnull %1, ptr noundef nonnull %2) #4
  %28 = load i64, ptr @main.id, align 8, !tbaa !9
  %29 = add i64 %28, 1
  store i64 %29, ptr @main.id, align 8, !tbaa !9
  %30 = fadd double %.sroa.4.0.copyload, %.sroa.6.023
  br label %31

31:                                               ; preds = %22, %24
  %.sroa.6.2 = phi double [ %30, %24 ], [ %.sroa.6.023, %22 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  %32 = fcmp olt double %17, 5.000000e+00
  br i1 %32, label %11, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %31, %.thread
  %33 = call i32 @flow_field_finalize(ptr noundef nonnull %2) #4
  %.not18 = icmp eq i32 %33, 0
  br i1 %.not18, label %34, label %36

34:                                               ; preds = %.loopexit
  %35 = call i32 @flow_solver_finalize(ptr noundef nonnull %3) #4
  %.not19 = icmp ne i32 %35, 0
  %. = zext i1 %.not19 to i32
  br label %36

36:                                               ; preds = %.loopexit, %34, %8, %6, %0
  %.111 = phi i32 [ 1, %0 ], [ 1, %6 ], [ 1, %8 ], [ 1, %.loopexit ], [ %., %34 ]
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #4
  ret i32 %.111
}

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

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

declare i32 @domain_init(ptr noundef) local_unnamed_addr #3

declare i32 @flow_field_init(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @flow_solver_init(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @integrate(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @monitor(i64 noundef, double noundef, double noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @save(i64 noundef, i64 noundef, double noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

declare i32 @flow_field_finalize(ptr noundef) local_unnamed_addr #3

declare i32 @flow_solver_finalize(ptr noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 }

!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 = !{!"double", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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