; LLVM IR from kkumatani/distant_speech_recognition :: btk20_src/common/mach_ind_io.ll (Z16write_floatbytesP8_IO_FILEPfi)

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

@stderr = external global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [77 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

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

19:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %107

20:                                               ; preds = %3
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = mul i64 1, %22
  %24 = call noalias ptr @malloc(i64 noundef %23) #7
  store ptr %24, ptr %8, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %30

27:                                               ; preds = %20
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str.10) #6
  store i32 0, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %107

30:                                               ; preds = %20
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %31, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %84, %30
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %87

36:                                               ; preds = %32
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load float, ptr %37, align 4, !tbaa !11
  %39 = fpext float %38 to double
  %40 = fcmp olt double %39, 0.000000e+00
  br i1 %40, label %41, label %55

41:                                               ; preds = %36
  %42 = load i32, ptr %13, align 4, !tbaa !9
  %43 = load i32, ptr %14, align 4, !tbaa !9
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %51

45:                                               ; preds = %41
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load float, ptr %47, align 4, !tbaa !11
  %49 = fpext float %48 to double
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str.11, double noundef %49) #6
  br label %51

51:                                               ; preds = %45, %41
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  store float 0.000000e+00, ptr %52, align 4, !tbaa !11
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %13, align 4, !tbaa !9
  br label %75

55:                                               ; preds = %36
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = load float, ptr %56, align 4, !tbaa !11
  %58 = fpext float %57 to double
  %59 = fcmp ogt double %58, 1.000000e+00
  br i1 %59, label %60, label %74

60:                                               ; preds = %55
  %61 = load i32, ptr %13, align 4, !tbaa !9
  %62 = load i32, ptr %14, align 4, !tbaa !9
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %64, label %70

64:                                               ; preds = %60
  %65 = load ptr, ptr @stderr, align 8, !tbaa !5
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load float, ptr %66, align 4, !tbaa !11
  %68 = fpext float %67 to double
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %65, ptr noundef @.str.12, double noundef %68) #6
  br label %70

70:                                               ; preds = %64, %60
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  store float 1.000000e+00, ptr %71, align 4, !tbaa !11
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %13, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %70, %55
  br label %75

75:                                               ; preds = %74, %51
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds float, ptr %76, i32 1
  store ptr %77, ptr %10, align 8, !tbaa !5
  %78 = load float, ptr %76, align 4, !tbaa !11
  %79 = fpext float %78 to double
  %80 = call double @llvm.fmuladd.f64(double %79, double 2.550000e+02, double 5.000000e-01)
  %81 = fptoui double %80 to i8
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i32 1
  store ptr %83, ptr %9, align 8, !tbaa !5
  store i8 %81, ptr %82, align 1, !tbaa !13
  br label %84

84:                                               ; preds = %75
  %85 = load i32, ptr %11, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %11, align 4, !tbaa !9
  br label %32, !llvm.loop !14

87:                                               ; preds = %32
  %88 = load i32, ptr %13, align 4, !tbaa !9
  %89 = load i32, ptr %14, align 4, !tbaa !9
  %90 = icmp sge i32 %88, %89
  br i1 %90, label %91, label %98

91:                                               ; preds = %87
  %92 = load ptr, ptr @stderr, align 8, !tbaa !5
  %93 = load i32, ptr %13, align 4, !tbaa !9
  %94 = load i32, ptr %14, align 4, !tbaa !9
  %95 = sub nsw i32 %93, %94
  %96 = add nsw i32 %95, 1
  %97 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %92, ptr noundef @.str.13, i32 noundef %96) #6
  br label %98

98:                                               ; preds = %91, %87
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = call i64 @fwrite(ptr noundef %99, i64 noundef 1, i64 noundef %101, ptr noundef %102)
  %104 = trunc i64 %103 to i32
  store i32 %104, ptr %12, align 4, !tbaa !9
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %105) #6
  %106 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %106, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %107

107:                                              ; preds = %98, %27, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %108 = load i32, ptr %4, align 4
  ret i32 %108
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind allocsize(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 = { "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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [77 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z16write_floatbytesP8_IO_FILEPfi(ptr nocapture noundef %0, ptr nocapture noundef %1, i32 noundef %2) local_unnamed_addr #4 {
  %4 = icmp slt i32 %2, 1
  br i1 %4, label %40, label %5

5:                                                ; preds = %3
  %6 = zext nneg i32 %2 to i64
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %.lr.ph

9:                                                ; preds = %5
  %10 = load ptr, ptr @stderr, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.10) #6
  br label %40

.lr.ph:                                           ; preds = %5, %24
  %.03142 = phi i32 [ %.1, %24 ], [ 0, %5 ]
  %.03241 = phi ptr [ %30, %24 ], [ %7, %5 ]
  %.03340 = phi i32 [ %31, %24 ], [ 0, %5 ]
  %.03439 = phi ptr [ %26, %24 ], [ %1, %5 ]
  %12 = load float, ptr %.03439, align 4, !tbaa !9
  %13 = fpext float %12 to double
  %14 = fcmp olt float %12, 0.000000e+00
  br i1 %14, label %15, label %17

15:                                               ; preds = %.lr.ph
  %16 = icmp slt i32 %.03142, 5
  br i1 %16, label %.sink.split.sink.split, label %.sink.split

17:                                               ; preds = %.lr.ph
  %18 = fcmp ogt float %12, 1.000000e+00
  br i1 %18, label %19, label %24

19:                                               ; preds = %17
  %20 = icmp slt i32 %.03142, 5
  br i1 %20, label %.sink.split.sink.split, label %.sink.split

.sink.split.sink.split:                           ; preds = %19, %15
  %.str.12.sink = phi ptr [ @.str.11, %15 ], [ @.str.12, %19 ]
  %.sink.ph = phi float [ 0.000000e+00, %15 ], [ 1.000000e+00, %19 ]
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull %.str.12.sink, double noundef %13) #6
  br label %.sink.split

.sink.split:                                      ; preds = %.sink.split.sink.split, %19, %15
  %.sink = phi float [ 0.000000e+00, %15 ], [ 1.000000e+00, %19 ], [ %.sink.ph, %.sink.split.sink.split ]
  store float %.sink, ptr %.03439, align 4, !tbaa !9
  %23 = add nsw i32 %.03142, 1
  br label %24

24:                                               ; preds = %.sink.split, %17
  %25 = phi float [ %12, %17 ], [ %.sink, %.sink.split ]
  %.1 = phi i32 [ %.03142, %17 ], [ %23, %.sink.split ]
  %26 = getelementptr inbounds i8, ptr %.03439, i64 4
  %27 = fpext float %25 to double
  %28 = tail call double @llvm.fmuladd.f64(double %27, double 2.550000e+02, double 5.000000e-01)
  %29 = fptoui double %28 to i8
  %30 = getelementptr inbounds i8, ptr %.03241, i64 1
  store i8 %29, ptr %.03241, align 1, !tbaa !11
  %31 = add nuw nsw i32 %.03340, 1
  %exitcond.not = icmp eq i32 %31, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %24
  %32 = icmp sgt i32 %.1, 4
  br i1 %32, label %33, label %37

33:                                               ; preds = %._crit_edge
  %34 = load ptr, ptr @stderr, align 8, !tbaa !5
  %35 = add nsw i32 %.1, -4
  %36 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.13, i32 noundef %35) #6
  br label %37

37:                                               ; preds = %33, %._crit_edge
  %38 = tail call i64 @fwrite(ptr noundef nonnull %7, i64 noundef 1, i64 noundef %6, ptr noundef %0)
  %39 = trunc i64 %38 to i32
  tail call void @free(ptr noundef %7) #7
  br label %40

40:                                               ; preds = %3, %37, %9
  %.0 = phi i32 [ 0, %9 ], [ %39, %37 ], [ 0, %3 ]
  ret i32 %.0
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #5 = { nounwind allocsize(0) }
attributes #6 = { cold nounwind }
attributes #7 = { 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 = !{!"float", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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