; LLVM IR from wumo/vkg :: src/par/test (lz4)

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

; 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: alwaysinline nounwind uwtable
declare hidden i32 @LZ4_decompress_generic(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @LZ4_decompress_safe_continue(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %15, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %16 = load ptr, ptr %12, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr %18, %19
  br i1 %20, label %21, label %58

21:                                               ; preds = %5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %29, i32 0, i32 3
  %31 = load i64, ptr %30, align 8, !tbaa !14
  %32 = sub i64 0, %31
  %33 = getelementptr inbounds i8, ptr %28, i64 %32
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !16
  %40 = call i32 @LZ4_decompress_generic(ptr noundef %22, ptr noundef %23, i32 noundef %24, i32 noundef %25, i32 noundef 1, i32 noundef 0, i32 noundef 0, i32 noundef 2, ptr noundef %33, ptr noundef %36, i64 noundef %39)
  store i32 %40, ptr %13, align 4, !tbaa !9
  %41 = load i32, ptr %13, align 4, !tbaa !9
  %42 = icmp sle i32 %41, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %21
  %44 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %44, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %103

45:                                               ; preds = %21
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %48, i32 0, i32 3
  %50 = load i64, ptr %49, align 8, !tbaa !14
  %51 = add i64 %50, %47
  store i64 %51, ptr %49, align 8, !tbaa !14
  %52 = load i32, ptr %13, align 4, !tbaa !9
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = sext i32 %52 to i64
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  store ptr %57, ptr %54, align 8, !tbaa !11
  br label %101

58:                                               ; preds = %5
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %59, i32 0, i32 3
  %61 = load i64, ptr %60, align 8, !tbaa !14
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %62, i32 0, i32 1
  store i64 %61, ptr %63, align 8, !tbaa !16
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %67, i32 0, i32 1
  %69 = load i64, ptr %68, align 8, !tbaa !16
  %70 = sub i64 0, %69
  %71 = getelementptr inbounds i8, ptr %66, i64 %70
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %72, i32 0, i32 0
  store ptr %71, ptr %73, align 8, !tbaa !15
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !15
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %82, i32 0, i32 1
  %84 = load i64, ptr %83, align 8, !tbaa !16
  %85 = call i32 @LZ4_decompress_generic(ptr noundef %74, ptr noundef %75, i32 noundef %76, i32 noundef %77, i32 noundef 1, i32 noundef 0, i32 noundef 0, i32 noundef 2, ptr noundef %78, ptr noundef %81, i64 noundef %84)
  store i32 %85, ptr %13, align 4, !tbaa !9
  %86 = load i32, ptr %13, align 4, !tbaa !9
  %87 = icmp sle i32 %86, 0
  br i1 %87, label %88, label %90

88:                                               ; preds = %58
  %89 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %89, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %103

90:                                               ; preds = %58
  %91 = load i32, ptr %13, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = load ptr, ptr %12, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %93, i32 0, i32 3
  store i64 %92, ptr %94, align 8, !tbaa !14
  %95 = load ptr, ptr %9, align 8, !tbaa !5
  %96 = load i32, ptr %13, align 4, !tbaa !9
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i8, ptr %95, i64 %97
  %99 = load ptr, ptr %12, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.LZ4_streamDecode_t_internal, ptr %99, i32 0, i32 2
  store ptr %98, ptr %100, align 8, !tbaa !11
  br label %101

101:                                              ; preds = %90, %45
  %102 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %102, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %103

103:                                              ; preds = %101, %88, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %104 = load i32, ptr %6, align 4
  ret i32 %104
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 = { 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 = !{!"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 = !{!12, !6, i64 16}
!12 = !{!"", !6, i64 0, !13, i64 8, !6, i64 16, !13, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 24}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !13, 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: alwaysinline nounwind uwtable
declare hidden i32 @LZ4_decompress_generic(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @LZ4_decompress_safe_continue(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp eq ptr %7, %2
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load i64, ptr %9, align 8, !tbaa !11
  br i1 %8, label %11, label %25

11:                                               ; preds = %5
  %12 = sub i64 0, %10
  %13 = getelementptr inbounds i8, ptr %7, i64 %12
  %14 = load ptr, ptr %0, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !13
  %17 = tail call i32 @LZ4_decompress_generic(ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef 1, i32 noundef 0, i32 noundef 0, i32 noundef 2, ptr noundef %13, ptr noundef %14, i64 noundef %16)
  %18 = icmp slt i32 %17, 1
  br i1 %18, label %35, label %19

19:                                               ; preds = %11
  %20 = zext nneg i32 %17 to i64
  %21 = load i64, ptr %9, align 8, !tbaa !11
  %22 = add i64 %21, %20
  store i64 %22, ptr %9, align 8, !tbaa !11
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 %20
  br label %34

25:                                               ; preds = %5
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %10, ptr %26, align 8, !tbaa !13
  %27 = sub i64 0, %10
  %28 = getelementptr inbounds i8, ptr %7, i64 %27
  store ptr %28, ptr %0, align 8, !tbaa !12
  %29 = tail call i32 @LZ4_decompress_generic(ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef 1, i32 noundef 0, i32 noundef 0, i32 noundef 2, ptr noundef %2, ptr noundef %28, i64 noundef %10)
  %30 = icmp slt i32 %29, 1
  br i1 %30, label %35, label %31

31:                                               ; preds = %25
  %32 = zext nneg i32 %29 to i64
  store i64 %32, ptr %9, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %2, i64 %32
  br label %34

34:                                               ; preds = %31, %19
  %storemerge = phi ptr [ %33, %31 ], [ %24, %19 ]
  %.0 = phi i32 [ %29, %31 ], [ %17, %19 ]
  store ptr %storemerge, ptr %6, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %25, %11, %34
  %.037 = phi i32 [ %.0, %34 ], [ %17, %11 ], [ %29, %25 ]
  ret i32 %.037
}

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

!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 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 8}


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