; LLVM IR from microsoft/Multiverso :: Applications/WordEmbedding/src/util.ll (ZN13wordembedding8ReadWordEPcP8_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"

@.str.69 = 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN13wordembedding8ReadWordEPcP8_IO_FILE(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = 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) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  br label %9

9:                                                ; preds = %67, %54, %21, %2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call i32 @feof(ptr noundef %10) #4
  %12 = icmp ne i32 %11, 0
  %13 = xor i1 %12, true
  br i1 %13, label %14, label %68

14:                                               ; preds = %9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call i32 @fgetc(ptr noundef %15)
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %7, align 1, !tbaa !11
  %18 = load i8, ptr %7, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %19, 13
  br i1 %20, label %21, label %22

21:                                               ; preds = %14
  br label %9, !llvm.loop !12

22:                                               ; preds = %14
  %23 = load i8, ptr %7, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %24, 32
  br i1 %25, label %34, label %26

26:                                               ; preds = %22
  %27 = load i8, ptr %7, align 1, !tbaa !11
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 9
  br i1 %29, label %34, label %30

30:                                               ; preds = %26
  %31 = load i8, ptr %7, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 10
  br i1 %33, label %34, label %55

34:                                               ; preds = %30, %26, %22
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %47

37:                                               ; preds = %34
  %38 = load i8, ptr %7, align 1, !tbaa !11
  %39 = sext i8 %38 to i32
  %40 = icmp eq i32 %39, 10
  br i1 %40, label %41, label %46

41:                                               ; preds = %37
  %42 = load i8, ptr %7, align 1, !tbaa !11
  %43 = sext i8 %42 to i32
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call i32 @ungetc(i32 noundef %43, ptr noundef %44)
  br label %46

46:                                               ; preds = %41, %37
  br label %68

47:                                               ; preds = %34
  %48 = load i8, ptr %7, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = icmp eq i32 %49, 10
  br i1 %50, label %51, label %54

51:                                               ; preds = %47
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call ptr @strcpy(ptr noundef %52, ptr noundef @.str.69) #4
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %75

54:                                               ; preds = %47
  br label %9, !llvm.loop !12

55:                                               ; preds = %30
  %56 = load i8, ptr %7, align 1, !tbaa !11
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !9
  %60 = sext i32 %58 to i64
  %61 = getelementptr inbounds i8, ptr %57, i64 %60
  store i8 %56, ptr %61, align 1, !tbaa !11
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = icmp sge i32 %62, 499
  br i1 %63, label %64, label %67

64:                                               ; preds = %55
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = add nsw i32 %65, -1
  store i32 %66, ptr %6, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %64, %55
  br label %9, !llvm.loop !12

68:                                               ; preds = %46, %9
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i8, ptr %69, i64 %71
  store i8 0, ptr %72, align 1, !tbaa !11
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = icmp sgt i32 %73, 0
  store i1 %74, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %75

75:                                               ; preds = %68, %51
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %76 = load i1, ptr %3, align 1
  ret i1 %76
}

; 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.69 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef zeroext i1 @_ZN13wordembedding8ReadWordEPcP8_IO_FILE(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @feof(ptr noundef %1) #3
  %.not3751 = icmp eq i32 %3, 0
  br i1 %.not3751, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %2, %.outer
  %.025.ph52 = phi i32 [ %spec.select, %.outer ], [ 0, %2 ]
  %.not54 = icmp eq i32 %.025.ph52, 0
  br i1 %.not54, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.backedge.us
  %4 = tail call i32 @fgetc(ptr noundef %1)
  %trunc88 = trunc i32 %4 to i8
  switch i8 %trunc88, label %.outer [
    i8 13, label %.backedge.us
    i8 10, label %8
    i8 9, label %.loopexit
    i8 32, label %.loopexit
  ]

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

.lr.ph.split:                                     ; preds = %.lr.ph, %.backedge
  %6 = tail call i32 @fgetc(ptr noundef %1)
  %trunc = trunc i32 %6 to i8
  switch i8 %trunc, label %.outer [
    i8 13, label %.backedge
    i8 10, label %10
    i8 9, label %.backedge
    i8 32, label %.backedge
  ]

.backedge:                                        ; preds = %.lr.ph.split, %.lr.ph.split, %.lr.ph.split
  %7 = tail call i32 @feof(ptr noundef %1) #3
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.lr.ph.split, label %.loopexit, !llvm.loop !5

8:                                                ; preds = %.lr.ph.split.us
  %9 = tail call i32 @ungetc(i32 noundef 10, ptr noundef %1)
  br label %.loopexit

10:                                               ; preds = %.lr.ph.split
  %11 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.69) #3
  br label %21

.outer:                                           ; preds = %.lr.ph.split.us, %.lr.ph.split
  %.us-phi = phi i32 [ %6, %.lr.ph.split ], [ %4, %.lr.ph.split.us ]
  %12 = trunc i32 %.us-phi to i8
  %13 = sext i32 %.025.ph52 to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 %13
  store i8 %12, ptr %14, align 1, !tbaa !7
  %15 = icmp slt i32 %.025.ph52, 498
  %16 = zext i1 %15 to i32
  %spec.select = add i32 %.025.ph52, %16
  %17 = tail call i32 @feof(ptr noundef %1) #3
  %.not37 = icmp eq i32 %17, 0
  br i1 %.not37, label %.lr.ph, label %.loopexit, !llvm.loop !5

.loopexit:                                        ; preds = %.outer, %.backedge.us, %.lr.ph.split.us, %.lr.ph.split.us, %.backedge, %2, %8
  %.025.ph35 = phi i32 [ %.025.ph52, %8 ], [ 0, %2 ], [ 0, %.backedge ], [ %.025.ph52, %.lr.ph.split.us ], [ %.025.ph52, %.lr.ph.split.us ], [ %.025.ph52, %.backedge.us ], [ %spec.select, %.outer ]
  %18 = sext i32 %.025.ph35 to i64
  %19 = getelementptr inbounds i8, ptr %0, i64 %18
  store i8 0, ptr %19, align 1, !tbaa !7
  %20 = icmp sgt i32 %.025.ph35, 0
  br label %21

21:                                               ; preds = %.loopexit, %10
  %.0 = phi i1 [ %20, %.loopexit ], [ true, %10 ]
  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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


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