; LLVM IR from erwincoumans/tiny-differentiable-simulator :: src/visualizer/opengl/tiny_font_stash.ll (Z19sth_add_bitmap_fontP9sth_stashiii)

; 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.sth_font = type { i32, i32, %struct.stbtt_fontinfo, ptr, ptr, [256 x i32], i32, float, float, float, ptr }
%struct.stbtt_fontinfo = type { ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.sth_stash = type { i32, i32, float, float, ptr, ptr, i32, ptr }

@_ZL3idx = external hidden global i32, align 4

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z19sth_add_bitmap_fontP9sth_stashiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #4 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store ptr null, ptr %12, align 8, !tbaa !5
  %14 = call noalias ptr @malloc(i64 noundef 1128) #6
  store ptr %14, ptr %12, align 8, !tbaa !5
  %15 = load ptr, ptr %12, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  br label %74

18:                                               ; preds = %4
  %19 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %19, i8 0, i64 1128, i1 false)
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %29, %18
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 256
  br i1 %22, label %23, label %32

23:                                               ; preds = %20
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.sth_font, ptr %24, i32 0, i32 5
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [256 x i32], ptr %25, i64 0, i64 %27
  store i32 -1, ptr %28, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %23
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %10, align 4, !tbaa !9
  br label %20, !llvm.loop !11

32:                                               ; preds = %20
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = sub nsw i32 %33, %34
  store i32 %35, ptr %11, align 4, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = sitofp i32 %36 to float
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = sitofp i32 %38 to float
  %40 = fdiv float %37, %39
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.sth_font, ptr %41, i32 0, i32 7
  store float %40, ptr %42, align 4, !tbaa !13
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sitofp i32 %43 to float
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = sitofp i32 %45 to float
  %47 = fdiv float %44, %46
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.sth_font, ptr %48, i32 0, i32 8
  store float %47, ptr %49, align 8, !tbaa !17
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = add nsw i32 %50, %51
  %53 = sitofp i32 %52 to float
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = sitofp i32 %54 to float
  %56 = fdiv float %53, %55
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.sth_font, ptr %57, i32 0, i32 9
  store float %56, ptr %58, align 4, !tbaa !18
  %59 = load i32, ptr @_ZL3idx, align 4, !tbaa !9
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.sth_font, ptr %60, i32 0, i32 0
  store i32 %59, ptr %61, align 8, !tbaa !19
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.sth_font, ptr %62, i32 0, i32 1
  store i32 3, ptr %63, align 4, !tbaa !20
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.sth_stash, ptr %64, i32 0, i32 5
  %66 = load ptr, ptr %65, align 8, !tbaa !21
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.sth_font, ptr %67, i32 0, i32 10
  store ptr %66, ptr %68, align 8, !tbaa !23
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.sth_stash, ptr %70, i32 0, i32 5
  store ptr %69, ptr %71, align 8, !tbaa !21
  %72 = load i32, ptr @_ZL3idx, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr @_ZL3idx, align 4, !tbaa !9
  store i32 %72, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %80

74:                                               ; preds = %17
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %79

77:                                               ; preds = %74
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %78) #5
  br label %79

79:                                               ; preds = %77, %74
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %80

80:                                               ; preds = %79, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %81 = load i32, ptr %5, align 4
  ret i32 %81
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 }
attributes #6 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !16, i64 1108}
!14 = !{!"_ZTS8sth_font", !10, i64 0, !10, i64 4, !15, i64 8, !6, i64 64, !6, i64 72, !7, i64 80, !10, i64 1104, !16, i64 1108, !16, i64 1112, !16, i64 1116, !6, i64 1120}
!15 = !{!"_ZTS14stbtt_fontinfo", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!16 = !{!"float", !7, i64 0}
!17 = !{!14, !16, i64 1112}
!18 = !{!14, !16, i64 1116}
!19 = !{!14, !10, i64 0}
!20 = !{!14, !10, i64 4}
!21 = !{!22, !6, i64 24}
!22 = !{!"_ZTS9sth_stash", !10, i64 0, !10, i64 4, !16, i64 8, !16, i64 12, !6, i64 16, !6, i64 24, !10, i64 32, !6, i64 40}
!23 = !{!14, !6, i64 1120}


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

@_ZL3idx = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: mustprogress nofree nounwind willreturn uwtable
define dso_local noundef i32 @_Z19sth_add_bitmap_fontP9sth_stashiii(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %calloc = tail call dereferenceable_or_null(1128) ptr @calloc(i64 1, i64 1128)
  %5 = icmp eq ptr %calloc, null
  br i1 %5, label %27, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %calloc, i64 80
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1024) %7, i8 -1, i64 1024, i1 false), !tbaa !5
  %8 = sub nsw i32 %1, %2
  %9 = insertelement <2 x i32> poison, i32 %1, i64 0
  %10 = insertelement <2 x i32> %9, i32 %2, i64 1
  %11 = sitofp <2 x i32> %10 to <2 x float>
  %12 = sitofp i32 %8 to float
  %13 = getelementptr inbounds i8, ptr %calloc, i64 1108
  %14 = insertelement <2 x float> poison, float %12, i64 0
  %15 = shufflevector <2 x float> %14, <2 x float> poison, <2 x i32> zeroinitializer
  %16 = fdiv <2 x float> %11, %15
  store <2 x float> %16, ptr %13, align 4, !tbaa !9
  %17 = add nsw i32 %8, %3
  %18 = sitofp i32 %17 to float
  %19 = fdiv float %18, %12
  %20 = getelementptr inbounds i8, ptr %calloc, i64 1116
  store float %19, ptr %20, align 4, !tbaa !11
  %21 = load i32, ptr @_ZL3idx, align 4, !tbaa !5
  store i32 %21, ptr %calloc, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %calloc, i64 4
  store i32 3, ptr %22, align 4, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %calloc, i64 1120
  store ptr %24, ptr %25, align 8, !tbaa !19
  store ptr %calloc, ptr %23, align 8, !tbaa !17
  %26 = add nsw i32 %21, 1
  store i32 %26, ptr @_ZL3idx, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %4, %6
  %.0 = phi i32 [ %21, %6 ], [ 0, %4 ]
  ret i32 %.0
}

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nofree nounwind willreturn 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 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 1116}
!12 = !{!"_ZTS8sth_font", !6, i64 0, !6, i64 4, !13, i64 8, !14, i64 64, !14, i64 72, !7, i64 80, !6, i64 1104, !10, i64 1108, !10, i64 1112, !10, i64 1116, !14, i64 1120}
!13 = !{!"_ZTS14stbtt_fontinfo", !14, i64 0, !14, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !6, i64 4}
!17 = !{!18, !14, i64 24}
!18 = !{!"_ZTS9sth_stash", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 12, !14, i64 16, !14, i64 24, !6, i64 32, !14, i64 40}
!19 = !{!12, !14, i64 1120}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass