; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/C (XzIn)

; 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: nounwind uwtable
define dso_local i32 @XzBlock_ReadHeader(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [1024 x i8], align 16
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1024, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %18 = call i32 @SeqInStream_ReadByte(ptr noundef %16, ptr noundef %17)
  store i32 %18, ptr %12, align 4, !tbaa !9
  %19 = load i32, ptr %12, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %4
  %22 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %22, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %24

23:                                               ; preds = %4
  store i32 0, ptr %13, align 4
  br label %24

24:                                               ; preds = %23, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %25 = load i32, ptr %13, align 4
  switch i32 %25, label %60 [
    i32 0, label %26
  ]

26:                                               ; preds = %24
  %27 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %28 = load i8, ptr %27, align 16, !tbaa !11
  %29 = zext i8 %28 to i32
  store i32 %29, ptr %11, align 4, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %26
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 1, ptr %33, align 4, !tbaa !9
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 1, ptr %34, align 4, !tbaa !9
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %60

35:                                               ; preds = %26
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %36, align 4, !tbaa !9
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = shl i32 %37, 2
  %39 = add i32 %38, 4
  store i32 %39, ptr %11, align 4, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %40, ptr %41, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %44 = getelementptr inbounds i8, ptr %43, i64 1
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = sub i32 %45, 1
  %47 = zext i32 %46 to i64
  %48 = call i32 @SeqInStream_Read(ptr noundef %42, ptr noundef %44, i64 noundef %47)
  store i32 %48, ptr %14, align 4, !tbaa !9
  %49 = load i32, ptr %14, align 4, !tbaa !9
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %35
  %52 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %52, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %54

53:                                               ; preds = %35
  store i32 0, ptr %13, align 4
  br label %54

54:                                               ; preds = %53, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %55 = load i32, ptr %13, align 4
  switch i32 %55, label %60 [
    i32 0, label %56
  ]

56:                                               ; preds = %54
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %59 = call i32 @XzBlock_Parse(ptr noundef %57, ptr noundef %58)
  store i32 %59, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %60

60:                                               ; preds = %56, %54, %32, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1024, ptr %10) #3
  %61 = load i32, ptr %5, align 4
  ret i32 %61
}

declare i32 @SeqInStream_ReadByte(ptr noundef, ptr noundef) #2

declare i32 @SeqInStream_Read(ptr noundef, ptr noundef, i64 noundef) #2

declare i32 @XzBlock_Parse(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!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: nounwind uwtable
define dso_local i32 @XzBlock_ReadHeader(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = alloca [1024 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %5) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  %6 = call i32 @SeqInStream_ReadByte(ptr noundef %1, ptr noundef nonnull %5) #3
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %21

7:                                                ; preds = %4
  %8 = load i8, ptr %5, align 16, !tbaa !9
  %9 = icmp eq i8 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %7
  store i32 1, ptr %3, align 4, !tbaa !5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %21

11:                                               ; preds = %7
  %12 = zext i8 %8 to i32
  store i32 0, ptr %2, align 4, !tbaa !5
  %13 = shl nuw nsw i32 %12, 2
  %14 = add nuw nsw i32 %13, 4
  store i32 %14, ptr %3, align 4, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %5, i64 1
  %16 = or disjoint i32 %13, 3
  %17 = zext nneg i32 %16 to i64
  %18 = call i32 @SeqInStream_Read(ptr noundef %1, ptr noundef nonnull %15, i64 noundef %17) #3
  %.not22 = icmp eq i32 %18, 0
  br i1 %.not22, label %19, label %21

19:                                               ; preds = %11
  %20 = call i32 @XzBlock_Parse(ptr noundef %0, ptr noundef nonnull %5) #3
  br label %21

21:                                               ; preds = %11, %4, %19, %10
  %.2 = phi i32 [ 0, %10 ], [ %20, %19 ], [ %18, %11 ], [ %6, %4 ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %5) #3
  ret i32 %.2
}

declare i32 @SeqInStream_ReadByte(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @SeqInStream_Read(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @XzBlock_Parse(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass