; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

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

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

20:                                               ; preds = %5
  store i32 13, ptr %6, align 4
  br label %63

21:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !11
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = call i32 @segy_seek(ptr noundef %22, i32 noundef %23, i64 noundef %24, i32 noundef %25)
  store i32 %26, ptr %12, align 4, !tbaa !9
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %21
  %30 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %30, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %62

31:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 240, ptr %14) #4
  %32 = getelementptr inbounds [240 x i8], ptr %14, i64 0, i64 0
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %32, ptr align 1 %33, i64 240, i1 false)
  %34 = getelementptr inbounds [240 x i8], ptr %14, i64 0, i64 0
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.segy_file_handle, ptr %35, i32 0, i32 7
  %37 = load i32, ptr %36, align 8, !tbaa !15
  %38 = call i32 @bswap_th(ptr noundef %34, i32 noundef %37)
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.segy_file_handle, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %50

43:                                               ; preds = %31
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.segy_file_handle, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  %48 = getelementptr inbounds [240 x i8], ptr %14, i64 0, i64 0
  %49 = call i32 @memwrite(ptr noundef %44, ptr noundef %47, ptr noundef %48, i64 noundef 240)
  store i32 %49, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %61

50:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %51 = getelementptr inbounds [240 x i8], ptr %14, i64 0, i64 0
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.segy_file_handle, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  %55 = call i64 @fwrite(ptr noundef %51, i64 noundef 1, i64 noundef 240, ptr noundef %54)
  store i64 %55, ptr %15, align 8, !tbaa !11
  %56 = load i64, ptr %15, align 8, !tbaa !11
  %57 = icmp ne i64 %56, 240
  br i1 %57, label %58, label %59

58:                                               ; preds = %50
  store i32 4, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %60

59:                                               ; preds = %50
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %60

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

61:                                               ; preds = %60, %43
  call void @llvm.lifetime.end.p0(i64 240, ptr %14) #4
  br label %62

62:                                               ; preds = %61, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %63

63:                                               ; preds = %62, %20
  %64 = load i32, ptr %6, align 4
  ret i32 %64
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 #4 = { 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 = !{!14, !10, i64 48}
!16 = !{!14, !6, i64 0}
!17 = !{!14, !6, i64 8}
!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"

; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local i32 @segy_write_traceheader(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca [240 x i8], align 16
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %25, label %9

9:                                                ; preds = %5
  %10 = tail call i32 @segy_seek(ptr noundef nonnull %0, i32 noundef %1, i64 noundef %3, i32 noundef %4)
  %.not15 = icmp eq i32 %10, 0
  br i1 %.not15, label %11, label %25

11:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 240, ptr nonnull %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(240) %6, ptr noundef nonnull align 1 dereferenceable(240) %2, i64 240, i1 false)
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load i32, ptr %12, align 8, !tbaa !12
  %14 = call i32 @bswap_th(ptr noundef nonnull %6, i32 noundef %13)
  %15 = load ptr, ptr %0, align 8, !tbaa !13
  %.not16 = icmp eq ptr %15, null
  br i1 %.not16, label %20, label %16

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = call i32 @memwrite(ptr noundef nonnull %0, ptr noundef %18, ptr noundef nonnull %6, i64 noundef 240)
  br label %24

20:                                               ; preds = %11
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = call i64 @fwrite(ptr noundef nonnull %6, i64 noundef 1, i64 noundef 240, ptr noundef %22)
  %.not17 = icmp eq i64 %23, 240
  %. = select i1 %.not17, i32 0, i32 4
  br label %24

24:                                               ; preds = %20, %16
  %.1 = phi i32 [ %19, %16 ], [ %., %20 ]
  call void @llvm.lifetime.end.p0(i64 240, ptr nonnull %6) #4
  br label %25

25:                                               ; preds = %24, %9, %5
  %.3 = phi i32 [ 13, %5 ], [ %.1, %24 ], [ %10, %9 ]
  ret i32 %.3
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nofree 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 #4 = { 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, !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 = !{!6, !11, i64 48}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass