; 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 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; 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
define dso_local ptr @segy_open(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [5 x i8], align 1
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %17

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %14, %2
  store ptr null, ptr %3, align 8
  br label %87

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 5, ptr %6) #7
  call void @llvm.memset.p0.i64(ptr align 1 %6, i8 0, i64 5, i1 false)
  %19 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 0
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call ptr @strncpy(ptr noundef %19, ptr noundef %20, i64 noundef 3) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %22 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 0
  %23 = call i64 @strlen(ptr noundef %22) #8
  store i64 %23, ptr %7, align 8, !tbaa !9
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = sub i64 %24, 1
  %26 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = sext i8 %27 to i32
  %29 = icmp ne i32 %28, 98
  br i1 %29, label %30, label %33

30:                                               ; preds = %18
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 %31
  store i8 98, ptr %32, align 1, !tbaa !11
  br label %33

33:                                               ; preds = %30, %18
  %34 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 0
  %35 = call ptr @strstr(ptr noundef @.str, ptr noundef %34) #8
  %36 = icmp ne ptr %35, null
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %86

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 0
  %41 = call noalias ptr @fopen64(ptr noundef %39, ptr noundef %40)
  store ptr %41, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %45, label %44

44:                                               ; preds = %38
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %85

45:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %46 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 56) #9
  store ptr %46, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %52, label %49

49:                                               ; preds = %45
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = call i32 @fclose(ptr noundef %50)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %84

52:                                               ; preds = %45
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.segy_file_handle, ptr %54, i32 0, i32 2
  store ptr %53, ptr %55, align 8, !tbaa !12
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.segy_file_handle, ptr %56, i32 0, i32 4
  %58 = getelementptr inbounds [5 x i8], ptr %57, i64 0, i64 0
  %59 = getelementptr inbounds [5 x i8], ptr %6, i64 0, i64 0
  %60 = call ptr @strcpy(ptr noundef %58, ptr noundef %59) #7
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #7
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.segy_file_handle, ptr %61, i32 0, i32 4
  %63 = getelementptr inbounds [5 x i8], ptr %62, i64 0, i64 0
  %64 = call ptr @strstr(ptr noundef %63, ptr noundef @.str.1) #8
  %65 = icmp ne ptr %64, null
  br i1 %65, label %72, label %66

66:                                               ; preds = %52
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.segy_file_handle, ptr %67, i32 0, i32 4
  %69 = getelementptr inbounds [5 x i8], ptr %68, i64 0, i64 0
  %70 = call ptr @strstr(ptr noundef %69, ptr noundef @.str.2) #8
  %71 = icmp ne ptr %70, null
  br label %72

72:                                               ; preds = %66, %52
  %73 = phi i1 [ true, %52 ], [ %71, %66 ]
  %74 = zext i1 %73 to i8
  store i8 %74, ptr %11, align 1, !tbaa !15
  %75 = load i8, ptr %11, align 1, !tbaa !15, !range !17, !noundef !18
  %76 = trunc i8 %75 to i1
  br i1 %76, label %77, label %80

77:                                               ; preds = %72
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.segy_file_handle, ptr %78, i32 0, i32 5
  store i32 1, ptr %79, align 8, !tbaa !19
  br label %80

80:                                               ; preds = %77, %72
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.segy_file_handle, ptr %81, i32 0, i32 6
  store i32 4, ptr %82, align 4, !tbaa !20
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %83, ptr %3, align 8
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #7
  br label %84

84:                                               ; preds = %80, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %85

85:                                               ; preds = %84, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  br label %86

86:                                               ; preds = %85, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 5, ptr %6) #7
  br label %87

87:                                               ; preds = %86, %17
  %88 = load ptr, ptr %3, align 8
  ret ptr %88
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #1

declare noalias ptr @fopen64(ptr noundef, ptr noundef) #5

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #6

declare i32 @fclose(ptr noundef) #5

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { "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 #6 = { nounwind allocsize(0,1) "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind allocsize(0,1) }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"segy_file_handle", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !7, i64 32, !14, i64 40, !14, i64 44, !14, i64 48}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!13, !14, i64 40}
!20 = !{!13, !14, i64 44}


; 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 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind uwtable
define dso_local noundef ptr @segy_open(ptr noundef readonly %0, ptr noundef readonly %1) local_unnamed_addr #2 {
  %3 = alloca [5 x i8], align 1
  %4 = icmp ne ptr %0, null
  %5 = icmp ne ptr %1, null
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %6, label %34

6:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %3) #6
  %7 = getelementptr inbounds i8, ptr %3, i64 3
  store i16 0, ptr %7, align 1
  %8 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) %1, i64 noundef 3) #6
  %9 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #7
  %10 = add i64 %9, -1
  %11 = getelementptr inbounds [5 x i8], ptr %3, i64 0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not = icmp eq i8 %12, 98
  br i1 %.not, label %15, label %13

13:                                               ; preds = %6
  %14 = getelementptr inbounds [5 x i8], ptr %3, i64 0, i64 %9
  store i8 98, ptr %14, align 1, !tbaa !5
  br label %15

15:                                               ; preds = %13, %6
  %16 = call ptr @strstr(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull dereferenceable(1) %3) #7
  %.not23 = icmp eq ptr %16, null
  br i1 %.not23, label %33, label %17

17:                                               ; preds = %15
  %18 = call noalias ptr @fopen64(ptr noundef nonnull %0, ptr noundef nonnull %3)
  %.not24 = icmp eq ptr %18, null
  br i1 %.not24, label %33, label %19

19:                                               ; preds = %17
  %20 = call noalias dereferenceable_or_null(56) ptr @calloc(i64 noundef 1, i64 noundef 56) #8
  %.not25 = icmp eq ptr %20, null
  br i1 %.not25, label %21, label %23

21:                                               ; preds = %19
  %22 = call i32 @fclose(ptr noundef nonnull %18)
  br label %33

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %20, i64 16
  store ptr %18, ptr %24, align 8, !tbaa !8
  %25 = getelementptr inbounds i8, ptr %20, i64 32
  %26 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %25, ptr noundef nonnull dereferenceable(1) %3) #6
  %27 = call ptr @strstr(ptr noundef nonnull dereferenceable(1) %25, ptr noundef nonnull dereferenceable(1) @.str.1) #7
  %.not26 = icmp eq ptr %27, null
  br i1 %.not26, label %28, label %.critedge

28:                                               ; preds = %23
  %29 = call ptr @strstr(ptr noundef nonnull dereferenceable(1) %25, ptr noundef nonnull dereferenceable(1) @.str.2) #7
  %.not27 = icmp eq ptr %29, null
  br i1 %.not27, label %31, label %.critedge

.critedge:                                        ; preds = %23, %28
  %30 = getelementptr inbounds i8, ptr %20, i64 40
  store i32 1, ptr %30, align 8, !tbaa !13
  br label %31

31:                                               ; preds = %.critedge, %28
  %32 = getelementptr inbounds i8, ptr %20, i64 44
  store i32 4, ptr %32, align 4, !tbaa !14
  br label %33

33:                                               ; preds = %17, %31, %21, %15
  %.2 = phi ptr [ null, %15 ], [ null, %17 ], [ %20, %31 ], [ null, %21 ]
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %3) #6
  br label %34

34:                                               ; preds = %2, %33
  %.3 = phi ptr [ %.2, %33 ], [ null, %2 ]
  ret ptr %.3
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen64(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nofree 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { 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 #5 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { nounwind allocsize(0,1) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 16}
!9 = !{!"segy_file_handle", !10, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !12, i64 48}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"long", !6, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!9, !12, i64 40}
!14 = !{!9, !12, i64 44}


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