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

; 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 hidden void @native_ibm(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @formatsize(i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @segy_from_native(i32 noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = call i32 @formatsize(i32 noundef %12)
  store i32 %13, ptr %8, align 4, !tbaa !5
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  store i32 10, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %43

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %18 = load ptr, ptr %7, align 8, !tbaa !11
  store ptr %18, ptr %10, align 8, !tbaa !11
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %38

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %34, %21
  %23 = load i64, ptr %11, align 8, !tbaa !9
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp slt i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %37

27:                                               ; preds = %22
  %28 = load ptr, ptr %10, align 8, !tbaa !11
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = mul nsw i64 %29, %31
  %33 = getelementptr inbounds i8, ptr %28, i64 %32
  call void @native_ibm(ptr noundef %33)
  br label %34

34:                                               ; preds = %27
  %35 = load i64, ptr %11, align 8, !tbaa !9
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %11, align 8, !tbaa !9
  br label %22, !llvm.loop !13

37:                                               ; preds = %26
  br label %38

38:                                               ; preds = %37, %17
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !11
  %42 = call i32 @segy_native_byteswap(i32 noundef %39, i64 noundef %40, ptr noundef %41)
  store i32 %42, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %43

43:                                               ; preds = %38, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %44 = load i32, ptr %4, align 4
  ret i32 %44
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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"

; Function Attrs: nounwind uwtable
declare hidden void @native_ibm(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @formatsize(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @segy_native_byteswap(i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @segy_from_native(i32 noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @formatsize(i32 noundef %0)
  %5 = icmp slt i32 %4, 0
  br i1 %5, label %15, label %6

6:                                                ; preds = %3
  %7 = icmp eq i32 %0, 1
  %8 = icmp sgt i64 %1, 0
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %6
  %9 = zext nneg i32 %4 to i64
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %.015 = phi i64 [ 0, %.lr.ph ], [ %13, %10 ]
  %11 = mul nuw nsw i64 %.015, %9
  %12 = getelementptr inbounds i8, ptr %2, i64 %11
  tail call void @native_ibm(ptr noundef %12)
  %13 = add nuw nsw i64 %.015, 1
  %exitcond.not = icmp eq i64 %13, %1
  br i1 %exitcond.not, label %.loopexit, label %10, !llvm.loop !5

.loopexit:                                        ; preds = %10, %6
  %14 = tail call i32 @segy_native_byteswap(i32 noundef %0, i64 noundef %1, ptr noundef %2)
  br label %15

15:                                               ; preds = %3, %.loopexit
  %.013 = phi i32 [ %14, %.loopexit ], [ 10, %3 ]
  ret i32 %.013
}

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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