; LLVM IR from theck01/offbrand_lib :: src/classes (obstring)

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

@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__.obstring_copy_substring = external hidden unnamed_addr constant [71 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @obstring_create_default() #2

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

; 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
define dso_local ptr @obstring_copy_substring(ptr noundef %0, i64 noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %14

13:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 37, ptr noundef @__PRETTY_FUNCTION__.obstring_copy_substring) #6
  unreachable

14:                                               ; preds = %12
  %15 = call ptr @obstring_create_default()
  store ptr %15, ptr %8, align 8, !tbaa !5
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = icmp slt i64 %16, 0
  br i1 %17, label %18, label %25

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.obstring_struct, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = zext i32 %21 to i64
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = add nsw i64 %23, %22
  store i64 %24, ptr %6, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %18, %14
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = icmp slt i64 %26, 0
  br i1 %27, label %28, label %34

28:                                               ; preds = %25
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = zext i32 %30 to i64
  %32 = add nsw i64 %31, %29
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %7, align 4, !tbaa !11
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %28, %25
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = zext i32 %36 to i64
  %38 = add nsw i64 %35, %37
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.obstring_struct, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !13
  %42 = zext i32 %41 to i64
  %43 = icmp sgt i64 %38, %42
  br i1 %43, label %44, label %52

44:                                               ; preds = %34
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.obstring_struct, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !13
  %48 = zext i32 %47 to i64
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = sub nsw i64 %48, %49
  %51 = trunc i64 %50 to i32
  store i32 %51, ptr %7, align 4, !tbaa !11
  br label %52

52:                                               ; preds = %44, %34
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.obstring_struct, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 8, !tbaa !13
  %57 = zext i32 %56 to i64
  %58 = icmp sgt i64 %53, %57
  br i1 %58, label %73, label %59

59:                                               ; preds = %52
  %60 = load i64, ptr %6, align 8, !tbaa !9
  %61 = load i32, ptr %7, align 4, !tbaa !11
  %62 = zext i32 %61 to i64
  %63 = add nsw i64 %60, %62
  %64 = icmp slt i64 %63, 0
  br i1 %64, label %73, label %65

65:                                               ; preds = %59
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.obstring_struct, ptr %66, i32 0, i32 2
  %68 = load i32, ptr %67, align 8, !tbaa !13
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %73, label %70

70:                                               ; preds = %65
  %71 = load i32, ptr %7, align 4, !tbaa !11
  %72 = icmp ule i32 %71, 0
  br i1 %72, label %73, label %75

73:                                               ; preds = %70, %65, %59, %52
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %74, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %114

75:                                               ; preds = %70
  %76 = load i32, ptr %7, align 4, !tbaa !11
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.obstring_struct, ptr %77, i32 0, i32 2
  store i32 %76, ptr %78, align 8, !tbaa !13
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.obstring_struct, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !15
  %82 = load i32, ptr %7, align 4, !tbaa !11
  %83 = add i32 %82, 1
  %84 = zext i32 %83 to i64
  %85 = mul i64 %84, 1
  %86 = call ptr @realloc(ptr noundef %81, i64 noundef %85) #7
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.obstring_struct, ptr %87, i32 0, i32 1
  store ptr %86, ptr %88, align 8, !tbaa !15
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.obstring_struct, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %90, align 8, !tbaa !15
  %92 = icmp ne ptr %91, null
  br i1 %92, label %93, label %94

93:                                               ; preds = %75
  br label %95

94:                                               ; preds = %75
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 60, ptr noundef @__PRETTY_FUNCTION__.obstring_copy_substring) #6
  unreachable

95:                                               ; preds = %93
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.obstring_struct, ptr %96, i32 0, i32 1
  %98 = load ptr, ptr %97, align 8, !tbaa !15
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.obstring_struct, ptr %99, i32 0, i32 1
  %101 = load ptr, ptr %100, align 8, !tbaa !15
  %102 = load i64, ptr %6, align 8, !tbaa !9
  %103 = getelementptr inbounds i8, ptr %101, i64 %102
  %104 = load i32, ptr %7, align 4, !tbaa !11
  %105 = zext i32 %104 to i64
  %106 = call ptr @strncpy(ptr noundef %98, ptr noundef %103, i64 noundef %105) #5
  %107 = load ptr, ptr %8, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.obstring_struct, ptr %107, i32 0, i32 1
  %109 = load ptr, ptr %108, align 8, !tbaa !15
  %110 = load i32, ptr %7, align 4, !tbaa !11
  %111 = zext i32 %110 to i64
  %112 = getelementptr inbounds i8, ptr %109, i64 %111
  store i8 0, ptr %112, align 1, !tbaa !16
  %113 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %113, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %114

114:                                              ; preds = %95, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %115 = load ptr, ptr %4, align 8
  ret ptr %115
}

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

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

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"obstring_struct", !6, i64 0, !6, i64 8, !12, i64 16}
!15 = !{!14, !6, i64 8}
!16 = !{!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"

@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__.obstring_copy_substring = external hidden unnamed_addr constant [71 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @obstring_create_default() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @obstring_copy_substring(ptr noundef readonly %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %._crit_edge

4:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 37, ptr noundef nonnull @__PRETTY_FUNCTION__.obstring_copy_substring) #5
  unreachable

._crit_edge:                                      ; preds = %3
  %5 = tail call ptr @obstring_create_default()
  %6 = icmp slt i64 %1, 0
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = select i1 %6, i64 %9, i64 0
  %.034 = add nsw i64 %10, %1
  %.135 = tail call i64 @llvm.smax.i64(i64 %.034, i64 0)
  %11 = tail call i64 @llvm.smin.i64(i64 %.034, i64 0)
  %12 = trunc i64 %11 to i32
  %.033 = add i32 %12, %2
  %13 = zext i32 %.033 to i64
  %14 = add nuw nsw i64 %.135, %13
  %15 = icmp ugt i64 %14, %9
  %16 = trunc i64 %.135 to i32
  %17 = sub i32 %8, %16
  %.1 = select i1 %15, i32 %17, i32 %.033
  %18 = icmp sgt i64 %.034, %9
  br i1 %18, label %37, label %19

19:                                               ; preds = %._crit_edge
  %20 = zext i32 %.1 to i64
  %21 = icmp eq i32 %8, 0
  %22 = icmp eq i32 %.1, 0
  %or.cond = or i1 %21, %22
  br i1 %or.cond, label %37, label %23

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %5, i64 16
  store i32 %.1, ptr %24, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %5, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = add i32 %.1, 1
  %28 = zext i32 %27 to i64
  %29 = tail call ptr @realloc(ptr noundef %26, i64 noundef %28) #6
  store ptr %29, ptr %25, align 8, !tbaa !11
  %.not40 = icmp eq ptr %29, null
  br i1 %.not40, label %30, label %31

30:                                               ; preds = %23
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 60, ptr noundef nonnull @__PRETTY_FUNCTION__.obstring_copy_substring) #5
  unreachable

31:                                               ; preds = %23
  %32 = getelementptr inbounds i8, ptr %0, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %33, i64 %.135
  %35 = tail call ptr @strncpy(ptr noundef nonnull %29, ptr noundef %34, i64 noundef %20) #7
  %36 = getelementptr inbounds i8, ptr %29, i64 %20
  store i8 0, ptr %36, align 1, !tbaa !12
  br label %37

37:                                               ; preds = %._crit_edge, %19, %31
  ret ptr %5
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #3

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

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

attributes #0 = { 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 #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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #3 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { noreturn nounwind }
attributes #6 = { nounwind allocsize(1) }
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, !10, i64 16}
!6 = !{!"obstring_struct", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!8, !8, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass