; LLVM IR from moarseniy/CudaFEMproject :: FEMproject/thirdparty/segyio2/src (segy)

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

@field_size = external hidden global [238 x i32], align 16

; 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: nounwind uwtable
declare dso_local i32 @segy_get_field(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @segy_traceheader(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @segy_offset_indices(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca [240 x i8], align 16
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i64 %4, ptr %12, align 8, !tbaa !11
  store i32 %5, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 240, ptr %15) #2
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [238 x i32], ptr @field_size, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %6
  store i32 5, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %58

25:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %52, %25
  %27 = load i32, ptr %17, align 4, !tbaa !9
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 2, ptr %16, align 4
  br label %55

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #2
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %17, align 4, !tbaa !9
  %34 = getelementptr inbounds [240 x i8], ptr %15, i64 0, i64 0
  %35 = load i64, ptr %12, align 8, !tbaa !11
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = call i32 @segy_traceheader(ptr noundef %32, i32 noundef %33, ptr noundef %34, i64 noundef %35, i32 noundef %36)
  store i32 %37, ptr %18, align 4, !tbaa !9
  %38 = load i32, ptr %18, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %31
  %41 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %41, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %49

42:                                               ; preds = %31
  %43 = getelementptr inbounds [240 x i8], ptr %15, i64 0, i64 0
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = call i32 @segy_get_field(ptr noundef %43, i32 noundef %44, ptr noundef %14)
  %46 = load i32, ptr %14, align 4, !tbaa !9
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds i32, ptr %47, i32 1
  store ptr %48, ptr %11, align 8, !tbaa !5
  store i32 %46, ptr %47, align 4, !tbaa !9
  store i32 0, ptr %16, align 4
  br label %49

49:                                               ; preds = %42, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #2
  %50 = load i32, ptr %16, align 4
  switch i32 %50, label %55 [
    i32 0, label %51
  ]

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %17, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %17, align 4, !tbaa !9
  br label %26, !llvm.loop !13

55:                                               ; preds = %49, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  %56 = load i32, ptr %16, align 4
  switch i32 %56, label %58 [
    i32 2, label %57
  ]

57:                                               ; preds = %55
  store i32 0, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %58

58:                                               ; preds = %57, %55, %24
  call void @llvm.lifetime.end.p0(i64 240, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  %59 = load i32, ptr %7, align 4
  ret i32 %59
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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"

@field_size = external hidden local_unnamed_addr global [238 x i32], align 16

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @segy_get_field(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @segy_traceheader(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @segy_offset_indices(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3, i64 noundef %4, i32 noundef %5) local_unnamed_addr #1 {
  %7 = alloca i32, align 4
  %8 = alloca [240 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 240, ptr nonnull %8) #2
  %9 = sext i32 %1 to i64
  %10 = getelementptr inbounds [238 x i32], ptr @field_size, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %6
  %.not2126 = icmp sgt i32 %2, 0
  br i1 %.not2126, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %14
  %.01528 = phi i32 [ %18, %14 ], [ 0, %.preheader ]
  %.01827 = phi ptr [ %17, %14 ], [ %3, %.preheader ]
  %13 = call i32 @segy_traceheader(ptr noundef %0, i32 noundef %.01528, ptr noundef nonnull %8, i64 noundef %4, i32 noundef %5)
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %14, label %.loopexit

14:                                               ; preds = %.lr.ph
  %15 = call i32 @segy_get_field(ptr noundef nonnull %8, i32 noundef %1, ptr noundef nonnull %7)
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.01827, i64 4
  store i32 %16, ptr %.01827, align 4, !tbaa !5
  %18 = add nuw nsw i32 %.01528, 1
  %exitcond.not = icmp eq i32 %18, %2
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %14, %.preheader, %6
  %.3 = phi i32 [ 5, %6 ], [ 0, %.preheader ], [ %13, %.lr.ph ], [ 0, %14 ]
  call void @llvm.lifetime.end.p0(i64 240, ptr nonnull %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #2
  ret i32 %.3
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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