; LLVM IR from microsoft/Multiverso :: Applications/WordEmbedding/src/reader.ll (ZN13wordembedding6Reader8ReadWordEPcP8_IO_FILE)

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

%"class.wordembedding::Reader" = type { ptr, ptr, [501 x i8], ptr, ptr, i64, i64, %"class.std::unordered_set" }
%"class.std::unordered_set" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }

@.str.3 = external hidden unnamed_addr constant [5 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN13wordembedding6Reader8ReadWordEPcP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(608) %0, ptr noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  br label %12

12:                                               ; preds = %80, %67, %34, %3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = call i32 @feof(ptr noundef %13) #4
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %22, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds %"class.wordembedding::Reader", ptr %11, i32 0, i32 5
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %"class.wordembedding::Reader", ptr %11, i32 0, i32 6
  %20 = load i64, ptr %19, align 8, !tbaa !19
  %21 = icmp slt i64 %18, %20
  br label %22

22:                                               ; preds = %16, %12
  %23 = phi i1 [ false, %12 ], [ %21, %16 ]
  br i1 %23, label %24, label %81

24:                                               ; preds = %22
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = call i32 @fgetc(ptr noundef %25)
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %9, align 1, !tbaa !20
  %28 = getelementptr inbounds %"class.wordembedding::Reader", ptr %11, i32 0, i32 5
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = add nsw i64 %29, 1
  store i64 %30, ptr %28, align 8, !tbaa !11
  %31 = load i8, ptr %9, align 1, !tbaa !20
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 13
  br i1 %33, label %34, label %35

34:                                               ; preds = %24
  br label %12, !llvm.loop !21

35:                                               ; preds = %24
  %36 = load i8, ptr %9, align 1, !tbaa !20
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 32
  br i1 %38, label %47, label %39

39:                                               ; preds = %35
  %40 = load i8, ptr %9, align 1, !tbaa !20
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 %41, 9
  br i1 %42, label %47, label %43

43:                                               ; preds = %39
  %44 = load i8, ptr %9, align 1, !tbaa !20
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %45, 10
  br i1 %46, label %47, label %68

47:                                               ; preds = %43, %39, %35
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = icmp sgt i32 %48, 0
  br i1 %49, label %50, label %60

50:                                               ; preds = %47
  %51 = load i8, ptr %9, align 1, !tbaa !20
  %52 = sext i8 %51 to i32
  %53 = icmp eq i32 %52, 10
  br i1 %53, label %54, label %59

54:                                               ; preds = %50
  %55 = load i8, ptr %9, align 1, !tbaa !20
  %56 = sext i8 %55 to i32
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = call i32 @ungetc(i32 noundef %56, ptr noundef %57)
  br label %59

59:                                               ; preds = %54, %50
  br label %81

60:                                               ; preds = %47
  %61 = load i8, ptr %9, align 1, !tbaa !20
  %62 = sext i8 %61 to i32
  %63 = icmp eq i32 %62, 10
  br i1 %63, label %64, label %67

64:                                               ; preds = %60
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = call ptr @strcpy(ptr noundef %65, ptr noundef @.str.3) #4
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %88

67:                                               ; preds = %60
  br label %12, !llvm.loop !21

68:                                               ; preds = %43
  %69 = load i8, ptr %9, align 1, !tbaa !20
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %8, align 4, !tbaa !9
  %73 = sext i32 %71 to i64
  %74 = getelementptr inbounds i8, ptr %70, i64 %73
  store i8 %69, ptr %74, align 1, !tbaa !20
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = icmp sge i32 %75, 499
  br i1 %76, label %77, label %80

77:                                               ; preds = %68
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr %8, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %77, %68
  br label %12, !llvm.loop !21

81:                                               ; preds = %59, %22
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load i32, ptr %8, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %82, i64 %84
  store i8 0, ptr %85, align 1, !tbaa !20
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = icmp ne i32 %86, 0
  store i1 %87, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %88

88:                                               ; preds = %81, %64
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %89 = load i1, ptr %4, align 1
  ret i1 %89
}

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

; Function Attrs: nounwind
declare i32 @feof(ptr noundef) #2

declare i32 @fgetc(ptr noundef) #3

declare i32 @ungetc(i32 noundef, ptr noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 536}
!12 = !{!"_ZTSN13wordembedding6ReaderE", !6, i64 0, !6, i64 8, !7, i64 16, !6, i64 520, !6, i64 528, !13, i64 536, !13, i64 544, !14, i64 552}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTSSt13unordered_setINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4hashIS5_ESt8equal_toIS5_ESaIS5_EE", !15, i64 0}
!15 = !{!"_ZTSSt10_HashtableINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_SaIS5_ENSt8__detail9_IdentityESt8equal_toIS5_ESt4hashIS5_ENS7_18_Mod_range_hashingENS7_20_Default_ranged_hashENS7_20_Prime_rehash_policyENS7_17_Hashtable_traitsILb1ELb1ELb1EEEE", !6, i64 0, !13, i64 8, !16, i64 16, !13, i64 24, !17, i64 32, !6, i64 48}
!16 = !{!"_ZTSNSt8__detail15_Hash_node_baseE", !6, i64 0}
!17 = !{!"_ZTSNSt8__detail20_Prime_rehash_policyE", !18, i64 0, !13, i64 8}
!18 = !{!"float", !7, i64 0}
!19 = !{!12, !13, i64 544}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef zeroext i1 @_ZN13wordembedding6Reader8ReadWordEPcP8_IO_FILE(ptr nocapture noundef nonnull align 8 dereferenceable(608) %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 align 2 {
  %4 = tail call i32 @feof(ptr noundef %2) #3
  %.not3858 = icmp eq i32 %4, 0
  br i1 %.not3858, label %.lr.ph.lr.ph, label %.critedge

.lr.ph.lr.ph:                                     ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 536
  %6 = getelementptr inbounds i8, ptr %0, i64 544
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %.outer
  %.026.ph59 = phi i32 [ 0, %.lr.ph.lr.ph ], [ %spec.select, %.outer ]
  %.not61 = icmp eq i32 %.026.ph59, 0
  br i1 %.not61, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.backedge.us
  %7 = load i64, ptr %5, align 8, !tbaa !5
  %8 = load i64, ptr %6, align 8, !tbaa !16
  %9 = icmp slt i64 %7, %8
  br i1 %9, label %10, label %.critedge

10:                                               ; preds = %.lr.ph.split.us
  %11 = tail call i32 @fgetc(ptr noundef %2)
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = add nsw i64 %12, 1
  store i64 %13, ptr %5, align 8, !tbaa !5
  %trunc86 = trunc i32 %11 to i8
  switch i8 %trunc86, label %.outer [
    i8 13, label %.backedge.us
    i8 10, label %23
    i8 9, label %.critedge
    i8 32, label %.critedge
  ]

.backedge.us:                                     ; preds = %10
  %14 = tail call i32 @feof(ptr noundef %2) #3
  %.not.us = icmp eq i32 %14, 0
  br i1 %.not.us, label %.lr.ph.split.us, label %.critedge, !llvm.loop !17

.lr.ph.split:                                     ; preds = %.lr.ph, %.backedge
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = load i64, ptr %6, align 8, !tbaa !16
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %18, label %.critedge

18:                                               ; preds = %.lr.ph.split
  %19 = tail call i32 @fgetc(ptr noundef %2)
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = add nsw i64 %20, 1
  store i64 %21, ptr %5, align 8, !tbaa !5
  %trunc = trunc i32 %19 to i8
  switch i8 %trunc, label %.outer [
    i8 13, label %.backedge
    i8 10, label %25
    i8 9, label %.backedge
    i8 32, label %.backedge
  ]

.backedge:                                        ; preds = %18, %18, %18
  %22 = tail call i32 @feof(ptr noundef %2) #3
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %.lr.ph.split, label %.critedge, !llvm.loop !17

23:                                               ; preds = %10
  %24 = tail call i32 @ungetc(i32 noundef 10, ptr noundef %2)
  br label %.critedge

25:                                               ; preds = %18
  %26 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.3) #3
  br label %36

.outer:                                           ; preds = %10, %18
  %.us-phi42 = phi i32 [ %19, %18 ], [ %11, %10 ]
  %27 = trunc i32 %.us-phi42 to i8
  %28 = sext i32 %.026.ph59 to i64
  %29 = getelementptr inbounds i8, ptr %1, i64 %28
  store i8 %27, ptr %29, align 1, !tbaa !19
  %30 = icmp slt i32 %.026.ph59, 498
  %31 = zext i1 %30 to i32
  %spec.select = add i32 %.026.ph59, %31
  %32 = tail call i32 @feof(ptr noundef %2) #3
  %.not38 = icmp eq i32 %32, 0
  br i1 %.not38, label %.lr.ph, label %.critedge, !llvm.loop !17

.critedge:                                        ; preds = %.outer, %.lr.ph.split.us, %.backedge.us, %10, %10, %.lr.ph.split, %.backedge, %3, %23
  %.026.ph36 = phi i32 [ %.026.ph59, %23 ], [ 0, %3 ], [ 0, %.backedge ], [ 0, %.lr.ph.split ], [ %.026.ph59, %10 ], [ %.026.ph59, %10 ], [ %.026.ph59, %.backedge.us ], [ %.026.ph59, %.lr.ph.split.us ], [ %spec.select, %.outer ]
  %33 = sext i32 %.026.ph36 to i64
  %34 = getelementptr inbounds i8, ptr %1, i64 %33
  store i8 0, ptr %34, align 1, !tbaa !19
  %35 = icmp ne i32 %.026.ph36, 0
  br label %36

36:                                               ; preds = %.critedge, %25
  %.0 = phi i1 [ %35, %.critedge ], [ true, %25 ]
  ret i1 %.0
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @ungetc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #1

; 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 #2

attributes #0 = { mustprogress 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 #1 = { 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 #2 = { 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 #3 = { 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, !10, i64 536}
!6 = !{!"_ZTSN13wordembedding6ReaderE", !7, i64 0, !7, i64 8, !8, i64 16, !7, i64 520, !7, i64 528, !10, i64 536, !10, i64 544, !11, i64 552}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_ZTSSt13unordered_setINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4hashIS5_ESt8equal_toIS5_ESaIS5_EE", !12, i64 0}
!12 = !{!"_ZTSSt10_HashtableINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES5_SaIS5_ENSt8__detail9_IdentityESt8equal_toIS5_ESt4hashIS5_ENS7_18_Mod_range_hashingENS7_20_Default_ranged_hashENS7_20_Prime_rehash_policyENS7_17_Hashtable_traitsILb1ELb1ELb1EEEE", !7, i64 0, !10, i64 8, !13, i64 16, !10, i64 24, !14, i64 32, !7, i64 48}
!13 = !{!"_ZTSNSt8__detail15_Hash_node_baseE", !7, i64 0}
!14 = !{!"_ZTSNSt8__detail20_Prime_rehash_policyE", !15, i64 0, !10, i64 8}
!15 = !{!"float", !8, i64 0}
!16 = !{!6, !10, i64 544}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass