; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Grid.ll (ZNK6R2Grid5PrintEP8_IO_FILE)

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

%class.R2Grid = type { %class.R2Affine, %class.R2Affine, double, ptr, [2 x i32], i32, i32 }
%class.R2Affine = type <{ %class.R2Transformation, %class.R3Matrix, i32, [4 x i8] }>
%class.R2Transformation = type { ptr }
%class.R3Matrix = type { [3 x [3 x double]] }

@stdout = external global ptr, align 8
@.str.80 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.81 = external hidden unnamed_addr constant [2 x i8], align 1

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, i32 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK6R2Grid5PrintEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %13, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr @stdout, align 8, !tbaa !5
  store ptr %12, ptr %4, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %11, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %37, %13
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %8)
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %40

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %31, %19
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %8)
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %34

25:                                               ; preds = %20
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %8, i32 noundef %27, i32 noundef %28)
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str.80, double noundef %29) #5
  br label %31

31:                                               ; preds = %25
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !11

34:                                               ; preds = %24
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.81) #5
  br label %37

37:                                               ; preds = %34
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !9
  br label %14, !llvm.loop !13

40:                                               ; preds = %18
  %41 = getelementptr inbounds %class.R2Grid, ptr %8, i32 0, i32 6
  %42 = load i32, ptr %41, align 4, !tbaa !14
  ret i32 %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { inlinehint 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 #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 = { 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 #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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !10, i64 204}
!15 = !{!"_ZTS6R2Grid", !16, i64 0, !16, i64 88, !19, i64 176, !6, i64 184, !7, i64 192, !10, i64 200, !10, i64 204}
!16 = !{!"_ZTS8R2Affine", !17, i64 0, !18, i64 8, !10, i64 80}
!17 = !{!"_ZTS16R2Transformation"}
!18 = !{!"_ZTS8R3Matrix", !7, i64 0}
!19 = !{!"double", !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"

@stdout = external local_unnamed_addr global ptr, align 8
@.str.80 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.81 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK6R2Grid5PrintEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef %1) local_unnamed_addr #3 align 2 {
  %.not = icmp eq ptr %1, null
  %3 = load ptr, ptr @stdout, align 8
  %spec.select = select i1 %.not, ptr %3, ptr %1
  %4 = tail call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader, label %._crit_edge14

.preheader:                                       ; preds = %2, %._crit_edge
  %.0913 = phi i32 [ %11, %._crit_edge ], [ 0, %2 ]
  %6 = tail call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge14:                                    ; preds = %._crit_edge, %2
  %8 = getelementptr inbounds i8, ptr %0, i64 204
  %9 = load i32, ptr %8, align 4, !tbaa !5
  ret i32 %9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %spec.select, ptr noundef nonnull @.str.81) #4
  %11 = add nuw nsw i32 %.0913, 1
  %12 = tail call noundef i32 @_ZNK6R2Grid11YResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %.preheader, label %._crit_edge14, !llvm.loop !15

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.012 = phi i32 [ %16, %.lr.ph ], [ 0, %.preheader ]
  %14 = tail call noundef double @_ZNK6R2Grid9GridValueEii(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %.012, i32 noundef %.0913)
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %spec.select, ptr noundef nonnull @.str.80, double noundef %14) #4
  %16 = add nuw nsw i32 %.012, 1
  %17 = tail call noundef i32 @_ZNK6R2Grid11XResolutionEv(ptr noundef nonnull align 8 dereferenceable(208) %0)
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !17
}

attributes #0 = { inlinehint 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 #1 = { inlinehint 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 #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 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, !12, i64 204}
!6 = !{!"_ZTS6R2Grid", !7, i64 0, !7, i64 88, !13, i64 176, !14, i64 184, !10, i64 192, !12, i64 200, !12, i64 204}
!7 = !{!"_ZTS8R2Affine", !8, i64 0, !9, i64 8, !12, i64 80}
!8 = !{!"_ZTS16R2Transformation"}
!9 = !{!"_ZTS8R3Matrix", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"double", !10, i64 0}
!14 = !{!"any pointer", !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass