; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Compress (Lzma2Encoder)

; 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.tagPROPVARIANT = type { i16, i16, i16, i16, %union.anon }
%union.anon = type { %struct._LARGE_INTEGER }
%struct._LARGE_INTEGER = type { i64 }
%struct.CLzma2EncProps = type { %struct._CLzmaEncProps, i64, i32, i32, i32 }
%struct._CLzmaEncProps = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64 }
%struct._ULARGE_INTEGER = type { i64 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9NCompress6NLzma212SetLzma2PropEjRK14tagPROPVARIANTR14CLzma2EncProps(i32 noundef %0, ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(80) %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !5
  switch i32 %10, label %53 [
    i32 4, label %11
    i32 13, label %40
  ]

11:                                               ; preds = %3
  %12 = load ptr, ptr %6, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %12, i32 0, i32 0
  %14 = load i16, ptr %13, align 8, !tbaa !11
  %15 = zext i16 %14 to i32
  %16 = icmp eq i32 %15, 19
  br i1 %16, label %17, label %24

17:                                               ; preds = %11
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %18, i32 0, i32 4
  %20 = load i32, ptr %19, align 8, !tbaa !14
  %21 = zext i32 %20 to i64
  %22 = load ptr, ptr %7, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.CLzma2EncProps, ptr %22, i32 0, i32 1
  store i64 %21, ptr %23, align 8, !tbaa !15
  br label %39

24:                                               ; preds = %11
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %25, i32 0, i32 0
  %27 = load i16, ptr %26, align 8, !tbaa !11
  %28 = zext i16 %27 to i32
  %29 = icmp eq i32 %28, 21
  br i1 %29, label %30, label %37

30:                                               ; preds = %24
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %31, i32 0, i32 4
  %33 = getelementptr inbounds %struct._ULARGE_INTEGER, ptr %32, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.CLzma2EncProps, ptr %35, i32 0, i32 1
  store i64 %34, ptr %36, align 8, !tbaa !15
  br label %38

37:                                               ; preds = %24
  store i32 -2147024809, ptr %4, align 4
  br label %68

38:                                               ; preds = %30
  br label %39

39:                                               ; preds = %38, %17
  br label %67

40:                                               ; preds = %3
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %41, i32 0, i32 0
  %43 = load i16, ptr %42, align 8, !tbaa !11
  %44 = zext i16 %43 to i32
  %45 = icmp ne i32 %44, 19
  br i1 %45, label %46, label %47

46:                                               ; preds = %40
  store i32 -2147024809, ptr %4, align 4
  br label %68

47:                                               ; preds = %40
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %48, i32 0, i32 4
  %50 = load i32, ptr %49, align 8, !tbaa !14
  %51 = load ptr, ptr %7, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.CLzma2EncProps, ptr %51, i32 0, i32 4
  store i32 %50, ptr %52, align 8, !tbaa !19
  br label %67

53:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = load ptr, ptr %6, align 8, !tbaa !9
  %56 = load ptr, ptr %7, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.CLzma2EncProps, ptr %56, i32 0, i32 0
  %58 = call noundef i32 @_ZN9NCompress5NLzma11SetLzmaPropEjRK14tagPROPVARIANTR14_CLzmaEncProps(i32 noundef %54, ptr noundef nonnull align 8 dereferenceable(16) %55, ptr noundef nonnull align 8 dereferenceable(56) %57)
  store i32 %58, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !5
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %63

61:                                               ; preds = %53
  %62 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %62, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %64

63:                                               ; preds = %53
  store i32 0, ptr %9, align 4
  br label %64

64:                                               ; preds = %63, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %65 = load i32, ptr %9, align 4
  switch i32 %65, label %70 [
    i32 0, label %66
    i32 1, label %68
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66, %47, %39
  store i32 0, ptr %4, align 4
  br label %68

68:                                               ; preds = %67, %64, %46, %37
  %69 = load i32, ptr %4, align 4
  ret i32 %69

70:                                               ; preds = %64
  unreachable
}

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

declare noundef i32 @_ZN9NCompress5NLzma11SetLzmaPropEjRK14tagPROPVARIANTR14_CLzmaEncProps(i32 noundef, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(56)) #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 = { "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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS14tagPROPVARIANT", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !18, i64 56}
!16 = !{!"_ZTS14CLzma2EncProps", !17, i64 0, !18, i64 56, !6, i64 64, !6, i64 68, !6, i64 72}
!17 = !{!"_ZTS14_CLzmaEncProps", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !18, i64 48}
!18 = !{!"long long", !7, i64 0}
!19 = !{!16, !6, i64 72}


; 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 uwtable
define dso_local noundef i32 @_ZN9NCompress6NLzma212SetLzma2PropEjRK14tagPROPVARIANTR14CLzma2EncProps(i32 noundef %0, ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(80) %2) local_unnamed_addr #0 {
  switch i32 %0, label %21 [
    i32 4, label %4
    i32 13, label %15
  ]

4:                                                ; preds = %3
  %5 = load i16, ptr %1, align 8, !tbaa !5
  switch i16 %5, label %24 [
    i16 19, label %6
    i16 21, label %11
  ]

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !10
  %9 = zext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %2, i64 56
  store i64 %9, ptr %10, align 8, !tbaa !11
  br label %23

11:                                               ; preds = %4
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %2, i64 56
  store i64 %13, ptr %14, align 8, !tbaa !11
  br label %23

15:                                               ; preds = %3
  %16 = load i16, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i16 %16, 19
  br i1 %.not, label %17, label %24

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = load i32, ptr %18, align 8, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %2, i64 72
  store i32 %19, ptr %20, align 8, !tbaa !16
  br label %23

21:                                               ; preds = %3
  %22 = tail call noundef i32 @_ZN9NCompress5NLzma11SetLzmaPropEjRK14tagPROPVARIANTR14_CLzmaEncProps(i32 noundef %0, ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(56) %2)
  %.not18.not = icmp eq i32 %22, 0
  br i1 %.not18.not, label %23, label %24

23:                                               ; preds = %21, %6, %11, %17
  br label %24

24:                                               ; preds = %21, %15, %4, %23
  %.1 = phi i32 [ %22, %21 ], [ 0, %23 ], [ -2147024809, %4 ], [ -2147024809, %15 ]
  ret i32 %.1
}

declare noundef i32 @_ZN9NCompress5NLzma11SetLzmaPropEjRK14tagPROPVARIANTR14_CLzmaEncProps(i32 noundef, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #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 = { "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 = !{!"_ZTS14tagPROPVARIANT", !7, i64 0, !7, i64 2, !7, i64 4, !7, i64 6, !8, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !15, i64 56}
!12 = !{!"_ZTS14CLzma2EncProps", !13, i64 0, !15, i64 56, !14, i64 64, !14, i64 68, !14, i64 72}
!13 = !{!"_ZTS14_CLzmaEncProps", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44, !15, i64 48}
!14 = !{!"int", !8, i64 0}
!15 = !{!"long long", !8, i64 0}
!16 = !{!12, !14, i64 72}


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