; LLVM IR from ryanlayer/giggle :: src (wah)

; 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"

@WAH_SIZE = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @get_wah_i(ptr noundef, ptr noundef, i32 noundef, i32 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @wah_get_ints_count(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds i32, ptr %8, i64 0
  %10 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %10, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %46, %1
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp ult i32 %12, %13
  br i1 %14, label %15, label %49

15:                                               ; preds = %11
  store i8 0, ptr %3, align 1, !tbaa !11
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = load i32, ptr @WAH_SIZE, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  call void @get_wah_i(ptr noundef %16, ptr noundef %3, i32 noundef %17, i32 noundef %18)
  %19 = load i8, ptr %3, align 1, !tbaa !11
  %20 = zext i8 %19 to i32
  %21 = load i32, ptr @WAH_SIZE, align 4, !tbaa !9
  %22 = sub i32 %21, 1
  %23 = ashr i32 %20, %22
  %24 = and i32 %23, 1
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %34

26:                                               ; preds = %15
  %27 = load i8, ptr %3, align 1, !tbaa !11
  %28 = zext i8 %27 to i32
  %29 = load i32, ptr @WAH_SIZE, align 4, !tbaa !9
  %30 = sub i32 %29, 1
  %31 = shl i32 1, %30
  %32 = xor i32 %31, -1
  %33 = and i32 %28, %32
  br label %35

34:                                               ; preds = %15
  br label %35

35:                                               ; preds = %34, %26
  %36 = phi i32 [ %33, %26 ], [ 1, %34 ]
  store i32 %36, ptr %4, align 4, !tbaa !9
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %45

39:                                               ; preds = %35
  %40 = load i8, ptr %3, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = call i32 @llvm.ctpop.i32(i32 %41)
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = add i32 %43, %42
  store i32 %44, ptr %6, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %39, %35
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = add i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !9
  br label %11, !llvm.loop !12

49:                                               ; preds = %11
  %50 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret i32 %50
}

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@WAH_SIZE = external dso_local local_unnamed_addr global i32, align 4

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

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

; Function Attrs: mustprogress 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 @wah_get_ints_count(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #3
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %.not11 = icmp eq i32 %3, 0
  br i1 %.not11, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %.pre = load i32, ptr @WAH_SIZE, align 4, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %4 = phi i32 [ %7, %19 ], [ %.pre, %.lr.ph.preheader ]
  %.010 = phi i32 [ %20, %19 ], [ 0, %.lr.ph.preheader ]
  %.089 = phi i32 [ %.1, %19 ], [ 0, %.lr.ph.preheader ]
  store i8 0, ptr %2, align 1, !tbaa !9
  call void @get_wah_i(ptr noundef nonnull %0, ptr noundef nonnull %2, i32 noundef %4, i32 noundef %.010)
  %5 = load i8, ptr %2, align 1, !tbaa !9
  %6 = zext i8 %5 to i32
  %7 = load i32, ptr @WAH_SIZE, align 4, !tbaa !5
  %8 = add i32 %7, -1
  %9 = shl nuw i32 1, %8
  %10 = and i32 %9, %6
  %.not = icmp eq i32 %10, 0
  %11 = xor i32 %9, -1
  %12 = and i32 %11, %6
  %13 = icmp eq i32 %12, 1
  %14 = or i1 %.not, %13
  br i1 %14, label %15, label %19

15:                                               ; preds = %.lr.ph
  %16 = call range(i8 0, 9) i8 @llvm.ctpop.i8(i8 %5)
  %17 = zext nneg i8 %16 to i32
  %18 = add i32 %.089, %17
  br label %19

19:                                               ; preds = %.lr.ph, %15
  %.1 = phi i32 [ %18, %15 ], [ %.089, %.lr.ph ]
  %20 = add nuw i32 %.010, 1
  %exitcond.not = icmp eq i32 %20, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %19, %1
  %.08.lcssa = phi i32 [ 0, %1 ], [ %.1, %19 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #3
  ret i32 %.08.lcssa
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.ctpop.i8(i8) #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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