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

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @flow_solver_init(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.domain_t, ptr %12, i32 0, i32 2
  %14 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %14, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.domain_t, ptr %15, i32 0, i32 3
  %17 = load i64, ptr %16, align 8, !tbaa !14
  store i64 %17, ptr %7, align 8, !tbaa !13
  %18 = load i64, ptr %6, align 8, !tbaa !13
  %19 = add i64 %18, 2
  %20 = load i64, ptr %7, align 8, !tbaa !13
  %21 = add i64 %20, 2
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.flow_solver_t, ptr %22, i32 0, i32 0
  %24 = call i32 @array_init(i64 noundef %19, i64 noundef %21, ptr noundef %23)
  %25 = load i64, ptr %6, align 8, !tbaa !13
  %26 = add i64 %25, 2
  %27 = load i64, ptr %7, align 8, !tbaa !13
  %28 = add i64 %27, 2
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.flow_solver_t, ptr %29, i32 0, i32 1
  %31 = call i32 @array_init(i64 noundef %26, i64 noundef %28, ptr noundef %30)
  %32 = load i64, ptr %6, align 8, !tbaa !13
  %33 = add i64 %32, 2
  %34 = load i64, ptr %7, align 8, !tbaa !13
  %35 = add i64 %34, 2
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.flow_solver_t, ptr %36, i32 0, i32 2
  %38 = call i32 @array_init(i64 noundef %33, i64 noundef %35, ptr noundef %37)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.flow_solver_t, ptr %39, i32 0, i32 3
  store ptr %40, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.poisson_solver_t, ptr %41, i32 0, i32 0
  store ptr %42, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.poisson_solver_t, ptr %43, i32 0, i32 1
  store ptr %44, ptr %10, align 8, !tbaa !5
  %45 = load i64, ptr %6, align 8, !tbaa !13
  %46 = load i64, ptr %7, align 8, !tbaa !13
  %47 = mul i64 %45, %46
  %48 = call ptr @memory_alloc(i64 noundef %47, i64 noundef 8)
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %48, ptr %49, align 8, !tbaa !5
  %50 = load i64, ptr %6, align 8, !tbaa !13
  %51 = load i64, ptr %7, align 8, !tbaa !13
  %52 = mul i64 %50, %51
  %53 = call ptr @memory_alloc(i64 noundef %52, i64 noundef 8)
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %53, ptr %54, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = call i32 @init_x_solver(ptr noundef %55, ptr noundef %56)
  %58 = icmp ne i32 0, %57
  br i1 %58, label %59, label %65

59:                                               ; preds = %2
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr @stderr, align 8, !tbaa !5
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 104, ptr noundef @.str.2) #4
  br label %63

63:                                               ; preds = %60
  br label %64

64:                                               ; preds = %63
  br label %77

65:                                               ; preds = %2
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = call i32 @init_y_solver(ptr noundef %66, ptr noundef %67)
  %69 = icmp ne i32 0, %68
  br i1 %69, label %70, label %76

70:                                               ; preds = %65
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr @stderr, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 109, ptr noundef @.str.3) #4
  br label %74

74:                                               ; preds = %71
  br label %75

75:                                               ; preds = %74
  br label %77

76:                                               ; preds = %65
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %83

77:                                               ; preds = %75, %64
  br label %78

78:                                               ; preds = %77
  %79 = load ptr, ptr @stderr, align 8, !tbaa !5
  %80 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %79, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 114, ptr noundef @.str.4) #4
  br label %81

81:                                               ; preds = %78
  br label %82

82:                                               ; preds = %81
  store i32 1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %83

83:                                               ; preds = %82, %76
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %84 = load i32, ptr %3, 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

declare i32 @array_init(i64 noundef, i64 noundef, ptr noundef) #2

declare ptr @memory_alloc(i64 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @init_x_solver(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @init_y_solver(ptr noundef, ptr noundef) #0

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

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

!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, !12, i64 16}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 24, !11, i64 32, !11, i64 40}
!11 = !{!"double", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !12, i64 24}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @flow_solver_init(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !11
  %7 = add i64 %4, 2
  %8 = add i64 %6, 2
  %9 = tail call i32 @array_init(i64 noundef %7, i64 noundef %8, ptr noundef %1) #3
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = tail call i32 @array_init(i64 noundef %7, i64 noundef %8, ptr noundef nonnull %10) #3
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = tail call i32 @array_init(i64 noundef %7, i64 noundef %8, ptr noundef nonnull %12) #3
  %14 = getelementptr inbounds i8, ptr %1, i64 24
  %15 = getelementptr inbounds i8, ptr %1, i64 32
  %16 = mul i64 %6, %4
  %17 = tail call ptr @memory_alloc(i64 noundef %16, i64 noundef 8) #3
  store ptr %17, ptr %14, align 8, !tbaa !12
  %18 = tail call ptr @memory_alloc(i64 noundef %16, i64 noundef 8) #3
  store ptr %18, ptr %15, align 8, !tbaa !12
  %19 = tail call i32 @init_x_solver(ptr noundef %0, ptr noundef nonnull %14)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %23, label %20

20:                                               ; preds = %2
  %21 = load ptr, ptr @stderr, align 8, !tbaa !12
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 104, ptr noundef nonnull @.str.2) #4
  br label %28

23:                                               ; preds = %2
  %24 = tail call i32 @init_y_solver(ptr noundef nonnull %0, ptr noundef nonnull %14)
  %.not24 = icmp eq i32 %24, 0
  br i1 %.not24, label %31, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr @stderr, align 8, !tbaa !12
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 109, ptr noundef nonnull @.str.3) #4
  br label %28

28:                                               ; preds = %20, %25
  %29 = load ptr, ptr @stderr, align 8, !tbaa !12
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 114, ptr noundef nonnull @.str.4) #4
  br label %31

31:                                               ; preds = %23, %28
  %.0 = phi i32 [ 1, %28 ], [ 0, %23 ]
  ret i32 %.0
}

declare i32 @array_init(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @memory_alloc(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @init_x_solver(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden i32 @init_y_solver(ptr noundef, ptr noundef) 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" }
attributes #1 = { "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 }
attributes #4 = { cold 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, !10, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}


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