; LLVM IR from moarseniy/CudaFEMproject :: FEMproject/thirdparty/segyio/src/SegyIn.ll (ZN7CSegyIn6getBufEPKcRKPcRKiS6_)

; 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.CSegyIO = type <{ ptr, i32, i32, i32, float, i32, [71 x i32], [27 x i32], [4 x i8], ptr, ptr, i64, %"class.std::basic_ifstream", %"class.std::basic_ofstream", %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", i8, i8, [6 x i8] }>
%"class.std::basic_ifstream" = type { %"class.std::basic_istream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_istream.base" = type { ptr, i64 }
%"class.std::basic_filebuf" = type { %"class.std::basic_streambuf", %union.pthread_mutex_t, %"class.std::__basic_file", i32, %struct.__mbstate_t, %struct.__mbstate_t, %struct.__mbstate_t, ptr, i64, i8, i8, i8, i8, ptr, ptr, i8, ptr, ptr, i64, ptr, ptr }
%"class.std::basic_streambuf" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::locale" }
%"class.std::locale" = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::__basic_file" = type <{ ptr, i8, [7 x i8] }>
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::basic_ofstream" = type { %"class.std::basic_ostream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_ostream.base" = type { ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon.0 }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon.0 = type { i64, [8 x i8] }

; 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 uwtable
define dso_local void @_ZN7CSegyIn6getBufEPKcRKPcRKiS6_(ptr noundef nonnull align 8 dereferenceable(1546) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, 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 %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %32, %5
  %14 = load i32, ptr %11, align 4, !tbaa !9
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %18, label %35

18:                                               ; preds = %13
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = add nsw i32 %21, %22
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %19, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %28, i64 %30
  store i8 %26, ptr %31, align 1, !tbaa !11
  br label %32

32:                                               ; preds = %18
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %11, align 4, !tbaa !9
  br label %13, !llvm.loop !12

35:                                               ; preds = %13
  %36 = getelementptr inbounds %class.CSegyIO, ptr %12, i32 0, i32 16
  %37 = load i8, ptr %36, align 8, !tbaa !14, !range !31, !noundef !32
  %38 = trunc i8 %37 to i1
  br i1 %38, label %43, label %39

39:                                               ; preds = %35
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN7CSegyIO10switchByteEPcRKi(ptr noundef nonnull align 8 dereferenceable(1546) %12, ptr noundef %41, ptr noundef nonnull align 4 dereferenceable(4) %42)
  br label %43

43:                                               ; preds = %39, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret void
}

declare void @_ZN7CSegyIO10switchByteEPcRKi(ptr noundef nonnull align 8 dereferenceable(1546), ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !24, i64 1544}
!15 = !{!"_ZTS7CSegyIO", !10, i64 8, !10, i64 12, !10, i64 16, !16, i64 20, !10, i64 24, !7, i64 28, !7, i64 312, !6, i64 424, !6, i64 432, !17, i64 440, !18, i64 448, !27, i64 968, !29, i64 1480, !29, i64 1512, !24, i64 1544, !24, i64 1545}
!16 = !{!"float", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSSt14basic_ifstreamIcSt11char_traitsIcEE", !19, i64 0, !20, i64 16}
!19 = !{!"_ZTSSi", !17, i64 8}
!20 = !{!"_ZTSSt13basic_filebufIcSt11char_traitsIcEE", !21, i64 0, !7, i64 64, !23, i64 104, !25, i64 120, !26, i64 124, !26, i64 132, !26, i64 140, !6, i64 152, !17, i64 160, !24, i64 168, !24, i64 169, !24, i64 170, !7, i64 171, !6, i64 176, !6, i64 184, !24, i64 192, !6, i64 200, !6, i64 208, !17, i64 216, !6, i64 224, !6, i64 232}
!21 = !{!"_ZTSSt15basic_streambufIcSt11char_traitsIcEE", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !22, i64 56}
!22 = !{!"_ZTSSt6locale", !6, i64 0}
!23 = !{!"_ZTSSt12__basic_fileIcE", !6, i64 0, !24, i64 8}
!24 = !{!"bool", !7, i64 0}
!25 = !{!"_ZTSSt13_Ios_Openmode", !7, i64 0}
!26 = !{!"_ZTS11__mbstate_t", !10, i64 0, !7, i64 4}
!27 = !{!"_ZTSSt14basic_ofstreamIcSt11char_traitsIcEE", !28, i64 0, !20, i64 8}
!28 = !{!"_ZTSSo"}
!29 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !30, i64 0, !17, i64 8, !7, i64 16}
!30 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!31 = !{i8 0, i8 2}
!32 = !{}


; 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 uwtable
define dso_local void @_ZN7CSegyIn6getBufEPKcRKPcRKiS6_(ptr noundef nonnull align 8 dereferenceable(1546) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %2, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4) local_unnamed_addr #0 align 2 {
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = trunc nuw nsw i64 %indvars.iv to i32
  %10 = add nsw i32 %8, %9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %1, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = load ptr, ptr %2, align 8, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %14, i64 %indvars.iv
  store i8 %13, ptr %15, align 1, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %5
  %19 = getelementptr inbounds i8, ptr %0, i64 1544
  %20 = load i8, ptr %19, align 8, !tbaa !14, !range !31, !noundef !32
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %24, label %22

22:                                               ; preds = %._crit_edge
  %23 = load ptr, ptr %2, align 8, !tbaa !10
  tail call void @_ZN7CSegyIO10switchByteEPcRKi(ptr noundef nonnull align 8 dereferenceable(1546) %0, ptr noundef %23, ptr noundef nonnull align 4 dereferenceable(4) %4)
  br label %24

24:                                               ; preds = %22, %._crit_edge
  ret void
}

declare void @_ZN7CSegyIO10switchByteEPcRKi(ptr noundef nonnull align 8 dereferenceable(1546), ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !24, i64 1544}
!15 = !{!"_ZTS7CSegyIO", !6, i64 8, !6, i64 12, !6, i64 16, !16, i64 20, !6, i64 24, !7, i64 28, !7, i64 312, !11, i64 424, !11, i64 432, !17, i64 440, !18, i64 448, !27, i64 968, !29, i64 1480, !29, i64 1512, !24, i64 1544, !24, i64 1545}
!16 = !{!"float", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSSt14basic_ifstreamIcSt11char_traitsIcEE", !19, i64 0, !20, i64 16}
!19 = !{!"_ZTSSi", !17, i64 8}
!20 = !{!"_ZTSSt13basic_filebufIcSt11char_traitsIcEE", !21, i64 0, !7, i64 64, !23, i64 104, !25, i64 120, !26, i64 124, !26, i64 132, !26, i64 140, !11, i64 152, !17, i64 160, !24, i64 168, !24, i64 169, !24, i64 170, !7, i64 171, !11, i64 176, !11, i64 184, !24, i64 192, !11, i64 200, !11, i64 208, !17, i64 216, !11, i64 224, !11, i64 232}
!21 = !{!"_ZTSSt15basic_streambufIcSt11char_traitsIcEE", !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !22, i64 56}
!22 = !{!"_ZTSSt6locale", !11, i64 0}
!23 = !{!"_ZTSSt12__basic_fileIcE", !11, i64 0, !24, i64 8}
!24 = !{!"bool", !7, i64 0}
!25 = !{!"_ZTSSt13_Ios_Openmode", !7, i64 0}
!26 = !{!"_ZTS11__mbstate_t", !6, i64 0, !7, i64 4}
!27 = !{!"_ZTSSt14basic_ofstreamIcSt11char_traitsIcEE", !28, i64 0, !20, i64 8}
!28 = !{!"_ZTSSo"}
!29 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !30, i64 0, !17, i64 8, !7, i64 16}
!30 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !11, i64 0}
!31 = !{i8 0, i8 2}
!32 = !{}


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