; LLVM IR from aap/librw :: tools/hopalong/vfs.ll (Z9vfs_fopenPKcS0_)

; 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.FILE_VFS = type { i32, ptr, i32, i32 }
%struct.VFS = type { ptr, i32 }
%struct.VFS_file = type { ptr, ptr, i32 }

@vfsfiles = external dso_local global [64 x %struct.FILE_VFS], align 16
@globalVFS = external dso_local global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z9vfs_fopenPKcS0_(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = 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 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef ptr @strrchr(ptr noundef %14, i32 noundef 47) #4
  store ptr %15, ptr %12, align 8, !tbaa !5
  %16 = load ptr, ptr %12, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %21

18:                                               ; preds = %2
  %19 = load ptr, ptr %12, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i32 1
  store ptr %20, ptr %12, align 8, !tbaa !5
  br label %23

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %22, ptr %12, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %21, %18
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %37, %23
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = icmp ult i64 %26, 64
  br i1 %27, label %28, label %40

28:                                               ; preds = %24
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.FILE_VFS, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %36, label %35

35:                                               ; preds = %28
  br label %41

36:                                               ; preds = %28
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !9
  br label %24, !llvm.loop !13

40:                                               ; preds = %24
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %115

41:                                               ; preds = %35
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call noundef ptr @strchr(ptr noundef %42, i32 noundef 114) #4
  store ptr %43, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call noundef ptr @strchr(ptr noundef %44, i32 noundef 119) #4
  store ptr %45, ptr %10, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call noundef ptr @strchr(ptr noundef %46, i32 noundef 43) #4
  store ptr %47, ptr %11, align 8, !tbaa !5
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %53, label %50

50:                                               ; preds = %41
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %54

53:                                               ; preds = %50, %41
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %115

54:                                               ; preds = %50
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %75, %54
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = load ptr, ptr @globalVFS, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.VFS, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 8, !tbaa !15
  %60 = icmp slt i32 %56, %59
  br i1 %60, label %61, label %78

61:                                               ; preds = %55
  %62 = load ptr, ptr @globalVFS, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.VFS, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !17
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.VFS_file, ptr %64, i64 %66
  %68 = getelementptr inbounds %struct.VFS_file, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !18
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = call i32 @strcmp(ptr noundef %69, ptr noundef %70) #4
  %72 = icmp eq i32 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %61
  br label %79

74:                                               ; preds = %61
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %8, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %8, align 4, !tbaa !9
  br label %55, !llvm.loop !20

78:                                               ; preds = %55
  store ptr null, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %115

79:                                               ; preds = %73
  %80 = load i32, ptr %7, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.FILE_VFS, ptr %82, i32 0, i32 0
  store i32 1, ptr %83, align 8, !tbaa !11
  %84 = load ptr, ptr @globalVFS, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.VFS, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !17
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds %struct.VFS_file, ptr %86, i64 %88
  %90 = getelementptr inbounds %struct.VFS_file, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %90, align 8, !tbaa !21
  %92 = load i32, ptr %7, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %93
  %95 = getelementptr inbounds %struct.FILE_VFS, ptr %94, i32 0, i32 1
  store ptr %91, ptr %95, align 8, !tbaa !22
  %96 = load i32, ptr %7, align 4, !tbaa !9
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %97
  %99 = getelementptr inbounds %struct.FILE_VFS, ptr %98, i32 0, i32 2
  store i32 0, ptr %99, align 8, !tbaa !23
  %100 = load ptr, ptr @globalVFS, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.VFS, ptr %100, i32 0, i32 0
  %102 = load ptr, ptr %101, align 8, !tbaa !17
  %103 = load i32, ptr %8, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds %struct.VFS_file, ptr %102, i64 %104
  %106 = getelementptr inbounds %struct.VFS_file, ptr %105, i32 0, i32 2
  %107 = load i32, ptr %106, align 8, !tbaa !24
  %108 = load i32, ptr %7, align 4, !tbaa !9
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %109
  %111 = getelementptr inbounds %struct.FILE_VFS, ptr %110, i32 0, i32 3
  store i32 %107, ptr %111, align 4, !tbaa !25
  %112 = load i32, ptr %7, align 4, !tbaa !9
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %113
  store ptr %114, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %115

115:                                              ; preds = %79, %78, %53, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %116 = load ptr, ptr %3, align 8
  ret ptr %116
}

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

; Function Attrs: nounwind willreturn memory(read)
declare noundef ptr @strrchr(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare noundef ptr @strchr(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

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

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS8FILE_VFS", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 8}
!16 = !{!"_ZTS3VFS", !6, i64 0, !10, i64 8}
!17 = !{!16, !6, i64 0}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTS8VFS_file", !6, i64 0, !6, i64 8, !10, i64 16}
!20 = distinct !{!20, !14}
!21 = !{!19, !6, i64 8}
!22 = !{!12, !6, i64 8}
!23 = !{!12, !10, i64 16}
!24 = !{!19, !10, i64 16}
!25 = !{!12, !10, i64 20}


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

%struct.FILE_VFS = type { i32, ptr, i32, i32 }
%struct.VFS_file = type { ptr, ptr, i32 }

@vfsfiles = external dso_local global [64 x %struct.FILE_VFS], align 16
@globalVFS = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_Z9vfs_fopenPKcS0_(ptr noundef readonly %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call noundef ptr @strrchr(ptr noundef nonnull dereferenceable(1) %0, i32 noundef 47) #2
  %.not = icmp eq ptr %3, null
  %4 = getelementptr inbounds i8, ptr %3, i64 1
  %.0 = select i1 %.not, ptr %0, ptr %4
  br label %15

5:                                                ; preds = %15
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %6 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %indvars.iv.next
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %.not29.1 = icmp eq i32 %7, 0
  br i1 %.not29.1, label %18, label %8

8:                                                ; preds = %5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %9 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %indvars.iv.next.1
  %10 = load i32, ptr %9, align 16, !tbaa !5
  %.not29.2 = icmp eq i32 %10, 0
  br i1 %.not29.2, label %18, label %11

11:                                               ; preds = %8
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %12 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %indvars.iv.next.2
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %.not29.3 = icmp eq i32 %13, 0
  br i1 %.not29.3, label %18, label %14

14:                                               ; preds = %11
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 64
  br i1 %exitcond.not.3, label %.loopexit, label %15, !llvm.loop !11

15:                                               ; preds = %14, %2
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next.3, %14 ]
  %16 = getelementptr inbounds [64 x %struct.FILE_VFS], ptr @vfsfiles, i64 0, i64 %indvars.iv
  %17 = load i32, ptr %16, align 16, !tbaa !5
  %.not29 = icmp eq i32 %17, 0
  br i1 %.not29, label %18, label %5

18:                                               ; preds = %11, %8, %5, %15
  %.lcssa = phi ptr [ %16, %15 ], [ %6, %5 ], [ %9, %8 ], [ %12, %11 ]
  %19 = tail call noundef ptr @strchr(ptr noundef nonnull dereferenceable(1) %1, i32 noundef 119) #2
  %20 = tail call noundef ptr @strchr(ptr noundef nonnull dereferenceable(1) %1, i32 noundef 43) #2
  %21 = icmp ne ptr %19, null
  %22 = icmp ne ptr %20, null
  %or.cond = or i1 %21, %22
  br i1 %or.cond, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %18
  %23 = load ptr, ptr @globalVFS, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %27 = load ptr, ptr %23, align 8, !tbaa !16
  %wide.trip.count = zext nneg i32 %25 to i64
  br label %29

28:                                               ; preds = %29
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next41, %wide.trip.count
  br i1 %exitcond43.not, label %.loopexit, label %29, !llvm.loop !17

29:                                               ; preds = %.lr.ph, %28
  %indvars.iv40 = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next41, %28 ]
  %30 = getelementptr inbounds %struct.VFS_file, ptr %27, i64 %indvars.iv40
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %31, ptr noundef nonnull dereferenceable(1) %.0) #2
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %28

34:                                               ; preds = %29
  store i32 1, ptr %.lcssa, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.VFS_file, ptr %27, i64 %indvars.iv40, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !20
  %37 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  store ptr %36, ptr %37, align 8, !tbaa !21
  %38 = getelementptr inbounds i8, ptr %.lcssa, i64 16
  store i32 0, ptr %38, align 8, !tbaa !22
  %39 = getelementptr inbounds %struct.VFS_file, ptr %27, i64 %indvars.iv40, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !23
  %41 = getelementptr inbounds i8, ptr %.lcssa, i64 20
  store i32 %40, ptr %41, align 4, !tbaa !24
  br label %.loopexit

.loopexit:                                        ; preds = %14, %28, %.preheader, %18, %34
  %.024 = phi ptr [ %.lcssa, %34 ], [ null, %18 ], [ null, %.preheader ], [ null, %28 ], [ null, %14 ]
  ret ptr %.024
}

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

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

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

attributes #0 = { mustprogress nofree nounwind memory(readwrite, argmem: read, inaccessiblemem: none) 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 #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 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, !7, i64 0}
!6 = !{!"_ZTS8FILE_VFS", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !7, i64 8}
!15 = !{!"_ZTS3VFS", !10, i64 0, !7, i64 8}
!16 = !{!15, !10, i64 0}
!17 = distinct !{!17, !12}
!18 = !{!19, !10, i64 0}
!19 = !{!"_ZTS8VFS_file", !10, i64 0, !10, i64 8, !7, i64 16}
!20 = !{!19, !10, i64 8}
!21 = !{!6, !10, i64 8}
!22 = !{!6, !7, i64 16}
!23 = !{!19, !7, i64 16}
!24 = !{!6, !7, i64 20}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass