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

%struct.segy_file_handle = type { ptr, ptr, ptr, i64, [5 x i8], i32, i32, i32 }

@.str.4 = external hidden unnamed_addr constant [99 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [41 x i8], align 1
@__PRETTY_FUNCTION__.segy_traces = external hidden unnamed_addr constant [47 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @segy_traces(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  %13 = load i64, ptr %8, align 8, !tbaa !9
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  store i32 10, ptr %5, align 4
  br label %71

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.segy_file_handle, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %25

21:                                               ; preds = %16
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.segy_file_handle, ptr %22, i32 0, i32 3
  %24 = load i64, ptr %23, align 8, !tbaa !15
  store i64 %24, ptr %10, align 8, !tbaa !16
  br label %38

25:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.segy_file_handle, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = call i32 @file_size(ptr noundef %28, ptr noundef %10)
  store i32 %29, ptr %11, align 4, !tbaa !11
  %30 = load i32, ptr %11, align 4, !tbaa !11
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %25
  %33 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %33, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %35

34:                                               ; preds = %25
  store i32 0, ptr %12, align 4
  br label %35

35:                                               ; preds = %34, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %36 = load i32, ptr %12, align 4
  switch i32 %36, label %70 [
    i32 0, label %37
  ]

37:                                               ; preds = %35
  br label %38

38:                                               ; preds = %37, %21
  %39 = load i64, ptr %8, align 8, !tbaa !9
  %40 = load i64, ptr %10, align 8, !tbaa !16
  %41 = icmp sgt i64 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %38
  store i32 10, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

43:                                               ; preds = %38
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = load i64, ptr %10, align 8, !tbaa !16
  %46 = sub nsw i64 %45, %44
  store i64 %46, ptr %10, align 8, !tbaa !16
  %47 = load i32, ptr %9, align 4, !tbaa !11
  %48 = add nsw i32 %47, 240
  store i32 %48, ptr %9, align 4, !tbaa !11
  %49 = load i64, ptr %10, align 8, !tbaa !16
  %50 = load i32, ptr %9, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = srem i64 %49, %51
  %53 = icmp ne i64 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %43
  store i32 9, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

55:                                               ; preds = %43
  %56 = load i64, ptr %10, align 8, !tbaa !16
  %57 = load i32, ptr %9, align 4, !tbaa !11
  %58 = sext i32 %57 to i64
  %59 = sdiv i64 %56, %58
  %60 = icmp sle i64 %59, 2147483647
  br i1 %60, label %61, label %62

61:                                               ; preds = %55
  br label %63

62:                                               ; preds = %55
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.4, i32 noundef 1197, ptr noundef @__PRETTY_FUNCTION__.segy_traces) #4
  unreachable

63:                                               ; preds = %61
  %64 = load i64, ptr %10, align 8, !tbaa !16
  %65 = load i32, ptr %9, align 4, !tbaa !11
  %66 = sext i32 %65 to i64
  %67 = sdiv i64 %64, %66
  %68 = trunc i64 %67 to i32
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %68, ptr %69, align 4, !tbaa !11
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

70:                                               ; preds = %63, %54, %42, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %71

71:                                               ; preds = %70, %15
  %72 = load i32, ptr %5, align 4
  ret i32 %72
}

; Function Attrs: nounwind uwtable
declare hidden i32 @file_size(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { 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 #3 = { nounwind }
attributes #4 = { noreturn 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"segy_file_handle", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !7, i64 32, !12, i64 40, !12, i64 44, !12, i64 48}
!15 = !{!14, !10, i64 24}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!14, !6, i64 16}


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

@.str.4 = external hidden unnamed_addr constant [99 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [41 x i8], align 1
@__PRETTY_FUNCTION__.segy_traces = external hidden unnamed_addr constant [47 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @segy_traces(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca i64, align 8
  %6 = icmp slt i64 %2, 0
  br i1 %6, label %29, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %11, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  br label %._crit_edge

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = call i32 @file_size(ptr noundef %13, ptr noundef nonnull %5)
  %.not18 = icmp eq i32 %14, 0
  br i1 %.not18, label %._crit_edge, label %28

._crit_edge:                                      ; preds = %11, %9
  %.in = phi ptr [ %10, %9 ], [ %5, %11 ]
  %15 = load i64, ptr %.in, align 8, !tbaa !13
  %16 = icmp slt i64 %15, %2
  br i1 %16, label %28, label %17

17:                                               ; preds = %._crit_edge
  %18 = sub nsw i64 %15, %2
  store i64 %18, ptr %5, align 8, !tbaa !14
  %19 = add nsw i32 %3, 240
  %20 = sext i32 %19 to i64
  %21 = srem i64 %18, %20
  %22 = sdiv i64 %18, %20
  %.not19 = icmp eq i64 %21, 0
  br i1 %.not19, label %23, label %28

23:                                               ; preds = %17
  %24 = icmp slt i64 %22, 2147483648
  br i1 %24, label %26, label %25

25:                                               ; preds = %23
  call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.4, i32 noundef 1197, ptr noundef nonnull @__PRETTY_FUNCTION__.segy_traces) #4
  unreachable

26:                                               ; preds = %23
  %27 = trunc i64 %22 to i32
  store i32 %27, ptr %1, align 4, !tbaa !16
  br label %28

28:                                               ; preds = %17, %._crit_edge, %11, %26
  %.1 = phi i32 [ 0, %26 ], [ %14, %11 ], [ 10, %._crit_edge ], [ 9, %17 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %29

29:                                               ; preds = %4, %28
  %.2 = phi i32 [ %.1, %28 ], [ 10, %4 ]
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare hidden i32 @file_size(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { 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 #3 = { nounwind }
attributes #4 = { noreturn 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, !7, i64 0}
!6 = !{!"segy_file_handle", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !8, i64 32, !11, i64 40, !11, i64 44, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 16}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long long", !8, i64 0}
!16 = !{!11, !11, i64 0}


; Effective O3 passes: DSEPass,DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass