; LLVM IR from facebookresearch/habitat-sim :: src/deps/tinyxml2/tinyxml2.ll (ZN8tinyxml27XMLUtil18ConvertUTF32ToUTF8EmPcPi)

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

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8tinyxml27XMLUtil18ConvertUTF32ToUTF8EmPcPi(i64 noundef %0, ptr noundef %1, ptr noundef %2) #2 align 2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca [7 x i64], align 16
  %10 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 191, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 128, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 56, ptr %9) #3
  call void @llvm.memset.p0.i64(ptr align 16 %9, i8 0, i64 56, i1 false)
  %11 = getelementptr inbounds [7 x i64], ptr %9, i32 0, i32 2
  store i64 192, ptr %11, align 16
  %12 = getelementptr inbounds [7 x i64], ptr %9, i32 0, i32 3
  store i64 224, ptr %12, align 8
  %13 = getelementptr inbounds [7 x i64], ptr %9, i32 0, i32 4
  store i64 240, ptr %13, align 16
  %14 = getelementptr inbounds [7 x i64], ptr %9, i32 0, i32 5
  store i64 248, ptr %14, align 8
  %15 = getelementptr inbounds [7 x i64], ptr %9, i32 0, i32 6
  store i64 252, ptr %15, align 16
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = icmp ult i64 %16, 128
  br i1 %17, label %18, label %20

18:                                               ; preds = %3
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 1, ptr %19, align 4, !tbaa !11
  br label %40

20:                                               ; preds = %3
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = icmp ult i64 %21, 2048
  br i1 %22, label %23, label %25

23:                                               ; preds = %20
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 2, ptr %24, align 4, !tbaa !11
  br label %39

25:                                               ; preds = %20
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = icmp ult i64 %26, 65536
  br i1 %27, label %28, label %30

28:                                               ; preds = %25
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 3, ptr %29, align 4, !tbaa !11
  br label %38

30:                                               ; preds = %25
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = icmp ult i64 %31, 2097152
  br i1 %32, label %33, label %35

33:                                               ; preds = %30
  %34 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 4, ptr %34, align 4, !tbaa !11
  br label %37

35:                                               ; preds = %30
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %36, align 4, !tbaa !11
  store i32 1, ptr %10, align 4
  br label %92

37:                                               ; preds = %33
  br label %38

38:                                               ; preds = %37, %28
  br label %39

39:                                               ; preds = %38, %23
  br label %40

40:                                               ; preds = %39, %18
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = sext i32 %42 to i64
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  store ptr %45, ptr %5, align 8, !tbaa !9
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  %47 = load i32, ptr %46, align 4, !tbaa !11
  switch i32 %47, label %90 [
    i32 4, label %48
    i32 3, label %58
    i32 2, label %68
    i32 1, label %78
  ]

48:                                               ; preds = %40
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = getelementptr inbounds i8, ptr %49, i32 -1
  store ptr %50, ptr %5, align 8, !tbaa !9
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = or i64 %51, 128
  %53 = and i64 %52, 191
  %54 = trunc i64 %53 to i8
  %55 = load ptr, ptr %5, align 8, !tbaa !9
  store i8 %54, ptr %55, align 1, !tbaa !13
  %56 = load i64, ptr %4, align 8, !tbaa !5
  %57 = lshr i64 %56, 6
  store i64 %57, ptr %4, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %48, %40
  %59 = load ptr, ptr %5, align 8, !tbaa !9
  %60 = getelementptr inbounds i8, ptr %59, i32 -1
  store ptr %60, ptr %5, align 8, !tbaa !9
  %61 = load i64, ptr %4, align 8, !tbaa !5
  %62 = or i64 %61, 128
  %63 = and i64 %62, 191
  %64 = trunc i64 %63 to i8
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  store i8 %64, ptr %65, align 1, !tbaa !13
  %66 = load i64, ptr %4, align 8, !tbaa !5
  %67 = lshr i64 %66, 6
  store i64 %67, ptr %4, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %58, %40
  %69 = load ptr, ptr %5, align 8, !tbaa !9
  %70 = getelementptr inbounds i8, ptr %69, i32 -1
  store ptr %70, ptr %5, align 8, !tbaa !9
  %71 = load i64, ptr %4, align 8, !tbaa !5
  %72 = or i64 %71, 128
  %73 = and i64 %72, 191
  %74 = trunc i64 %73 to i8
  %75 = load ptr, ptr %5, align 8, !tbaa !9
  store i8 %74, ptr %75, align 1, !tbaa !13
  %76 = load i64, ptr %4, align 8, !tbaa !5
  %77 = lshr i64 %76, 6
  store i64 %77, ptr %4, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %68, %40
  %79 = load ptr, ptr %5, align 8, !tbaa !9
  %80 = getelementptr inbounds i8, ptr %79, i32 -1
  store ptr %80, ptr %5, align 8, !tbaa !9
  %81 = load i64, ptr %4, align 8, !tbaa !5
  %82 = load ptr, ptr %6, align 8, !tbaa !9
  %83 = load i32, ptr %82, align 4, !tbaa !11
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [7 x i64], ptr %9, i64 0, i64 %84
  %86 = load i64, ptr %85, align 8, !tbaa !5
  %87 = or i64 %81, %86
  %88 = trunc i64 %87 to i8
  %89 = load ptr, ptr %5, align 8, !tbaa !9
  store i8 %88, ptr %89, align 1, !tbaa !13
  br label %91

90:                                               ; preds = %40
  br label %91

91:                                               ; preds = %90, %78
  store i32 0, ptr %10, align 4
  br label %92

92:                                               ; preds = %91, %35
  call void @llvm.lifetime.end.p0(i64 56, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %93 = load i32, ptr %10, align 4
  switch i32 %93, label %95 [
    i32 0, label %94
    i32 1, label %94
  ]

94:                                               ; preds = %92, %92
  ret void

95:                                               ; preds = %92
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!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"

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

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

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN8tinyxml27XMLUtil18ConvertUTF32ToUTF8EmPcPi(i64 noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef %2) local_unnamed_addr #2 align 2 {
  %4 = alloca [7 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %4) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(56) %4, i8 0, i64 16, i1 false)
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store i64 192, ptr %5, align 16
  %6 = getelementptr inbounds i8, ptr %4, i64 24
  store i64 224, ptr %6, align 8
  %7 = getelementptr inbounds i8, ptr %4, i64 32
  store i64 240, ptr %7, align 16
  %8 = getelementptr inbounds i8, ptr %4, i64 40
  store i64 248, ptr %8, align 8
  %9 = getelementptr inbounds i8, ptr %4, i64 48
  store i64 252, ptr %9, align 16
  %10 = icmp ult i64 %0, 128
  br i1 %10, label %18, label %11

11:                                               ; preds = %3
  %12 = icmp ult i64 %0, 2048
  br i1 %12, label %.thread32, label %13

.thread32:                                        ; preds = %11
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %31

13:                                               ; preds = %11
  %14 = icmp ult i64 %0, 65536
  br i1 %14, label %.thread31, label %15

.thread31:                                        ; preds = %13
  store i32 3, ptr %2, align 4, !tbaa !5
  br label %25

15:                                               ; preds = %13
  %16 = icmp ult i64 %0, 2097152
  br i1 %16, label %19, label %17

17:                                               ; preds = %15
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %44

18:                                               ; preds = %3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %38

19:                                               ; preds = %15
  store i32 4, ptr %2, align 4, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %1, i64 3
  %21 = trunc i64 %0 to i8
  %22 = and i8 %21, 63
  %23 = or disjoint i8 %22, -128
  store i8 %23, ptr %20, align 1, !tbaa !9
  %24 = lshr i64 %0, 6
  br label %25

25:                                               ; preds = %.thread31, %19
  %.0 = phi i64 [ %24, %19 ], [ %0, %.thread31 ]
  %26 = getelementptr inbounds i8, ptr %1, i64 2
  %27 = trunc i64 %.0 to i8
  %28 = and i8 %27, 63
  %29 = or disjoint i8 %28, -128
  store i8 %29, ptr %26, align 1, !tbaa !9
  %30 = lshr i64 %.0, 6
  br label %31

31:                                               ; preds = %.thread32, %25
  %.1 = phi i64 [ %30, %25 ], [ %0, %.thread32 ]
  %32 = getelementptr inbounds i8, ptr %1, i64 1
  %33 = trunc i64 %.1 to i8
  %34 = and i8 %33, 63
  %35 = or disjoint i8 %34, -128
  store i8 %35, ptr %32, align 1, !tbaa !9
  %36 = lshr i64 %.1, 6
  %.pre = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %.pre to i64
  br label %38

38:                                               ; preds = %18, %31
  %39 = phi i64 [ 1, %18 ], [ %37, %31 ]
  %.2 = phi i64 [ %0, %18 ], [ %36, %31 ]
  %40 = getelementptr inbounds [7 x i64], ptr %4, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !10
  %42 = or i64 %41, %.2
  %43 = trunc i64 %42 to i8
  store i8 %43, ptr %1, align 1, !tbaa !9
  br label %44

44:                                               ; preds = %38, %17
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %4) #3
  ret void
}

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass