; LLVM IR from Nonoum/ECL :: tests (tests)

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

; 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: mustprogress nounwind uwtable
declare dso_local void @ECL_JH_WInit(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @ECL_ZeroDevourer_Compress(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.ECL_JH_WState, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %18, i64 %20
  store ptr %21, ptr %13, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !9
  call void @ECL_JH_WInit(ptr noundef %10, ptr noundef %22, i32 noundef %23, i32 noundef 0)
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %33

26:                                               ; preds = %4
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %33

29:                                               ; preds = %26
  %30 = getelementptr inbounds %struct.ECL_JH_WState, ptr %10, i32 0, i32 4
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = icmp ne i8 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %29, %26, %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %125

34:                                               ; preds = %29
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %35, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %36, ptr %12, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %111, %34
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = icmp ult ptr %38, %39
  br i1 %40, label %41, label %45

41:                                               ; preds = %37
  %42 = getelementptr inbounds %struct.ECL_JH_WState, ptr %10, i32 0, i32 4
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = icmp ne i8 %43, 0
  br label %45

45:                                               ; preds = %41, %37
  %46 = phi i1 [ false, %37 ], [ %44, %41 ]
  br i1 %46, label %47, label %112

47:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %48, ptr %17, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %60, %47
  %50 = load ptr, ptr %17, align 8, !tbaa !5
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = icmp ult ptr %50, %51
  br i1 %52, label %53, label %57

53:                                               ; preds = %49
  %54 = load ptr, ptr %17, align 8, !tbaa !5
  %55 = load i8, ptr %54, align 1, !tbaa !13
  %56 = icmp ne i8 %55, 0
  br label %57

57:                                               ; preds = %53, %49
  %58 = phi i1 [ false, %49 ], [ %56, %53 ]
  br i1 %58, label %59, label %63

59:                                               ; preds = %57
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr %17, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %17, align 8, !tbaa !5
  br label %49, !llvm.loop !14

63:                                               ; preds = %57
  %64 = load ptr, ptr %17, align 8, !tbaa !5
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = ptrtoint ptr %64 to i64
  %67 = ptrtoint ptr %65 to i64
  %68 = sub i64 %66, %67
  %69 = trunc i64 %68 to i32
  store i32 %69, ptr %15, align 4, !tbaa !9
  %70 = load ptr, ptr %17, align 8, !tbaa !5
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = icmp eq ptr %70, %71
  br i1 %72, label %73, label %76

73:                                               ; preds = %63
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = load i32, ptr %15, align 4, !tbaa !9
  call void @_ZL27ECL_ZeroDevourer_DumpSeq111P13ECL_JH_WStatePKhj(ptr noundef %10, ptr noundef %74, i32 noundef %75)
  store i32 3, ptr %14, align 4
  br label %109

76:                                               ; preds = %63
  %77 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %77, ptr %12, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %90, %76
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = icmp ult ptr %79, %80
  br i1 %81, label %82, label %87

82:                                               ; preds = %78
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  %84 = load i8, ptr %83, align 1, !tbaa !13
  %85 = icmp ne i8 %84, 0
  %86 = xor i1 %85, true
  br label %87

87:                                               ; preds = %82, %78
  %88 = phi i1 [ false, %78 ], [ %86, %82 ]
  br i1 %88, label %89, label %93

89:                                               ; preds = %87
  br label %90

90:                                               ; preds = %89
  %91 = load ptr, ptr %12, align 8, !tbaa !5
  %92 = getelementptr inbounds i8, ptr %91, i32 1
  store ptr %92, ptr %12, align 8, !tbaa !5
  br label %78, !llvm.loop !16

93:                                               ; preds = %87
  %94 = load ptr, ptr %12, align 8, !tbaa !5
  %95 = load ptr, ptr %17, align 8, !tbaa !5
  %96 = ptrtoint ptr %94 to i64
  %97 = ptrtoint ptr %95 to i64
  %98 = sub i64 %96, %97
  %99 = trunc i64 %98 to i32
  store i32 %99, ptr %16, align 4, !tbaa !9
  %100 = load i32, ptr %15, align 4, !tbaa !9
  %101 = load i32, ptr %16, align 4, !tbaa !9
  %102 = call noundef zeroext i1 @_ZL24ECL_ZeroDevourer_IsWorthjj(i32 noundef %100, i32 noundef %101)
  br i1 %102, label %103, label %108

103:                                              ; preds = %93
  %104 = load ptr, ptr %11, align 8, !tbaa !5
  %105 = load i32, ptr %15, align 4, !tbaa !9
  %106 = load i32, ptr %16, align 4, !tbaa !9
  call void @_ZL28ECL_ZeroDevourer_DumpGenericP13ECL_JH_WStatePKhjj(ptr noundef %10, ptr noundef %104, i32 noundef %105, i32 noundef %106)
  %107 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %107, ptr %11, align 8, !tbaa !5
  br label %108

108:                                              ; preds = %103, %93
  store i32 0, ptr %14, align 4
  br label %109

109:                                              ; preds = %108, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  %110 = load i32, ptr %14, align 4
  switch i32 %110, label %127 [
    i32 0, label %111
    i32 3, label %112
  ]

111:                                              ; preds = %109
  br label %37, !llvm.loop !17

112:                                              ; preds = %109, %45
  %113 = getelementptr inbounds %struct.ECL_JH_WState, ptr %10, i32 0, i32 4
  %114 = load i8, ptr %113, align 1, !tbaa !11
  %115 = icmp ne i8 %114, 0
  br i1 %115, label %117, label %116

116:                                              ; preds = %112
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %125

117:                                              ; preds = %112
  %118 = getelementptr inbounds %struct.ECL_JH_WState, ptr %10, i32 0, i32 1
  %119 = load ptr, ptr %118, align 8, !tbaa !18
  %120 = load ptr, ptr %8, align 8, !tbaa !5
  %121 = ptrtoint ptr %119 to i64
  %122 = ptrtoint ptr %120 to i64
  %123 = sub i64 %121, %122
  %124 = trunc i64 %123 to i32
  store i32 %124, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %125

125:                                              ; preds = %117, %116, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #3
  %126 = load i32, ptr %5, align 4
  ret i32 %126

127:                                              ; preds = %109
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL27ECL_ZeroDevourer_DumpSeq111P13ECL_JH_WStatePKhj(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL24ECL_ZeroDevourer_IsWorthjj(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL28ECL_ZeroDevourer_DumpGenericP13ECL_JH_WStatePKhjj(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 25}
!12 = !{!"_ZTS13ECL_JH_WState", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 25}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}
!18 = !{!12, !6, 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"

%struct.ECL_JH_WState = type { ptr, ptr, ptr, i8, i8 }

; 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: mustprogress nounwind uwtable
declare dso_local void @ECL_JH_WInit(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @ECL_ZeroDevourer_Compress(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.ECL_JH_WState, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  %6 = zext i32 %1 to i64
  %7 = getelementptr inbounds i8, ptr %0, i64 %6
  call void @ECL_JH_WInit(ptr noundef nonnull %5, ptr noundef %2, i32 noundef %3, i32 noundef 0)
  %8 = icmp ne ptr %0, null
  %9 = icmp ne i32 %1, 0
  %or.cond = and i1 %8, %9
  %10 = getelementptr inbounds i8, ptr %5, i64 25
  %11 = load i8, ptr %10, align 1
  %12 = icmp ne i8 %11, 0
  %or.cond4 = select i1 %or.cond, i1 %12, i1 false
  br i1 %or.cond4, label %.preheader56, label %45

.preheader56:                                     ; preds = %4, %32
  %.04370 = phi ptr [ %.2, %32 ], [ %0, %4 ]
  %.04569 = phi ptr [ %.146.lcssa, %32 ], [ %0, %4 ]
  %13 = icmp ult ptr %.04569, %7
  br i1 %13, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader56, %15
  %.061 = phi ptr [ %16, %15 ], [ %.04569, %.preheader56 ]
  %14 = load i8, ptr %.061, align 1, !tbaa !5
  %.not = icmp eq i8 %14, 0
  br i1 %.not, label %.critedge, label %15

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %.061, i64 1
  %17 = icmp ult ptr %16, %7
  br i1 %17, label %.lr.ph, label %.critedge, !llvm.loop !8

.critedge:                                        ; preds = %.lr.ph, %15, %.preheader56
  %.0.lcssa = phi ptr [ %.04569, %.preheader56 ], [ %16, %15 ], [ %.061, %.lr.ph ]
  %18 = ptrtoint ptr %.0.lcssa to i64
  %19 = ptrtoint ptr %.04370 to i64
  %20 = sub i64 %18, %19
  %21 = trunc i64 %20 to i32
  %22 = icmp eq ptr %.0.lcssa, %7
  br i1 %22, label %.thread, label %.preheader

.preheader:                                       ; preds = %.critedge
  %23 = icmp ult ptr %.0.lcssa, %7
  br i1 %23, label %.lr.ph65, label %.critedge6

.thread:                                          ; preds = %.critedge
  call void @_ZL27ECL_ZeroDevourer_DumpSeq111P13ECL_JH_WStatePKhj(ptr noundef nonnull %5, ptr noundef %.04370, i32 noundef %21)
  %.pr = load i8, ptr %10, align 1, !tbaa !10
  br label %.loopexit

.lr.ph65:                                         ; preds = %.preheader, %25
  %.14664 = phi ptr [ %26, %25 ], [ %.0.lcssa, %.preheader ]
  %24 = load i8, ptr %.14664, align 1, !tbaa !5
  %.not50 = icmp eq i8 %24, 0
  br i1 %.not50, label %25, label %.critedge6.loopexit

25:                                               ; preds = %.lr.ph65
  %26 = getelementptr inbounds i8, ptr %.14664, i64 1
  %27 = icmp ult ptr %26, %7
  br i1 %27, label %.lr.ph65, label %.critedge6.loopexit, !llvm.loop !13

.critedge6.loopexit:                              ; preds = %25, %.lr.ph65
  %.146.lcssa.ph = phi ptr [ %.14664, %.lr.ph65 ], [ %26, %25 ]
  %.pre = ptrtoint ptr %.146.lcssa.ph to i64
  br label %.critedge6

.critedge6:                                       ; preds = %.critedge6.loopexit, %.preheader
  %.pre-phi = phi i64 [ %.pre, %.critedge6.loopexit ], [ %18, %.preheader ]
  %.146.lcssa = phi ptr [ %.146.lcssa.ph, %.critedge6.loopexit ], [ %.0.lcssa, %.preheader ]
  %28 = sub i64 %.pre-phi, %18
  %29 = trunc i64 %28 to i32
  %30 = call noundef zeroext i1 @_ZL24ECL_ZeroDevourer_IsWorthjj(i32 noundef %21, i32 noundef %29)
  br i1 %30, label %31, label %32

31:                                               ; preds = %.critedge6
  call void @_ZL28ECL_ZeroDevourer_DumpGenericP13ECL_JH_WStatePKhjj(ptr noundef nonnull %5, ptr noundef %.04370, i32 noundef %21, i32 noundef %29)
  br label %32

32:                                               ; preds = %.critedge6, %31
  %.2 = phi ptr [ %.146.lcssa, %31 ], [ %.04370, %.critedge6 ]
  %33 = icmp ult ptr %.2, %7
  %34 = load i8, ptr %10, align 1
  %35 = icmp ne i8 %34, 0
  %36 = select i1 %33, i1 %35, i1 false
  br i1 %36, label %.preheader56, label %.loopexit

.loopexit:                                        ; preds = %32, %.thread
  %37 = phi i8 [ %.pr, %.thread ], [ %34, %32 ]
  %.not51 = icmp eq i8 %37, 0
  br i1 %.not51, label %45, label %38

38:                                               ; preds = %.loopexit
  %39 = getelementptr inbounds i8, ptr %5, i64 8
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = ptrtoint ptr %40 to i64
  %42 = ptrtoint ptr %2 to i64
  %43 = sub i64 %41, %42
  %44 = trunc i64 %43 to i32
  br label %45

45:                                               ; preds = %.loopexit, %4, %38
  %.042 = phi i32 [ %44, %38 ], [ 0, %4 ], [ 0, %.loopexit ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  ret i32 %.042
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL27ECL_ZeroDevourer_DumpSeq111P13ECL_JH_WStatePKhj(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL24ECL_ZeroDevourer_IsWorthjj(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL28ECL_ZeroDevourer_DumpGenericP13ECL_JH_WStatePKhjj(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass