; LLVM IR from niessner/Matterport :: code/gaps/pkgs/RNBasics/json.ll (ZN4Json5Value8CZStringC2ERKS1_)

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

%"class.Json::Value::CZString" = type <{ ptr, %union.anon.35, [4 x i8] }>
%union.anon.35 = type { i32 }

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef ptr @_ZN4JsonL20duplicateStringValueEPKcm(ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Json5Value8CZStringC2ERKS1_(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull align 8 dereferenceable(12) %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"class.Json::Value::CZString", ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %"class.Json::Value::CZString", ptr %7, i32 0, i32 1
  %9 = load i32, ptr %8, align 8
  %10 = and i32 %9, 3
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %27

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %"class.Json::Value::CZString", ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %27

17:                                               ; preds = %12
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.Json::Value::CZString", ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.Json::Value::CZString", ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 8
  %24 = lshr i32 %23, 2
  %25 = zext i32 %24 to i64
  %26 = call noundef ptr @_ZN4JsonL20duplicateStringValueEPKcm(ptr noundef %20, i64 noundef %25)
  br label %31

27:                                               ; preds = %12, %2
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.Json::Value::CZString", ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %27, %17
  %32 = phi ptr [ %26, %17 ], [ %30, %27 ]
  store ptr %32, ptr %6, align 8, !tbaa !9
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.Json::Value::CZString", ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %45

37:                                               ; preds = %31
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.Json::Value::CZString", ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 8
  %41 = and i32 %40, 3
  %42 = icmp eq i32 %41, 0
  %43 = zext i1 %42 to i64
  %44 = select i1 %42, i32 0, i32 1
  br label %50

45:                                               ; preds = %31
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %"class.Json::Value::CZString", ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 8
  %49 = and i32 %48, 3
  br label %50

50:                                               ; preds = %45, %37
  %51 = phi i32 [ %44, %37 ], [ %49, %45 ]
  %52 = getelementptr inbounds %"class.Json::Value::CZString", ptr %5, i32 0, i32 1
  %53 = load i32, ptr %52, align 8
  %54 = and i32 %51, 3
  %55 = and i32 %53, -4
  %56 = or i32 %55, %54
  store i32 %56, ptr %52, align 8
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %"class.Json::Value::CZString", ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 8
  %60 = lshr i32 %59, 2
  %61 = getelementptr inbounds %"class.Json::Value::CZString", ptr %5, i32 0, i32 1
  %62 = load i32, ptr %61, align 8
  %63 = and i32 %60, 1073741823
  %64 = shl i32 %63, 2
  %65 = and i32 %62, 3
  %66 = or i32 %65, %64
  store i32 %66, ptr %61, align 8
  ret void
}

attributes #0 = { inlinehint mustprogress 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 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" }

!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, !6, i64 0}
!10 = !{!"_ZTSN4Json5Value8CZStringE", !6, i64 0, !7, i64 8}


; 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: inlinehint mustprogress uwtable
declare hidden noundef ptr @_ZN4JsonL20duplicateStringValueEPKcm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Json5Value8CZStringC2ERKS1_(ptr nocapture noundef nonnull align 8 dereferenceable(12) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(12) %1) unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load i32, ptr %3, align 8
  %5 = and i32 %4, 3
  %.not = icmp eq i32 %5, 0
  %.pre = load ptr, ptr %1, align 8, !tbaa !5
  br i1 %.not, label %11, label %6

6:                                                ; preds = %2
  %.not10 = icmp eq ptr %.pre, null
  br i1 %.not10, label %11, label %7

7:                                                ; preds = %6
  %8 = lshr i32 %4, 2
  %9 = zext nneg i32 %8 to i64
  %10 = tail call noundef ptr @_ZN4JsonL20duplicateStringValueEPKcm(ptr noundef nonnull %.pre, i64 noundef %9)
  br label %11

11:                                               ; preds = %2, %6, %7
  %12 = phi ptr [ %10, %7 ], [ null, %6 ], [ %.pre, %2 ]
  store ptr %12, ptr %0, align 8, !tbaa !5
  %13 = load ptr, ptr %1, align 8, !tbaa !5
  %.not11 = icmp eq ptr %13, null
  %14 = load i32, ptr %3, align 8
  %15 = and i32 %14, 3
  %16 = icmp ne i32 %15, 0
  %17 = zext i1 %16 to i32
  %18 = select i1 %.not11, i32 %15, i32 %17
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load i32, ptr %19, align 8
  %21 = and i32 %20, -4
  %22 = or disjoint i32 %21, %18
  store i32 %22, ptr %19, align 8
  %23 = load i32, ptr %3, align 8
  %24 = and i32 %23, -4
  %25 = or disjoint i32 %24, %18
  store i32 %25, ptr %19, align 8
  ret void
}

attributes #0 = { inlinehint mustprogress 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 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" }

!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 = !{!"_ZTSN4Json5Value8CZStringE", !7, i64 0, !8, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


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