; 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_stream_t_internal = type { [4096 x i32], i32, i32, ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @LZ4_resetStream(ptr noundef) #0

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

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

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

23:                                               ; preds = %3
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !13
  %27 = icmp ugt i32 %26, 1073741824
  br i1 %27, label %28, label %30

28:                                               ; preds = %23, %3
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  call void @LZ4_resetStream(ptr noundef %29)
  br label %30

30:                                               ; preds = %28, %23
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 8
  br i1 %32, label %33, label %38

33:                                               ; preds = %30
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %34, i32 0, i32 3
  store ptr null, ptr %35, align 8, !tbaa !14
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %36, i32 0, i32 5
  store i32 0, ptr %37, align 8, !tbaa !15
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %95

38:                                               ; preds = %30
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = ptrtoint ptr %39 to i64
  %42 = ptrtoint ptr %40 to i64
  %43 = sub i64 %41, %42
  %44 = icmp sgt i64 %43, 65536
  br i1 %44, label %45, label %48

45:                                               ; preds = %38
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 -65536
  store ptr %47, ptr %9, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %45, %38
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 8, !tbaa !13
  %52 = add i32 %51, 65536
  store i32 %52, ptr %50, align 8, !tbaa !13
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 8, !tbaa !13
  %57 = zext i32 %56 to i64
  %58 = sub i64 0, %57
  %59 = getelementptr inbounds i8, ptr %53, i64 %58
  store ptr %59, ptr %11, align 8, !tbaa !5
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %61, i32 0, i32 3
  store ptr %60, ptr %62, align 8, !tbaa !14
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = ptrtoint ptr %63 to i64
  %66 = ptrtoint ptr %64 to i64
  %67 = sub i64 %65, %66
  %68 = trunc i64 %67 to i32
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %69, i32 0, i32 5
  store i32 %68, ptr %70, align 8, !tbaa !15
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %71, i32 0, i32 5
  %73 = load i32, ptr %72, align 8, !tbaa !15
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 8, !tbaa !13
  %77 = add i32 %76, %73
  store i32 %77, ptr %75, align 8, !tbaa !13
  br label %78

78:                                               ; preds = %83, %48
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 -8
  %82 = icmp ule ptr %79, %81
  br i1 %82, label %83, label %91

83:                                               ; preds = %78
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %85, i32 0, i32 0
  %87 = getelementptr inbounds [4096 x i32], ptr %86, i64 0, i64 0
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  call void @LZ4_putPosition(ptr noundef %84, ptr noundef %87, i32 noundef 1, ptr noundef %88)
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i64 3
  store ptr %90, ptr %9, align 8, !tbaa !5
  br label %78, !llvm.loop !16

91:                                               ; preds = %78
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.LZ4_stream_t_internal, ptr %92, i32 0, i32 5
  %94 = load i32, ptr %93, align 8, !tbaa !15
  store i32 %94, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %95

95:                                               ; preds = %91, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %96 = load i32, ptr %4, align 4
  ret i32 %96
}

; Function Attrs: nounwind uwtable
declare hidden void @LZ4_putPosition(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !10, i64 16388}
!12 = !{!"", !7, i64 0, !10, i64 16384, !10, i64 16388, !6, i64 16392, !6, i64 16400, !10, i64 16408}
!13 = !{!12, !10, i64 16384}
!14 = !{!12, !6, i64 16392}
!15 = !{!12, !10, i64 16408}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local void @LZ4_resetStream(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @LZ4_loadDict(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %2 to i64
  %5 = getelementptr inbounds i8, ptr %1, i64 %4
  %6 = getelementptr inbounds i8, ptr %0, i64 16388
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %12

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 16384
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp ugt i32 %10, 1073741824
  br i1 %11, label %12, label %13

12:                                               ; preds = %8, %3
  tail call void @LZ4_resetStream(ptr noundef nonnull %0)
  br label %13

13:                                               ; preds = %12, %8
  %14 = icmp slt i32 %2, 8
  br i1 %14, label %15, label %18

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %0, i64 16392
  store ptr null, ptr %16, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %0, i64 16408
  store i32 0, ptr %17, align 8, !tbaa !13
  br label %._crit_edge

18:                                               ; preds = %13
  %19 = ptrtoint ptr %5 to i64
  %20 = icmp ugt i32 %2, 65536
  %21 = getelementptr inbounds i8, ptr %5, i64 -65536
  %spec.select = select i1 %20, ptr %21, ptr %1
  %22 = getelementptr inbounds i8, ptr %0, i64 16384
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = add i32 %23, 65536
  %25 = zext i32 %24 to i64
  %26 = sub nsw i64 0, %25
  %27 = getelementptr inbounds i8, ptr %spec.select, i64 %26
  %28 = getelementptr inbounds i8, ptr %0, i64 16392
  store ptr %spec.select, ptr %28, align 8, !tbaa !12
  %29 = ptrtoint ptr %spec.select to i64
  %30 = sub i64 %19, %29
  %31 = trunc i64 %30 to i32
  %32 = getelementptr inbounds i8, ptr %0, i64 16408
  store i32 %31, ptr %32, align 8, !tbaa !13
  %33 = add i32 %24, %31
  store i32 %33, ptr %22, align 8, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %5, i64 -8
  %.not3132 = icmp ugt ptr %spec.select, %34
  br i1 %.not3132, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %18, %.lr.ph
  %.133 = phi ptr [ %35, %.lr.ph ], [ %spec.select, %18 ]
  tail call void @LZ4_putPosition(ptr noundef %.133, ptr noundef %0, i32 noundef 1, ptr noundef %27)
  %35 = getelementptr inbounds i8, ptr %.133, i64 3
  %.not31 = icmp ugt ptr %35, %34
  br i1 %.not31, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %32, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %18, %._crit_edge.loopexit, %15
  %.0 = phi i32 [ 0, %15 ], [ %.pre, %._crit_edge.loopexit ], [ %31, %18 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @LZ4_putPosition(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { 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, !9, i64 16388}
!6 = !{!"", !7, i64 0, !9, i64 16384, !9, i64 16388, !10, i64 16392, !10, i64 16400, !9, i64 16408}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !9, i64 16384}
!12 = !{!6, !10, i64 16392}
!13 = !{!6, !9, i64 16408}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass