; LLVM IR from NotManyIdeasDev/double-pendulum-sim :: double-pendulum-sim/Libraries/raygui-2.8/examples/text_box_selection (GuiTextBoxDelete)

; 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.GuiTextBoxState = type { i32, i32, i32, i32 }

@guiTextBoxState = external hidden global %struct.GuiTextBoxState, 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 uwtable
declare dso_local i32 @GuiTextBoxGetByteIndex(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @GuiTextBoxDelete(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  %12 = zext i1 %2 to i8
  store i8 %12, ptr %7, align 1, !tbaa !11
  %13 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %14 = icmp ne i32 %13, -1
  br i1 %14, label %15, label %108

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %108

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  %19 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !15
  %20 = icmp ne i32 %19, -1
  br i1 %20, label %21, label %47

21:                                               ; preds = %18
  %22 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !15
  %23 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %24 = icmp ne i32 %22, %23
  br i1 %24, label %25, label %47

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %26 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  store i32 %26, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %27 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !15
  store i32 %27, ptr %11, align 4, !tbaa !9
  %28 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %29 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !15
  %30 = icmp sgt i32 %28, %29
  br i1 %30, label %31, label %34

31:                                               ; preds = %25
  %32 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !15
  store i32 %32, ptr %10, align 4, !tbaa !9
  %33 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  store i32 %33, ptr %11, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %31, %25
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = call i32 @GuiTextBoxGetByteIndex(ptr noundef %35, i32 noundef 0, i32 noundef 0, i32 noundef %36)
  store i32 %37, ptr %8, align 4, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = call i32 @GuiTextBoxGetByteIndex(ptr noundef %38, i32 noundef 0, i32 noundef 0, i32 noundef %39)
  store i32 %40, ptr %9, align 4, !tbaa !9
  %41 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %41, ptr @guiTextBoxState, align 4, !tbaa !13
  %42 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !15
  %43 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 1), align 4, !tbaa !16
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %34
  store i32 -1, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 1), align 4, !tbaa !16
  br label %46

46:                                               ; preds = %45, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %84

47:                                               ; preds = %21, %18
  %48 = load i8, ptr %7, align 1, !tbaa !11, !range !17, !noundef !18
  %49 = trunc i8 %48 to i1
  br i1 %49, label %50, label %68

50:                                               ; preds = %47
  %51 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %67

53:                                               ; preds = %50
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %56 = call i32 @GuiTextBoxGetByteIndex(ptr noundef %54, i32 noundef 0, i32 noundef 0, i32 noundef %55)
  store i32 %56, ptr %9, align 4, !tbaa !9
  %57 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr @guiTextBoxState, align 4, !tbaa !13
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %61 = call i32 @GuiTextBoxGetByteIndex(ptr noundef %59, i32 noundef 0, i32 noundef 0, i32 noundef %60)
  store i32 %61, ptr %8, align 4, !tbaa !9
  %62 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %63 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 1), align 4, !tbaa !16
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %65, label %66

65:                                               ; preds = %53
  store i32 -1, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 1), align 4, !tbaa !16
  br label %66

66:                                               ; preds = %65, %53
  br label %67

67:                                               ; preds = %66, %50
  br label %83

68:                                               ; preds = %47
  %69 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %70 = add nsw i32 %69, 1
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = call i32 @GuiCountCodepointsUntilNewline(ptr noundef %71)
  %73 = icmp ule i32 %70, %72
  br i1 %73, label %74, label %82

74:                                               ; preds = %68
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %77 = call i32 @GuiTextBoxGetByteIndex(ptr noundef %75, i32 noundef 0, i32 noundef 0, i32 noundef %76)
  store i32 %77, ptr %8, align 4, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load i32, ptr @guiTextBoxState, align 4, !tbaa !13
  %80 = add nsw i32 %79, 1
  %81 = call i32 @GuiTextBoxGetByteIndex(ptr noundef %78, i32 noundef 0, i32 noundef 0, i32 noundef %80)
  store i32 %81, ptr %9, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %74, %68
  br label %83

83:                                               ; preds = %82, %67
  br label %84

84:                                               ; preds = %83, %46
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i8, ptr %85, i64 %87
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = load i32, ptr %9, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds i8, ptr %89, i64 %91
  %93 = load i32, ptr %6, align 4, !tbaa !9
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = sub nsw i32 %93, %94
  %96 = sext i32 %95 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %88, ptr align 1 %92, i64 %96, i1 false)
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = load i32, ptr %6, align 4, !tbaa !9
  %99 = load i32, ptr %9, align 4, !tbaa !9
  %100 = load i32, ptr %8, align 4, !tbaa !9
  %101 = sub nsw i32 %99, %100
  %102 = sub nsw i32 %98, %101
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i8, ptr %97, i64 %103
  store i8 0, ptr %104, align 1, !tbaa !19
  store i32 -1, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !15
  %105 = load i32, ptr %9, align 4, !tbaa !9
  %106 = load i32, ptr %8, align 4, !tbaa !9
  %107 = sub nsw i32 %105, %106
  store i32 %107, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %109

108:                                              ; preds = %15, %3
  store i32 0, ptr %4, align 4
  br label %109

109:                                              ; preds = %108, %84
  %110 = load i32, ptr %4, align 4
  ret i32 %110
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @GuiCountCodepointsUntilNewline(ptr noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"GuiTextBoxState", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!15 = !{!14, !10, i64 12}
!16 = !{!14, !10, i64 4}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!7, !7, i64 0}


; 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.GuiTextBoxState = type { i32, i32, i32, i32 }

@guiTextBoxState = external hidden local_unnamed_addr global %struct.GuiTextBoxState, align 4

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

; Function Attrs: nounwind uwtable
define dso_local i32 @GuiTextBoxDelete(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @guiTextBoxState, align 4, !tbaa !5
  %5 = icmp ne i32 %4, -1
  %6 = icmp ne ptr %0, null
  %or.cond = and i1 %6, %5
  br i1 %or.cond, label %7, label %46

7:                                                ; preds = %3
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @guiTextBoxState, i64 12), align 4, !tbaa !10
  %.not = icmp eq i32 %8, -1
  %.not33 = icmp eq i32 %8, %4
  %or.cond36 = or i1 %.not, %.not33
  br i1 %or.cond36, label %16, label %9

9:                                                ; preds = %7
  %spec.select = tail call i32 @llvm.smin.i32(i32 %4, i32 %8)
  %spec.select37 = tail call i32 @llvm.smax.i32(i32 %4, i32 %8)
  %10 = tail call i32 @GuiTextBoxGetByteIndex(ptr noundef nonnull %0, i32 noundef 0, i32 noundef 0, i32 noundef %spec.select)
  %11 = tail call i32 @GuiTextBoxGetByteIndex(ptr noundef nonnull %0, i32 noundef 0, i32 noundef 0, i32 noundef %spec.select37)
  store i32 %spec.select, ptr @guiTextBoxState, align 4, !tbaa !5
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @guiTextBoxState, i64 12), align 4, !tbaa !10
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @guiTextBoxState, i64 4), align 4, !tbaa !11
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %35

15:                                               ; preds = %9
  store i32 -1, ptr getelementptr inbounds (i8, ptr @guiTextBoxState, i64 4), align 4, !tbaa !11
  br label %35

16:                                               ; preds = %7
  br i1 %2, label %17, label %27

17:                                               ; preds = %16
  %.not35 = icmp eq i32 %4, 0
  br i1 %.not35, label %35, label %18

18:                                               ; preds = %17
  %19 = tail call i32 @GuiTextBoxGetByteIndex(ptr noundef nonnull %0, i32 noundef 0, i32 noundef 0, i32 noundef %4)
  %20 = load i32, ptr @guiTextBoxState, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr @guiTextBoxState, align 4, !tbaa !5
  %22 = tail call i32 @GuiTextBoxGetByteIndex(ptr noundef nonnull %0, i32 noundef 0, i32 noundef 0, i32 noundef %21)
  %23 = load i32, ptr @guiTextBoxState, align 4, !tbaa !5
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @guiTextBoxState, i64 4), align 4, !tbaa !11
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %35

26:                                               ; preds = %18
  store i32 -1, ptr getelementptr inbounds (i8, ptr @guiTextBoxState, i64 4), align 4, !tbaa !11
  br label %35

27:                                               ; preds = %16
  %28 = tail call i32 @GuiCountCodepointsUntilNewline(ptr noundef nonnull %0)
  %.not34.not = icmp ult i32 %4, %28
  br i1 %.not34.not, label %29, label %35

29:                                               ; preds = %27
  %30 = load i32, ptr @guiTextBoxState, align 4, !tbaa !5
  %31 = tail call i32 @GuiTextBoxGetByteIndex(ptr noundef nonnull %0, i32 noundef 0, i32 noundef 0, i32 noundef %30)
  %32 = load i32, ptr @guiTextBoxState, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  %34 = tail call i32 @GuiTextBoxGetByteIndex(ptr noundef nonnull %0, i32 noundef 0, i32 noundef 0, i32 noundef %33)
  br label %35

35:                                               ; preds = %9, %15, %18, %26, %17, %29, %27
  %.027 = phi i32 [ %22, %26 ], [ %22, %18 ], [ 0, %17 ], [ %31, %29 ], [ 0, %27 ], [ %10, %15 ], [ %10, %9 ]
  %.026 = phi i32 [ %19, %26 ], [ %19, %18 ], [ 0, %17 ], [ %34, %29 ], [ 0, %27 ], [ %11, %15 ], [ %11, %9 ]
  %36 = sext i32 %.027 to i64
  %37 = getelementptr inbounds i8, ptr %0, i64 %36
  %38 = sext i32 %.026 to i64
  %39 = getelementptr inbounds i8, ptr %0, i64 %38
  %40 = sub nsw i32 %1, %.026
  %41 = sext i32 %40 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %37, ptr nonnull align 1 %39, i64 %41, i1 false)
  %42 = sub nsw i32 %.026, %.027
  %43 = sub nsw i32 %1, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %0, i64 %44
  store i8 0, ptr %45, align 1, !tbaa !12
  store i32 -1, ptr getelementptr inbounds (i8, ptr @guiTextBoxState, i64 12), align 4, !tbaa !10
  br label %46

46:                                               ; preds = %3, %35
  %.028 = phi i32 [ %42, %35 ], [ 0, %3 ]
  ret i32 %.028
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @GuiCountCodepointsUntilNewline(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

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 = { inlinehint 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"GuiTextBoxState", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 12}
!11 = !{!6, !7, i64 4}
!12 = !{!8, !8, i64 0}


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