; LLVM IR from kkumatani/distant_speech_recognition :: btk20_src/utils/utils.ll (Z5fgetsPKcS0_i)

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

@_ZZ5fgetsPKcS0_iE4line = external hidden global [1024 x i8], align 16
@_ZZ5fgetsPKcS0_iE11EmptyString = external hidden global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [95 x i8], align 1
@__PRETTY_FUNCTION__._Z5fgetsPKcS0_i = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z8fileLockPKci(ptr noundef, i32 noundef) #0

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

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

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

16:                                               ; preds = %3
  %17 = load ptr, ptr @_ZZ5fgetsPKcS0_iE11EmptyString, align 8, !tbaa !5
  store ptr %17, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %133

18:                                               ; preds = %3
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = call noalias ptr @fdopen(i32 noundef %19, ptr noundef @.str.2) #5
  store ptr %20, ptr %8, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %73, %21
  br label %23

23:                                               ; preds = %44, %22
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call i32 @getc(ptr noundef %24)
  %26 = trunc i32 %25 to i8
  store i8 %26, ptr %10, align 1, !tbaa !11
  br label %27

27:                                               ; preds = %23
  %28 = load i8, ptr %10, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = icmp eq i32 %29, 10
  br i1 %30, label %39, label %31

31:                                               ; preds = %27
  %32 = load i8, ptr %10, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 9
  br i1 %34, label %39, label %35

35:                                               ; preds = %31
  %36 = load i8, ptr %10, align 1, !tbaa !11
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 32
  br i1 %38, label %39, label %44

39:                                               ; preds = %35, %31, %27
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = call i32 @feof(ptr noundef %40) #5
  %42 = icmp ne i32 %41, 0
  %43 = xor i1 %42, true
  br label %44

44:                                               ; preds = %39, %35
  %45 = phi i1 [ false, %35 ], [ %43, %39 ]
  br i1 %45, label %23, label %46, !llvm.loop !12

46:                                               ; preds = %44
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = call i32 @feof(ptr noundef %47) #5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  br label %74

51:                                               ; preds = %46
  %52 = load i8, ptr %10, align 1, !tbaa !11
  %53 = sext i8 %52 to i32
  %54 = icmp ne i32 %53, 35
  br i1 %54, label %55, label %56

55:                                               ; preds = %51
  br label %74

56:                                               ; preds = %51
  br label %57

57:                                               ; preds = %70, %56
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = call i32 @getc(ptr noundef %58)
  %60 = trunc i32 %59 to i8
  store i8 %60, ptr %10, align 1, !tbaa !11
  br label %61

61:                                               ; preds = %57
  %62 = load i8, ptr %10, align 1, !tbaa !11
  %63 = sext i8 %62 to i32
  %64 = icmp ne i32 %63, 10
  br i1 %64, label %65, label %70

65:                                               ; preds = %61
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = call i32 @feof(ptr noundef %66) #5
  %68 = icmp ne i32 %67, 0
  %69 = xor i1 %68, true
  br label %70

70:                                               ; preds = %65, %61
  %71 = phi i1 [ false, %61 ], [ %69, %65 ]
  br i1 %71, label %57, label %72, !llvm.loop !14

72:                                               ; preds = %70
  br label %73

73:                                               ; preds = %72
  br i1 true, label %22, label %74, !llvm.loop !15

74:                                               ; preds = %73, %55, %50
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = call i32 @feof(ptr noundef %75) #5
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %128, label %78

78:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = call i32 @fseek(ptr noundef %79, i64 noundef -1, i32 noundef 1)
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = call i32 @fputc(i32 noundef 35, ptr noundef %81)
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = call i32 @fflush(ptr noundef %83)
  %85 = load i8, ptr %10, align 1, !tbaa !11
  store i32 0, ptr %12, align 4, !tbaa !9
  store i8 %85, ptr @_ZZ5fgetsPKcS0_iE4line, align 16, !tbaa !11
  br label %86

86:                                               ; preds = %118, %78
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = call i32 @getc(ptr noundef %87)
  %89 = trunc i32 %88 to i8
  store i8 %89, ptr %10, align 1, !tbaa !11
  %90 = load i32, ptr %12, align 4, !tbaa !9
  %91 = icmp slt i32 %90, 1024
  br i1 %91, label %92, label %93

92:                                               ; preds = %86
  br label %95

93:                                               ; preds = %86
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 89, ptr noundef @__PRETTY_FUNCTION__._Z5fgetsPKcS0_i) #6
  unreachable

94:                                               ; No predecessors!
  br label %95

95:                                               ; preds = %94, %92
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = call i32 @feof(ptr noundef %96) #5
  %98 = icmp ne i32 %97, 0
  br i1 %98, label %109, label %99

99:                                               ; preds = %95
  %100 = load i8, ptr %10, align 1, !tbaa !11
  %101 = sext i8 %100 to i32
  %102 = icmp ne i32 %101, 10
  br i1 %102, label %103, label %109

103:                                              ; preds = %99
  %104 = load i8, ptr %10, align 1, !tbaa !11
  %105 = load i32, ptr %12, align 4, !tbaa !9
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %12, align 4, !tbaa !9
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [1024 x i8], ptr @_ZZ5fgetsPKcS0_iE4line, i64 0, i64 %107
  store i8 %104, ptr %108, align 1, !tbaa !11
  br label %109

109:                                              ; preds = %103, %99, %95
  br label %110

110:                                              ; preds = %109
  %111 = load ptr, ptr %8, align 8, !tbaa !5
  %112 = call i32 @feof(ptr noundef %111) #5
  %113 = icmp ne i32 %112, 0
  br i1 %113, label %118, label %114

114:                                              ; preds = %110
  %115 = load i8, ptr %10, align 1, !tbaa !11
  %116 = sext i8 %115 to i32
  %117 = icmp ne i32 %116, 10
  br label %118

118:                                              ; preds = %114, %110
  %119 = phi i1 [ false, %110 ], [ %117, %114 ]
  br i1 %119, label %86, label %120, !llvm.loop !16

120:                                              ; preds = %118
  %121 = load i32, ptr %12, align 4, !tbaa !9
  %122 = add nsw i32 %121, 1
  store i32 %122, ptr %12, align 4, !tbaa !9
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [1024 x i8], ptr @_ZZ5fgetsPKcS0_iE4line, i64 0, i64 %123
  store i8 0, ptr %124, align 1, !tbaa !11
  %125 = load i32, ptr %9, align 4, !tbaa !9
  call void @_ZL10fileUnlocki(i32 noundef %125)
  %126 = load ptr, ptr %8, align 8, !tbaa !5
  %127 = call i32 @fclose(ptr noundef %126)
  store ptr @_ZZ5fgetsPKcS0_iE4line, ptr %4, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %133

128:                                              ; preds = %74
  %129 = load i32, ptr %9, align 4, !tbaa !9
  call void @_ZL10fileUnlocki(i32 noundef %129)
  %130 = load ptr, ptr %8, align 8, !tbaa !5
  %131 = call i32 @fclose(ptr noundef %130)
  %132 = load ptr, ptr @_ZZ5fgetsPKcS0_iE11EmptyString, align 8, !tbaa !5
  store ptr %132, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %133

133:                                              ; preds = %128, %120, %16
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %134 = load ptr, ptr %4, align 8
  ret ptr %134
}

; Function Attrs: nounwind
declare noalias ptr @fdopen(i32 noundef, ptr noundef) #2

declare i32 @getc(ptr noundef) #3

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

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #3

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

declare i32 @fflush(ptr noundef) #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL10fileUnlocki(i32 noundef) #0

declare i32 @fclose(ptr noundef) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn 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 = { nounwind }
attributes #6 = { noreturn 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"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}


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

@_ZZ5fgetsPKcS0_iE4line = external hidden global [1024 x i8], align 16
@_ZZ5fgetsPKcS0_iE11EmptyString = external hidden local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [95 x i8], align 1
@__PRETTY_FUNCTION__._Z5fgetsPKcS0_i = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z8fileLockPKci(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z5fgetsPKcS0_i(ptr noundef %0, ptr nocapture noundef readnone %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noundef i32 @_Z8fileLockPKci(ptr noundef %0, i32 noundef 2)
  %5 = icmp slt i32 %4, 0
  br i1 %5, label %6, label %8

6:                                                ; preds = %3
  %7 = load ptr, ptr @_ZZ5fgetsPKcS0_iE11EmptyString, align 8, !tbaa !5
  br label %51

8:                                                ; preds = %3
  %9 = tail call noalias ptr @fdopen(i32 noundef %4, ptr noundef nonnull @.str.2) #3
  br label %10

10:                                               ; preds = %.backedge, %8
  %11 = tail call i32 @getc(ptr noundef %9)
  %sext = shl i32 %11, 24
  switch i32 %sext, label %.critedge [
    i32 536870912, label %12
    i32 167772160, label %12
    i32 150994944, label %12
  ]

12:                                               ; preds = %10, %10, %10
  %13 = tail call i32 @feof(ptr noundef %9) #3
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %.backedge, label %.critedge

.backedge:                                        ; preds = %18, %.preheader, %12
  br label %10, !llvm.loop !9

.critedge:                                        ; preds = %10, %12
  %14 = tail call i32 @feof(ptr noundef %9) #3
  %15 = icmp ne i32 %14, 0
  %16 = icmp ne i32 %sext, 587202560
  %or.cond13 = or i1 %16, %15
  br i1 %or.cond13, label %20, label %.preheader

.preheader:                                       ; preds = %.critedge, %18
  %17 = tail call i32 @getc(ptr noundef %9)
  %sext45.mask = and i32 %17, 255
  %.not46 = icmp eq i32 %sext45.mask, 10
  br i1 %.not46, label %.backedge, label %18

18:                                               ; preds = %.preheader
  %19 = tail call i32 @feof(ptr noundef %9) #3
  %.not47 = icmp eq i32 %19, 0
  br i1 %.not47, label %.preheader, label %.backedge, !llvm.loop !11

20:                                               ; preds = %.critedge
  %21 = tail call i32 @feof(ptr noundef %9) #3
  %.not48 = icmp eq i32 %21, 0
  br i1 %.not48, label %22, label %48

22:                                               ; preds = %20
  %23 = trunc i32 %11 to i8
  %24 = tail call i32 @fseek(ptr noundef %9, i64 noundef -1, i32 noundef 1)
  %25 = tail call i32 @fputc(i32 noundef 35, ptr noundef %9)
  %26 = tail call i32 @fflush(ptr noundef %9)
  store i8 %23, ptr @_ZZ5fgetsPKcS0_iE4line, align 16, !tbaa !12
  br label %27

27:                                               ; preds = %40, %22
  %.0 = phi i32 [ 0, %22 ], [ %.1, %40 ]
  %28 = tail call i32 @getc(ptr noundef %9)
  %29 = trunc i32 %28 to i8
  %30 = icmp slt i32 %.0, 1024
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 89, ptr noundef nonnull @__PRETTY_FUNCTION__._Z5fgetsPKcS0_i) #4
  unreachable

32:                                               ; preds = %27
  %33 = tail call i32 @feof(ptr noundef %9) #3
  %34 = icmp eq i32 %33, 0
  %sext49.mask = and i32 %28, 255
  %35 = icmp ne i32 %sext49.mask, 10
  %or.cond10 = and i1 %35, %34
  br i1 %or.cond10, label %36, label %40

36:                                               ; preds = %32
  %37 = add nsw i32 %.0, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1024 x i8], ptr @_ZZ5fgetsPKcS0_iE4line, i64 0, i64 %38
  store i8 %29, ptr %39, align 1, !tbaa !12
  br label %40

40:                                               ; preds = %32, %36
  %.1 = phi i32 [ %37, %36 ], [ %.0, %32 ]
  %41 = tail call i32 @feof(ptr noundef %9) #3
  %.not50 = icmp eq i32 %41, 0
  %42 = and i1 %35, %.not50
  br i1 %42, label %27, label %43, !llvm.loop !13

43:                                               ; preds = %40
  %44 = add nsw i32 %.1, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1024 x i8], ptr @_ZZ5fgetsPKcS0_iE4line, i64 0, i64 %45
  store i8 0, ptr %46, align 1, !tbaa !12
  tail call void @_ZL10fileUnlocki(i32 noundef %4)
  %47 = tail call i32 @fclose(ptr noundef %9)
  br label %51

48:                                               ; preds = %20
  tail call void @_ZL10fileUnlocki(i32 noundef %4)
  %49 = tail call i32 @fclose(ptr noundef %9)
  %50 = load ptr, ptr @_ZZ5fgetsPKcS0_iE11EmptyString, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %48, %43, %6
  %.043 = phi ptr [ %7, %6 ], [ %50, %48 ], [ @_ZZ5fgetsPKcS0_iE4line, %43 ]
  ret ptr %.043
}

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

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

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

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

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

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL10fileUnlocki(i32 noundef) local_unnamed_addr #0

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

attributes #0 = { 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 #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 = { noreturn 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 = { nounwind }
attributes #4 = { noreturn 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !10}


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