; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.2/lzma465/CPP/7zip/Common (MethodId)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z23ConvertMethodIdToStringy(ptr dead_on_unwind noalias writable sret(%class.CStringBase) align 8 %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca [32 x i32], align 16
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store i64 %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 128, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 32, ptr %6, align 4, !tbaa !9
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr %6, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [32 x i32], ptr %5, i64 0, i64 %9
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %36, %2
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = trunc i64 %12 to i8
  %14 = zext i8 %13 to i32
  %15 = and i32 %14, 15
  %16 = trunc i32 %15 to i8
  %17 = call noundef signext i32 @_ZL6GetHexh(i8 noundef zeroext %16)
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %6, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [32 x i32], ptr %5, i64 0, i64 %20
  store i32 %17, ptr %21, align 4, !tbaa !11
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = lshr i64 %22, 4
  store i64 %23, ptr %4, align 8, !tbaa !5
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = trunc i64 %24 to i8
  %26 = zext i8 %25 to i32
  %27 = and i32 %26, 15
  %28 = trunc i32 %27 to i8
  %29 = call noundef signext i32 @_ZL6GetHexh(i8 noundef zeroext %28)
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %6, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [32 x i32], ptr %5, i64 0, i64 %32
  store i32 %29, ptr %33, align 4, !tbaa !11
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = lshr i64 %34, 4
  store i64 %35, ptr %4, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %11
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %11, label %39, !llvm.loop !13

39:                                               ; preds = %36
  %40 = getelementptr inbounds [32 x i32], ptr %5, i64 0, i64 0
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %40, i64 %42
  call void @_ZN11CStringBaseIwEC2EPKw(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %43)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr %5) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef signext i32 @_ZL6GetHexh(i8 noundef zeroext) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11CStringBaseIwEC2EPKw(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #0 align 2

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"wchar_t", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

%class.CStringBase = type { ptr, i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z23ConvertMethodIdToStringy(ptr dead_on_unwind noalias writable sret(%class.CStringBase) align 8 %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [32 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %3, i64 124
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %5, %2
  %indvars.iv = phi i64 [ %indvars.iv.next, %5 ], [ 31, %2 ]
  %.09 = phi i64 [ %14, %5 ], [ %1, %2 ]
  %6 = trunc i64 %.09 to i8
  %7 = and i8 %6, 15
  %8 = tail call noundef signext i32 @_ZL6GetHexh(i8 noundef zeroext %7)
  %9 = add nsw i64 %indvars.iv, -1
  %10 = getelementptr inbounds [32 x i32], ptr %3, i64 0, i64 %9
  store i32 %8, ptr %10, align 4, !tbaa !5
  %11 = lshr i8 %6, 4
  %12 = tail call noundef signext i32 @_ZL6GetHexh(i8 noundef zeroext %11)
  %indvars.iv.next = add nsw i64 %indvars.iv, -2
  %13 = getelementptr inbounds [32 x i32], ptr %3, i64 0, i64 %indvars.iv.next
  store i32 %12, ptr %13, align 4, !tbaa !5
  %14 = lshr i64 %.09, 8
  %.not = icmp ult i64 %.09, 256
  br i1 %.not, label %15, label %5, !llvm.loop !9

15:                                               ; preds = %5
  %16 = getelementptr inbounds [32 x i32], ptr %3, i64 0, i64 %indvars.iv.next
  call void @_ZN11CStringBaseIwEC2EPKw(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull %16)
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef signext i32 @_ZL6GetHexh(i8 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11CStringBaseIwEC2EPKw(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #0 align 2

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

attributes #0 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = !{!"wchar_t", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass