; LLVM IR from kajott/GIPS :: src/gips_core.ll (ZNK4GIPS8Pipeline12detectFormatEv)

; 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.GIPS::Pipeline" = type <{ %"class.std::vector.3", i32, i32, i32, [2 x i32], %"class.GLutil::FBO", i8, [3 x i8], %"class.GLutil::Shader", i32, i8, i8, [2 x i8], float, [4 x i8] }>
%"class.std::vector.3" = type { %"struct.std::_Vector_base.4" }
%"struct.std::_Vector_base.4" = type { %"struct.std::_Vector_base<GIPS::Node *, std::allocator<GIPS::Node *>>::_Vector_impl" }
%"struct.std::_Vector_base<GIPS::Node *, std::allocator<GIPS::Node *>>::_Vector_impl" = type { %"struct.std::_Vector_base<GIPS::Node *, std::allocator<GIPS::Node *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<GIPS::Node *, std::allocator<GIPS::Node *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.GLutil::FBO" = type { i32, i32 }
%"class.GLutil::Shader" = type <{ i32, i32, i32, [4 x i8], ptr, i8, [7 x i8] }>
%"class.GIPS::Node" = type <{ %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", i32, [4 x i8], [4 x %"struct.GIPS::Node::PassData"], %"class.std::vector", i8, i8, i8, [5 x i8], %"class.FileUtil::FileFingerprint", i32, [4 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"struct.GIPS::Node::PassData" = type { i8, i32, %"class.GLutil::Program", i32, i32, i32, [4 x i8] }
%"class.GLutil::Program" = type <{ i32, i32, ptr, i8, [7 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<GIPS::Parameter, std::allocator<GIPS::Parameter>>::_Vector_impl" }
%"struct.std::_Vector_base<GIPS::Parameter, std::allocator<GIPS::Parameter>>::_Vector_impl" = type { %"struct.std::_Vector_base<GIPS::Parameter, std::allocator<GIPS::Parameter>>::_Vector_impl_data" }
%"struct.std::_Vector_base<GIPS::Parameter, std::allocator<GIPS::Parameter>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.FileUtil::FileFingerprint" = type { i64, i64 }

; 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK4GIPS8Pipeline12detectFormatEv(ptr noundef nonnull align 8 dereferenceable(100) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 8, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i64 0, ptr %4, align 8, !tbaa !11
  br label %6

6:                                                ; preds = %29, %1
  %7 = load i64, ptr %4, align 8, !tbaa !11
  %8 = getelementptr inbounds %"class.GIPS::Pipeline", ptr %5, i32 0, i32 0
  %9 = call noundef i64 @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %8) #2
  %10 = icmp ult i64 %7, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %6
  %13 = getelementptr inbounds %"class.GIPS::Pipeline", ptr %5, i32 0, i32 0
  %14 = load i64, ptr %4, align 8, !tbaa !11
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %13, i64 noundef %14) #2
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds %"class.GIPS::Node", ptr %16, i32 0, i32 12
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = load i32, ptr %3, align 4, !tbaa !9
  %20 = icmp sgt i32 %18, %19
  br i1 %20, label %21, label %28

21:                                               ; preds = %12
  %22 = getelementptr inbounds %"class.GIPS::Pipeline", ptr %5, i32 0, i32 0
  %23 = load i64, ptr %4, align 8, !tbaa !11
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %22, i64 noundef %23) #2
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.GIPS::Node", ptr %25, i32 0, i32 12
  %27 = load i32, ptr %26, align 8, !tbaa !13
  store i32 %27, ptr %3, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %21, %12
  br label %29

29:                                               ; preds = %28
  %30 = load i64, ptr %4, align 8, !tbaa !11
  %31 = add i64 %30, 1
  store i64 %31, ptr %4, align 8, !tbaa !11
  br label %6, !llvm.loop !24

32:                                               ; preds = %11
  %33 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %33
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"_ZTSN4GIPS11PixelFormatE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 344}
!14 = !{!"_ZTSN4GIPS4NodeE", !15, i64 0, !15, i64 32, !15, i64 64, !17, i64 96, !7, i64 104, !18, i64 296, !22, i64 320, !22, i64 321, !22, i64 322, !23, i64 328, !10, i64 344}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !12, i64 8, !7, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!"_ZTSSt6vectorIN4GIPS9ParameterESaIS1_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIN4GIPS9ParameterESaIS1_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIN4GIPS9ParameterESaIS1_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIN4GIPS9ParameterESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!"bool", !7, i64 0}
!23 = !{!"_ZTSN8FileUtil15FileFingerprintE", !12, i64 0, !12, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK4GIPS8Pipeline12detectFormatEv(ptr noundef nonnull align 8 dereferenceable(100) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call noundef i64 @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %13, %1
  %.06.lcssa = phi i32 [ 8, %1 ], [ %.1, %13 ]
  ret i32 %.06.lcssa

.lr.ph:                                           ; preds = %1, %13
  %.08 = phi i64 [ %14, %13 ], [ 0, %1 ]
  %.067 = phi i32 [ %.1, %13 ], [ 8, %1 ]
  %3 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.08) #1
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 344
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp sgt i32 %6, %.067
  br i1 %7, label %8, label %13

8:                                                ; preds = %.lr.ph
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.08) #1
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 344
  %12 = load i32, ptr %11, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %.lr.ph, %8
  %.1 = phi i32 [ %12, %8 ], [ %.067, %.lr.ph ]
  %14 = add nuw i64 %.08, 1
  %15 = tail call noundef i64 @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !22
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIPN4GIPS4NodeESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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 = { 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, !21, i64 344}
!10 = !{!"_ZTSN4GIPS4NodeE", !11, i64 0, !11, i64 32, !11, i64 64, !14, i64 96, !7, i64 104, !15, i64 296, !19, i64 320, !19, i64 321, !19, i64 322, !20, i64 328, !21, i64 344}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !13, i64 8, !7, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTSSt6vectorIN4GIPS9ParameterESaIS1_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIN4GIPS9ParameterESaIS1_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIN4GIPS9ParameterESaIS1_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIN4GIPS9ParameterESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"_ZTSN8FileUtil15FileFingerprintE", !13, i64 0, !13, i64 8}
!21 = !{!"_ZTSN4GIPS11PixelFormatE", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass