; LLVM IR from vectozavr/3dzavr :: engine/io/microui (microui)

; 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.mu_Rect = type { i32, i32, i32, i32 }
%struct.mu_Vec2 = type { i32, i32 }
%struct.mu_Color = type { i8, i8, i8, i8 }
%struct.mu_Context = type { ptr, ptr, ptr, %struct.mu_Style, ptr, i32, i32, i32, %struct.mu_Rect, i32, i32, i32, ptr, ptr, ptr, [127 x i8], i32, %struct.anon, %struct.anon.0, %struct.anon.1, %struct.anon.2, %struct.anon.3, %struct.anon.4, [48 x %struct.mu_PoolItem], [48 x %struct.mu_Container], [48 x %struct.mu_PoolItem], %struct.mu_Vec2, %struct.mu_Vec2, %struct.mu_Vec2, %struct.mu_Vec2, i32, i32, i32, i32, [32 x i8] }
%struct.mu_Style = type { ptr, %struct.mu_Vec2, i32, i32, i32, i32, i32, i32, [14 x %struct.mu_Color] }
%struct.anon = type { i32, [262144 x i8] }
%struct.anon.0 = type { i32, [32 x ptr] }
%struct.anon.1 = type { i32, [32 x ptr] }
%struct.anon.2 = type { i32, [32 x %struct.mu_Rect] }
%struct.anon.3 = type { i32, [32 x i32] }
%struct.anon.4 = type { i32, [16 x %struct.mu_Layout] }
%struct.mu_Layout = type { %struct.mu_Rect, %struct.mu_Rect, %struct.mu_Vec2, %struct.mu_Vec2, %struct.mu_Vec2, [16 x i32], i32, i32, i32, i32, i32 }
%struct.mu_Container = type { ptr, ptr, %struct.mu_Rect, %struct.mu_Rect, %struct.mu_Vec2, %struct.mu_Vec2, i32, i32 }
%struct.mu_PoolItem = type { i32, i32 }
%struct.mu_TextCommand = type { %struct.mu_BaseCommand, ptr, %struct.mu_Vec2, %struct.mu_Color, [1 x i8] }
%struct.mu_BaseCommand = type { i32, i32 }

@unclipped_rect = external hidden global %struct.mu_Rect, align 4

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @mu_rect(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @mu_get_clip_rect(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @mu_check_clip(ptr noundef, i64, i64) #0

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

; Function Attrs: nounwind uwtable
declare dso_local void @mu_set_clip(ptr noundef, i64, i64) #0

; Function Attrs: nounwind uwtable
define dso_local void @mu_draw_text(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i64 %4, i32 %5) #0 {
  %7 = alloca %struct.mu_Vec2, align 4
  %8 = alloca %struct.mu_Color, align 1
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca %struct.mu_Rect, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca %struct.mu_Rect, align 4
  store i64 %4, ptr %7, align 4
  store i32 %5, ptr %8, align 1
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #4
  %18 = getelementptr inbounds %struct.mu_Vec2, ptr %7, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = getelementptr inbounds %struct.mu_Vec2, ptr %7, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mu_Context, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = call i32 %24(ptr noundef %25, ptr noundef %26, i32 noundef %27)
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mu_Context, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = call i32 %31(ptr noundef %32)
  %34 = call { i64, i64 } @mu_rect(i32 noundef %19, i32 noundef %21, i32 noundef %28, i32 noundef %33)
  %35 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 0
  %36 = extractvalue { i64, i64 } %34, 0
  store i64 %36, ptr %35, align 4
  %37 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 1
  %38 = extractvalue { i64, i64 } %34, 1
  store i64 %38, ptr %37, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 0
  %41 = load i64, ptr %40, align 4
  %42 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 1
  %43 = load i64, ptr %42, align 4
  %44 = call i32 @mu_check_clip(ptr noundef %39, i64 %41, i64 %43)
  store i32 %44, ptr %15, align 4, !tbaa !9
  %45 = load i32, ptr %15, align 4, !tbaa !9
  %46 = icmp eq i32 %45, 2
  br i1 %46, label %47, label %48

47:                                               ; preds = %6
  store i32 1, ptr %16, align 4
  br label %102

48:                                               ; preds = %6
  %49 = load i32, ptr %15, align 4, !tbaa !9
  %50 = icmp eq i32 %49, 1
  br i1 %50, label %51, label %63

51:                                               ; preds = %48
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = call { i64, i64 } @mu_get_clip_rect(ptr noundef %53)
  %55 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 0
  %56 = extractvalue { i64, i64 } %54, 0
  store i64 %56, ptr %55, align 4
  %57 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 1
  %58 = extractvalue { i64, i64 } %54, 1
  store i64 %58, ptr %57, align 4
  %59 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 0
  %60 = load i64, ptr %59, align 4
  %61 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 1
  %62 = load i64, ptr %61, align 4
  call void @mu_set_clip(ptr noundef %52, i64 %60, i64 %62)
  br label %63

63:                                               ; preds = %51, %48
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = icmp slt i32 %64, 0
  br i1 %65, label %66, label %70

66:                                               ; preds = %63
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = call i64 @strlen(ptr noundef %67) #5
  %69 = trunc i64 %68 to i32
  store i32 %69, ptr %12, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %66, %63
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = add i64 32, %73
  %75 = trunc i64 %74 to i32
  %76 = call ptr @mu_push_command(ptr noundef %71, i32 noundef 4, i32 noundef %75)
  store ptr %76, ptr %13, align 8, !tbaa !5
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.mu_TextCommand, ptr %77, i32 0, i32 4
  %79 = getelementptr inbounds [1 x i8], ptr %78, i64 0, i64 0
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load i32, ptr %12, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %79, ptr align 1 %80, i64 %82, i1 false)
  %83 = load ptr, ptr %13, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.mu_TextCommand, ptr %83, i32 0, i32 4
  %85 = load i32, ptr %12, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1 x i8], ptr %84, i64 0, i64 %86
  store i8 0, ptr %87, align 1, !tbaa !21
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.mu_TextCommand, ptr %88, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %89, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !22
  %90 = load ptr, ptr %13, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.mu_TextCommand, ptr %90, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %91, ptr align 1 %8, i64 4, i1 false), !tbaa.struct !23
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = load ptr, ptr %13, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.mu_TextCommand, ptr %93, i32 0, i32 1
  store ptr %92, ptr %94, align 8, !tbaa !21
  %95 = load i32, ptr %15, align 4, !tbaa !9
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %101

97:                                               ; preds = %70
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = load i64, ptr @unclipped_rect, align 4
  %100 = load i64, ptr getelementptr inbounds ({ i64, i64 }, ptr @unclipped_rect, i32 0, i32 1), align 4
  call void @mu_set_clip(ptr noundef %98, i64 %99, i64 %100)
  br label %101

101:                                              ; preds = %97, %70
  store i32 0, ptr %16, align 4
  br label %102

102:                                              ; preds = %101, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %103 = load i32, ptr %16, align 4
  switch i32 %103, label %105 [
    i32 0, label %104
    i32 1, label %104
  ]

104:                                              ; preds = %102, %102
  ret void

105:                                              ; preds = %102
  unreachable
}

attributes #0 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}
!14 = !{!15, !6, i64 0}
!15 = !{!"mu_Context", !6, i64 0, !6, i64 8, !6, i64 16, !16, i64 24, !6, i64 120, !10, i64 128, !10, i64 132, !10, i64 136, !17, i64 140, !10, i64 156, !10, i64 160, !10, i64 164, !6, i64 168, !6, i64 176, !6, i64 184, !7, i64 192, !10, i64 320, !18, i64 324, !19, i64 262472, !19, i64 262736, !18, i64 263000, !18, i64 263516, !18, i64 263648, !7, i64 265892, !7, i64 266280, !7, i64 269736, !12, i64 270120, !12, i64 270128, !12, i64 270136, !12, i64 270144, !10, i64 270152, !10, i64 270156, !10, i64 270160, !10, i64 270164, !7, i64 270168}
!16 = !{!"", !6, i64 0, !12, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!18 = !{!"", !10, i64 0, !7, i64 4}
!19 = !{!"", !10, i64 0, !7, i64 8}
!20 = !{!15, !6, i64 8}
!21 = !{!7, !7, i64 0}
!22 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}
!23 = !{i64 0, i64 1, !21, i64 1, i64 1, !21, i64 2, i64 1, !21, i64 3, i64 1, !21}


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

%struct.mu_Rect = type { i32, i32, i32, i32 }

@unclipped_rect = external hidden local_unnamed_addr global %struct.mu_Rect, align 4

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @mu_rect(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @mu_get_clip_rect(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @mu_check_clip(ptr noundef, i64, i64) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @mu_set_clip(ptr noundef, i64, i64) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @mu_draw_text(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i64 %4, i32 %5) local_unnamed_addr #0 {
  %.sroa.027.0.extract.trunc = trunc i64 %4 to i32
  %.sroa.3.0.extract.shift = lshr i64 %4, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = tail call i32 %7(ptr noundef %1, ptr noundef %2, i32 noundef %3) #3
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  %11 = tail call i32 %10(ptr noundef %1) #3
  %12 = tail call { i64, i64 } @mu_rect(i32 noundef %.sroa.027.0.extract.trunc, i32 noundef %.sroa.3.0.extract.trunc, i32 noundef %8, i32 noundef %11)
  %13 = extractvalue { i64, i64 } %12, 0
  %14 = extractvalue { i64, i64 } %12, 1
  %15 = tail call i32 @mu_check_clip(ptr noundef nonnull %0, i64 %13, i64 %14)
  switch i32 %15, label %20 [
    i32 2, label %37
    i32 1, label %16
  ]

16:                                               ; preds = %6
  %17 = tail call { i64, i64 } @mu_get_clip_rect(ptr noundef nonnull %0)
  %18 = extractvalue { i64, i64 } %17, 0
  %19 = extractvalue { i64, i64 } %17, 1
  tail call void @mu_set_clip(ptr noundef nonnull %0, i64 %18, i64 %19)
  br label %20

20:                                               ; preds = %6, %16
  %21 = icmp slt i32 %3, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %20
  %23 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #4
  %24 = trunc i64 %23 to i32
  br label %25

25:                                               ; preds = %22, %20
  %.0 = phi i32 [ %24, %22 ], [ %3, %20 ]
  %26 = sext i32 %.0 to i64
  %27 = add i32 %.0, 32
  %28 = tail call ptr @mu_push_command(ptr noundef nonnull %0, i32 noundef 4, i32 noundef %27)
  %29 = getelementptr inbounds i8, ptr %28, i64 28
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %29, ptr align 1 %2, i64 %26, i1 false)
  %30 = getelementptr inbounds [1 x i8], ptr %29, i64 0, i64 %26
  store i8 0, ptr %30, align 1, !tbaa !17
  %31 = getelementptr inbounds i8, ptr %28, i64 16
  store i32 %.sroa.027.0.extract.trunc, ptr %31, align 8, !tbaa !18
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %28, i64 20
  store i32 %.sroa.3.0.extract.trunc, ptr %.sroa.3.0..sroa_idx, align 4, !tbaa !18
  %32 = getelementptr inbounds i8, ptr %28, i64 24
  store i32 %5, ptr %32, align 8
  %33 = getelementptr inbounds i8, ptr %28, i64 8
  store ptr %1, ptr %33, align 8, !tbaa !17
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %37, label %34

34:                                               ; preds = %25
  %35 = load i64, ptr @unclipped_rect, align 4
  %36 = load i64, ptr getelementptr inbounds (i8, ptr @unclipped_rect, i64 8), align 4
  tail call void @mu_set_clip(ptr noundef nonnull %0, i64 %35, i64 %36)
  br label %37

37:                                               ; preds = %25, %34, %6
  ret void
}

attributes #0 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nounwind willreturn memory(read) }

!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, !7, i64 0}
!6 = !{!"mu_Context", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 120, !12, i64 128, !12, i64 132, !12, i64 136, !13, i64 140, !12, i64 156, !12, i64 160, !12, i64 164, !7, i64 168, !7, i64 176, !7, i64 184, !8, i64 192, !12, i64 320, !14, i64 324, !15, i64 262472, !15, i64 262736, !14, i64 263000, !14, i64 263516, !14, i64 263648, !8, i64 265892, !8, i64 266280, !8, i64 269736, !11, i64 270120, !11, i64 270128, !11, i64 270136, !11, i64 270144, !12, i64 270152, !12, i64 270156, !12, i64 270160, !12, i64 270164, !8, i64 270168}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !7, i64 0, !11, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !8, i64 40}
!11 = !{!"", !12, i64 0, !12, i64 4}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!14 = !{!"", !12, i64 0, !8, i64 4}
!15 = !{!"", !12, i64 0, !8, i64 8}
!16 = !{!6, !7, i64 8}
!17 = !{!8, !8, i64 0}
!18 = !{!12, !12, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass