; LLVM IR from emathew1/3DCompactSolver :: VisitWriter.ll (Z22write_curvilinear_meshPKciPiPfiS1_S1_PKS0_PS2_)

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

@_ZL9useBinary = external hidden global i32, align 4
@.str.11 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z15write_variablesiPiS_PKPKcPPfii(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL12write_stringPKc(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11write_floatf(float noundef) #0

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL9open_filePKc(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL12write_headerv() #3

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL10close_filev() #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z22write_curvilinear_meshPKciPiPfiS1_S1_PKS0_PS2_(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8) #0 {
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca [128 x i8], align 16
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store i32 %1, ptr %11, align 4, !tbaa !9
  store ptr %2, ptr %12, align 8, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !5
  store i32 %4, ptr %14, align 4, !tbaa !9
  store ptr %5, ptr %15, align 8, !tbaa !5
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  store ptr %8, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.start.p0(i64 128, ptr %21) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = getelementptr inbounds i32, ptr %27, i64 0
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds i32, ptr %30, i64 1
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = mul nsw i32 %29, %32
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = getelementptr inbounds i32, ptr %34, i64 2
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = mul nsw i32 %33, %36
  store i32 %37, ptr %22, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #4
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = getelementptr inbounds i32, ptr %38, i64 0
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = sub nsw i32 %40, 1
  %42 = icmp slt i32 %41, 1
  br i1 %42, label %43, label %44

43:                                               ; preds = %9
  br label %49

44:                                               ; preds = %9
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = getelementptr inbounds i32, ptr %45, i64 0
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = sub nsw i32 %47, 1
  br label %49

49:                                               ; preds = %44, %43
  %50 = phi i32 [ 1, %43 ], [ %48, %44 ]
  store i32 %50, ptr %23, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #4
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = getelementptr inbounds i32, ptr %51, i64 1
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = sub nsw i32 %53, 1
  %55 = icmp slt i32 %54, 1
  br i1 %55, label %56, label %57

56:                                               ; preds = %49
  br label %62

57:                                               ; preds = %49
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = getelementptr inbounds i32, ptr %58, i64 1
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = sub nsw i32 %60, 1
  br label %62

62:                                               ; preds = %57, %56
  %63 = phi i32 [ 1, %56 ], [ %61, %57 ]
  store i32 %63, ptr %24, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #4
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds i32, ptr %64, i64 2
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = sub nsw i32 %66, 1
  %68 = icmp slt i32 %67, 1
  br i1 %68, label %69, label %70

69:                                               ; preds = %62
  br label %75

70:                                               ; preds = %62
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = getelementptr inbounds i32, ptr %71, i64 2
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = sub nsw i32 %73, 1
  br label %75

75:                                               ; preds = %70, %69
  %76 = phi i32 [ 1, %69 ], [ %74, %70 ]
  store i32 %76, ptr %25, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #4
  %77 = load i32, ptr %23, align 4, !tbaa !9
  %78 = load i32, ptr %24, align 4, !tbaa !9
  %79 = mul nsw i32 %77, %78
  %80 = load i32, ptr %25, align 4, !tbaa !9
  %81 = mul nsw i32 %79, %80
  store i32 %81, ptr %26, align 4, !tbaa !9
  %82 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %82, ptr @_ZL9useBinary, align 4, !tbaa !9
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZL9open_filePKc(ptr noundef %83)
  call void @_ZL12write_headerv()
  call void @_ZL12write_stringPKc(ptr noundef @.str.19)
  %84 = getelementptr inbounds [128 x i8], ptr %21, i64 0, i64 0
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  %86 = getelementptr inbounds i32, ptr %85, i64 0
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = load ptr, ptr %12, align 8, !tbaa !5
  %89 = getelementptr inbounds i32, ptr %88, i64 1
  %90 = load i32, ptr %89, align 4, !tbaa !9
  %91 = load ptr, ptr %12, align 8, !tbaa !5
  %92 = getelementptr inbounds i32, ptr %91, i64 2
  %93 = load i32, ptr %92, align 4, !tbaa !9
  %94 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %84, ptr noundef @.str.15, i32 noundef %87, i32 noundef %90, i32 noundef %93) #4
  %95 = getelementptr inbounds [128 x i8], ptr %21, i64 0, i64 0
  call void @_ZL12write_stringPKc(ptr noundef %95)
  %96 = getelementptr inbounds [128 x i8], ptr %21, i64 0, i64 0
  %97 = load i32, ptr %22, align 4, !tbaa !9
  %98 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %96, ptr noundef @.str.11, i32 noundef %97) #4
  %99 = getelementptr inbounds [128 x i8], ptr %21, i64 0, i64 0
  call void @_ZL12write_stringPKc(ptr noundef %99)
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %100

100:                                              ; preds = %111, %75
  %101 = load i32, ptr %19, align 4, !tbaa !9
  %102 = load i32, ptr %22, align 4, !tbaa !9
  %103 = mul nsw i32 3, %102
  %104 = icmp slt i32 %101, %103
  br i1 %104, label %105, label %114

105:                                              ; preds = %100
  %106 = load ptr, ptr %13, align 8, !tbaa !5
  %107 = load i32, ptr %19, align 4, !tbaa !9
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds float, ptr %106, i64 %108
  %110 = load float, ptr %109, align 4, !tbaa !11
  call void @_ZL11write_floatf(float noundef %110)
  br label %111

111:                                              ; preds = %105
  %112 = load i32, ptr %19, align 4, !tbaa !9
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr %19, align 4, !tbaa !9
  br label %100, !llvm.loop !13

114:                                              ; preds = %100
  %115 = load i32, ptr %14, align 4, !tbaa !9
  %116 = load ptr, ptr %15, align 8, !tbaa !5
  %117 = load ptr, ptr %16, align 8, !tbaa !5
  %118 = load ptr, ptr %17, align 8, !tbaa !5
  %119 = load ptr, ptr %18, align 8, !tbaa !5
  %120 = load i32, ptr %22, align 4, !tbaa !9
  %121 = load i32, ptr %26, align 4, !tbaa !9
  call void @_Z15write_variablesiPiS_PKPKcPPfii(i32 noundef %115, ptr noundef %116, ptr noundef %117, ptr noundef %118, ptr noundef %119, i32 noundef %120, i32 noundef %121)
  call void @_ZL10close_filev()
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  ret void
}

attributes #0 = { mustprogress 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 = { 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 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@_ZL9useBinary = external hidden local_unnamed_addr global i32, align 4
@.str.11 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z15write_variablesiPiS_PKPKcPPfii(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL12write_stringPKc(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11write_floatf(float noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL9open_filePKc(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL12write_headerv() local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL10close_filev() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z22write_curvilinear_meshPKciPiPfiS1_S1_PKS0_PS2_(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, i32 noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8) local_unnamed_addr #0 {
  %10 = alloca [128 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %10) #5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %2, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = mul i32 %13, %11
  %15 = getelementptr inbounds i8, ptr %2, i64 8
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = mul i32 %14, %16
  store i32 %1, ptr @_ZL9useBinary, align 4, !tbaa !5
  tail call void @_ZL9open_filePKc(ptr noundef %0)
  tail call void @_ZL12write_headerv()
  tail call void @_ZL12write_stringPKc(ptr noundef nonnull @.str.19)
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr %12, align 4, !tbaa !5
  %20 = load i32, ptr %15, align 4, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %10, ptr noundef nonnull dereferenceable(1) @.str.15, i32 noundef %18, i32 noundef %19, i32 noundef %20) #5
  call void @_ZL12write_stringPKc(ptr noundef nonnull %10)
  %22 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %10, ptr noundef nonnull dereferenceable(1) @.str.11, i32 noundef %17) #5
  call void @_ZL12write_stringPKc(ptr noundef nonnull %10)
  %23 = icmp sgt i32 %17, 0
  br i1 %23, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %9
  %24 = mul i32 %17, 3
  %smax = call i32 @llvm.smax.i32(i32 %24, i32 1)
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %25 = getelementptr inbounds float, ptr %3, i64 %indvars.iv
  %26 = load float, ptr %25, align 4, !tbaa !9
  call void @_ZL11write_floatf(float noundef %26)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %9
  %27 = add nsw i32 %16, -1
  %.inv33 = icmp sgt i32 %16, 1
  %28 = select i1 %.inv33, i32 %27, i32 1
  %29 = add nsw i32 %13, -1
  %.inv32 = icmp sgt i32 %13, 1
  %30 = select i1 %.inv32, i32 %29, i32 1
  %31 = add nsw i32 %11, -1
  %.inv = icmp sgt i32 %11, 1
  %spec.select = select i1 %.inv, i32 %31, i32 1
  %32 = mul nsw i32 %30, %spec.select
  %33 = mul nsw i32 %32, %28
  call void @_Z15write_variablesiPiS_PKPKcPPfii(i32 noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8, i32 noundef %17, i32 noundef %33)
  call void @_ZL10close_filev()
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %10) #5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

attributes #0 = { mustprogress 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 = { 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 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass