; LLVM IR from jovanlanik/wip :: src (wip_mdl)

; 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.msh_ply_file = type { i32, i32, i32, ptr, ptr, ptr, i32, i32, i32 }

@.str.14 = external hidden unnamed_addr constant [3 x i8], align 1
@__func__.msh_ply_open = external hidden unnamed_addr constant [13 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

declare ptr @_wip_alloc(i64 noundef, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @msh_ply_open(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 0
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 %14, 114
  br i1 %15, label %16, label %23

16:                                               ; preds = %2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = icmp ne i32 %20, 119
  br i1 %21, label %22, label %23

22:                                               ; preds = %16
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %94

23:                                               ; preds = %16, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 114
  br i1 %28, label %29, label %30

29:                                               ; preds = %23
  store ptr @.str.14, ptr %8, align 8, !tbaa !5
  br label %32

30:                                               ; preds = %23
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %31, ptr %8, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %30, %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = call noalias ptr @fopen(ptr noundef %33, ptr noundef %34)
  store ptr %35, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %65

38:                                               ; preds = %32
  %39 = call ptr @_wip_alloc(i64 noundef 56, ptr noundef @__func__.msh_ply_open)
  store ptr %39, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.msh_ply_file, ptr %40, i32 0, i32 0
  store i32 0, ptr %41, align 8, !tbaa !10
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.msh_ply_file, ptr %42, i32 0, i32 1
  store i32 -1, ptr %43, align 4, !tbaa !13
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.msh_ply_file, ptr %44, i32 0, i32 2
  store i32 0, ptr %45, align 8, !tbaa !14
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.msh_ply_file, ptr %46, i32 0, i32 3
  store ptr null, ptr %47, align 8, !tbaa !15
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.msh_ply_file, ptr %48, i32 0, i32 4
  store ptr null, ptr %49, align 8, !tbaa !16
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.msh_ply_file, ptr %51, i32 0, i32 5
  store ptr %50, ptr %52, align 8, !tbaa !17
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.msh_ply_file, ptr %53, i32 0, i32 8
  store i32 0, ptr %54, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 1, ptr %10, align 4, !tbaa !19
  %55 = load i8, ptr %10, align 4, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = icmp eq i32 %56, 1
  br i1 %57, label %58, label %61

58:                                               ; preds = %38
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.msh_ply_file, ptr %59, i32 0, i32 7
  store i32 1, ptr %60, align 4, !tbaa !20
  br label %64

61:                                               ; preds = %38
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.msh_ply_file, ptr %62, i32 0, i32 7
  store i32 2, ptr %63, align 4, !tbaa !20
  br label %64

64:                                               ; preds = %61, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %65

65:                                               ; preds = %64, %32
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 0
  %68 = load i8, ptr %67, align 1, !tbaa !9
  %69 = sext i8 %68 to i32
  %70 = icmp eq i32 %69, 119
  br i1 %70, label %71, label %92

71:                                               ; preds = %65
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.msh_ply_file, ptr %72, i32 0, i32 2
  store i32 1, ptr %73, align 8, !tbaa !14
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.msh_ply_file, ptr %74, i32 0, i32 1
  store i32 0, ptr %75, align 4, !tbaa !13
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = call i64 @strlen(ptr noundef %76) #5
  %78 = icmp ugt i64 %77, 1
  br i1 %78, label %79, label %91

79:                                               ; preds = %71
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 1
  %82 = load i8, ptr %81, align 1, !tbaa !9
  %83 = sext i8 %82 to i32
  %84 = icmp eq i32 %83, 98
  br i1 %84, label %85, label %91

85:                                               ; preds = %79
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.msh_ply_file, ptr %86, i32 0, i32 7
  %88 = load i32, ptr %87, align 4, !tbaa !20
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.msh_ply_file, ptr %89, i32 0, i32 1
  store i32 %88, ptr %90, align 4, !tbaa !13
  br label %91

91:                                               ; preds = %85, %79, %71
  br label %92

92:                                               ; preds = %91, %65
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %93, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %94

94:                                               ; preds = %92, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %95 = load ptr, ptr %3, align 8
  ret ptr %95
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #2 = { 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"msh_ply_file", !12, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !12, i64 48}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !12, i64 4}
!14 = !{!11, !12, i64 8}
!15 = !{!11, !6, i64 16}
!16 = !{!11, !6, i64 24}
!17 = !{!11, !6, i64 32}
!18 = !{!11, !12, i64 48}
!19 = !{!12, !12, i64 0}
!20 = !{!11, !12, 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.14 = external hidden unnamed_addr constant [3 x i8], align 1
@__func__.msh_ply_open = external hidden unnamed_addr constant [13 x i8], align 1

declare ptr @_wip_alloc(i64 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @msh_ply_open(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = load i8, ptr %1, align 1, !tbaa !5
  switch i8 %3, label %30 [
    i8 114, label %4
    i8 119, label %4
  ]

4:                                                ; preds = %2, %2
  %5 = icmp eq i8 %3, 114
  %.str.14. = select i1 %5, ptr @.str.14, ptr %1
  %6 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull %.str.14.)
  %.not31 = icmp eq ptr %6, null
  br i1 %.not31, label %15, label %7

7:                                                ; preds = %4
  %8 = tail call ptr @_wip_alloc(i64 noundef 56, ptr noundef nonnull @__func__.msh_ply_open) #5
  store i32 0, ptr %8, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 -1, ptr %9, align 4, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  store i32 0, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %8, i64 16
  %12 = getelementptr inbounds i8, ptr %8, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  store ptr %6, ptr %12, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %8, i64 48
  store i32 0, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %8, i64 44
  store i32 1, ptr %14, align 4, !tbaa !16
  br label %15

15:                                               ; preds = %7, %4
  %.026 = phi ptr [ %8, %7 ], [ null, %4 ]
  %16 = load i8, ptr %1, align 1, !tbaa !5
  %17 = icmp eq i8 %16, 119
  br i1 %17, label %18, label %30

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %.026, i64 8
  store i32 1, ptr %19, align 8, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %.026, i64 4
  store i32 0, ptr %20, align 4, !tbaa !12
  %21 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  %22 = icmp ugt i64 %21, 1
  br i1 %22, label %23, label %30

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %1, i64 1
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = icmp eq i8 %25, 98
  br i1 %26, label %27, label %30

27:                                               ; preds = %23
  %28 = getelementptr inbounds i8, ptr %.026, i64 44
  %29 = load i32, ptr %28, align 4, !tbaa !16
  store i32 %29, ptr %20, align 4, !tbaa !12
  br label %30

30:                                               ; preds = %15, %27, %23, %18, %2
  %.0 = phi ptr [ null, %2 ], [ %.026, %18 ], [ %.026, %23 ], [ %.026, %27 ], [ %.026, %15 ]
  ret ptr %.0
}

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

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

attributes #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 #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 0}
!9 = !{!"msh_ply_file", !10, i64 0, !10, i64 4, !10, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40, !10, i64 44, !10, i64 48}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!9, !10, i64 4}
!13 = !{!9, !10, i64 8}
!14 = !{!9, !11, i64 32}
!15 = !{!9, !10, i64 48}
!16 = !{!9, !10, i64 44}


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