; LLVM IR from niessner/Matterport :: code/gaps/pkgs/RGBD/RGBDCamera.ll (ZNK10RGBDCamera19WriteMatterportFileEPKc)

; 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.RGBDCamera = type <{ i32, i32, i32, i32, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, %class.R4Matrix, ptr, ptr, ptr, ptr, i32, i32, i32, [4 x i8] }>
%class.R4Matrix = type { [4 x [4 x double]] }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.60 = external hidden unnamed_addr constant [34 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

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

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

declare i32 @fclose(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK10RGBDCamera19WriteMatterportFileEPKc(ptr noundef nonnull align 8 dereferenceable(348) %0, ptr noundef %1) #3 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call noalias ptr @fopen(ptr noundef %9, ptr noundef @.str.33)
  store ptr %10, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %17, label %13

13:                                               ; preds = %2
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str.1, ptr noundef %15) #4
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %44

17:                                               ; preds = %2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 4
  %24 = load double, ptr %23, align 8, !tbaa !15
  %25 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 5
  %26 = load double, ptr %25, align 8, !tbaa !16
  %27 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 6
  %28 = load double, ptr %27, align 8, !tbaa !17
  %29 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 7
  %30 = load double, ptr %29, align 8, !tbaa !18
  %31 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 8
  %32 = load double, ptr %31, align 8, !tbaa !19
  %33 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 9
  %34 = load double, ptr %33, align 8, !tbaa !20
  %35 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 12
  %36 = load double, ptr %35, align 8, !tbaa !21
  %37 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 13
  %38 = load double, ptr %37, align 8, !tbaa !22
  %39 = getelementptr inbounds %class.RGBDCamera, ptr %8, i32 0, i32 10
  %40 = load double, ptr %39, align 8, !tbaa !23
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str.60, i32 noundef %20, i32 noundef %22, double noundef %24, double noundef %26, double noundef %28, double noundef %30, double noundef %32, double noundef %34, double noundef %36, double noundef %38, double noundef %40) #4
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i32 @fclose(ptr noundef %42)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %44

44:                                               ; preds = %17, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %45 = load i32, ptr %3, align 4
  ret i32 %45
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS10RGBDCamera", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !13, i64 176, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !11, i64 336, !11, i64 340, !11, i64 344}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"_ZTS8R4Matrix", !7, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !12, i64 16}
!16 = !{!10, !12, i64 24}
!17 = !{!10, !12, i64 32}
!18 = !{!10, !12, i64 40}
!19 = !{!10, !12, i64 48}
!20 = !{!10, !12, i64 56}
!21 = !{!10, !12, i64 80}
!22 = !{!10, !12, i64 88}
!23 = !{!10, !12, i64 64}


; 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.1 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.60 = external hidden unnamed_addr constant [34 x i8], align 1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZNK10RGBDCamera19WriteMatterportFileEPKc(ptr nocapture noundef nonnull readonly align 8 dereferenceable(348) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.33)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %7

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.1, ptr noundef %1) #2
  br label %31

7:                                                ; preds = %2
  %8 = load i32, ptr %0, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load double, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load double, ptr %13, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = load double, ptr %15, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = load double, ptr %17, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %0, i64 48
  %20 = load double, ptr %19, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %0, i64 56
  %22 = load double, ptr %21, align 8, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %0, i64 80
  %24 = load double, ptr %23, align 8, !tbaa !21
  %25 = getelementptr inbounds i8, ptr %0, i64 88
  %26 = load double, ptr %25, align 8, !tbaa !22
  %27 = getelementptr inbounds i8, ptr %0, i64 64
  %28 = load double, ptr %27, align 8, !tbaa !23
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.60, i32 noundef %8, i32 noundef %10, double noundef %12, double noundef %14, double noundef %16, double noundef %18, double noundef %20, double noundef %22, double noundef %24, double noundef %26, double noundef %28) #3
  %30 = tail call i32 @fclose(ptr noundef nonnull %3)
  br label %31

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

attributes #0 = { 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 #1 = { mustprogress nofree 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 = { cold nounwind }
attributes #3 = { 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, !11, i64 0}
!10 = !{!"_ZTS10RGBDCamera", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !13, i64 176, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !11, i64 336, !11, i64 340, !11, i64 344}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"_ZTS8R4Matrix", !7, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !12, i64 16}
!16 = !{!10, !12, i64 24}
!17 = !{!10, !12, i64 32}
!18 = !{!10, !12, i64 40}
!19 = !{!10, !12, i64 48}
!20 = !{!10, !12, i64 56}
!21 = !{!10, !12, i64 80}
!22 = !{!10, !12, i64 88}
!23 = !{!10, !12, i64 64}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass