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

; 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_writetrace(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @segy_write_line(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, i64 noundef %6, i32 noundef %7) #1 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store i32 %1, ptr %11, align 4, !tbaa !9
  store i32 %2, ptr %12, align 4, !tbaa !9
  store i32 %3, ptr %13, align 4, !tbaa !9
  store i32 %4, ptr %14, align 4, !tbaa !9
  store ptr %5, ptr %15, align 8, !tbaa !5
  store i64 %6, ptr %16, align 8, !tbaa !11
  store i32 %7, ptr %17, align 4, !tbaa !9
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.segy_file_handle, ptr %21, i32 0, i32 5
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %8
  store i32 13, ptr %9, align 4
  br label %60

26:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #2
  %27 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %27, ptr %18, align 8, !tbaa !5
  %28 = load i32, ptr %14, align 4, !tbaa !9
  %29 = load i32, ptr %13, align 4, !tbaa !9
  %30 = mul nsw i32 %29, %28
  store i32 %30, ptr %13, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %50, %26
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = add nsw i32 %32, -1
  store i32 %33, ptr %12, align 4, !tbaa !9
  %34 = icmp ne i32 %32, 0
  br i1 %34, label %35, label %58

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #2
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = load ptr, ptr %18, align 8, !tbaa !5
  %39 = load i64, ptr %16, align 8, !tbaa !11
  %40 = load i32, ptr %17, align 4, !tbaa !9
  %41 = call i32 @segy_writetrace(ptr noundef %36, i32 noundef %37, ptr noundef %38, i64 noundef %39, i32 noundef %40)
  store i32 %41, ptr %19, align 4, !tbaa !9
  %42 = load i32, ptr %19, align 4, !tbaa !9
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %35
  %45 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %45, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %47

46:                                               ; preds = %35
  store i32 0, ptr %20, align 4
  br label %47

47:                                               ; preds = %46, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #2
  %48 = load i32, ptr %20, align 4
  switch i32 %48, label %59 [
    i32 0, label %49
  ]

49:                                               ; preds = %47
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = add nsw i32 %52, %51
  store i32 %53, ptr %11, align 4, !tbaa !9
  %54 = load i32, ptr %17, align 4, !tbaa !9
  %55 = load ptr, ptr %18, align 8, !tbaa !5
  %56 = sext i32 %54 to i64
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  store ptr %57, ptr %18, align 8, !tbaa !5
  br label %31, !llvm.loop !15

58:                                               ; preds = %31
  store i32 0, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %59

59:                                               ; preds = %58, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  br label %60

60:                                               ; preds = %59, %25
  %61 = load i32, ptr %9, align 4
  ret i32 %61
}

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 = !{!14, !10, i64 40}
!14 = !{!"segy_file_handle", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !10, i64 48}
!15 = distinct !{!15, !16}
!16 = !{!"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 dso_local i32 @segy_writetrace(ptr noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @segy_write_line(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, i64 noundef %6, i32 noundef %7) local_unnamed_addr #0 {
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %.loopexit, label %11

11:                                               ; preds = %8
  %12 = mul nsw i32 %4, %3
  %.not2224 = icmp eq i32 %2, 0
  br i1 %.not2224, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %13 = sext i32 %7 to i64
  br label %14

14:                                               ; preds = %.lr.ph, %16
  %.in = phi i32 [ %2, %.lr.ph ], [ %17, %16 ]
  %.01826 = phi ptr [ %5, %.lr.ph ], [ %19, %16 ]
  %.01925 = phi i32 [ %1, %.lr.ph ], [ %18, %16 ]
  %15 = tail call i32 @segy_writetrace(ptr noundef %0, i32 noundef %.01925, ptr noundef %.01826, i64 noundef %6, i32 noundef %7)
  %.not23 = icmp eq i32 %15, 0
  br i1 %.not23, label %16, label %.loopexit

16:                                               ; preds = %14
  %17 = add nsw i32 %.in, -1
  %18 = add nsw i32 %.01925, %12
  %19 = getelementptr inbounds i8, ptr %.01826, i64 %13
  %.not22 = icmp eq i32 %17, 0
  br i1 %.not22, label %.loopexit, label %14, !llvm.loop !12

.loopexit:                                        ; preds = %16, %14, %11, %8
  %.3 = phi i32 [ 13, %8 ], [ 0, %11 ], [ 0, %16 ], [ %15, %14 ]
  ret i32 %.3
}

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 = !{!6, !11, i64 40}
!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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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