; LLVM IR from simonaertssen/MIT-6.172-Performance-Engineering-of-Software-Systems :: Project 1 - Bit Hacks/everybit (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"

@test_bitarray = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [140 x i8], align 1
@__PRETTY_FUNCTION__.testutil_frmstr = external hidden unnamed_addr constant [40 x i8], align 1
@stdout = external global ptr, align 8
@test_verbose = external hidden global i8, align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__func__.testutil_frmstr = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @testutil_frmstr(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call i64 @strlen(ptr noundef %6) #7
  store i64 %7, ptr %3, align 8, !tbaa !9
  %8 = load ptr, ptr @test_bitarray, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %1
  %11 = load ptr, ptr @test_bitarray, align 8, !tbaa !5
  call void @bitarray_free(ptr noundef %11)
  br label %12

12:                                               ; preds = %10, %1
  %13 = load i64, ptr %3, align 8, !tbaa !9
  %14 = call ptr @bitarray_new(i64 noundef %13)
  store ptr %14, ptr @test_bitarray, align 8, !tbaa !5
  %15 = load ptr, ptr @test_bitarray, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  br label %19

18:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 172, ptr noundef @__PRETTY_FUNCTION__.testutil_frmstr) #8
  unreachable

19:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %36, %19
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = load i64, ptr %3, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %39

25:                                               ; preds = %20
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %26, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = call zeroext i1 @boolfromchar(i8 noundef signext %29)
  %31 = zext i1 %30 to i8
  store i8 %31, ptr %4, align 1, !tbaa !12
  %32 = load ptr, ptr @test_bitarray, align 8, !tbaa !5
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = load i8, ptr %4, align 1, !tbaa !12, !range !14, !noundef !15
  %35 = trunc i8 %34 to i1
  call void @bitarray_set(ptr noundef %32, i64 noundef %33, i1 noundef zeroext %35)
  br label %36

36:                                               ; preds = %25
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = add i64 %37, 1
  store i64 %38, ptr %5, align 8, !tbaa !9
  br label %20, !llvm.loop !16

39:                                               ; preds = %24
  %40 = load ptr, ptr @stdout, align 8, !tbaa !5
  %41 = load ptr, ptr @test_bitarray, align 8, !tbaa !5
  call void @bitarray_fprint(ptr noundef %40, ptr noundef %41)
  %42 = load i8, ptr @test_verbose, align 1, !tbaa !12, !range !14, !noundef !15
  %43 = trunc i8 %42 to i1
  br i1 %43, label %44, label %49

44:                                               ; preds = %39
  %45 = load ptr, ptr @stdout, align 8, !tbaa !5
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.2, ptr noundef %46) #6
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  call void @testutil_expect_internal(ptr noundef %48, ptr noundef @__func__.testutil_frmstr, i32 noundef 182)
  br label %49

49:                                               ; preds = %44, %39
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret void
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

declare void @bitarray_free(ptr noundef) #3

declare ptr @bitarray_new(i64 noundef) #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @boolfromchar(i8 noundef signext) #0

declare void @bitarray_set(ptr noundef, i64 noundef, i1 noundef zeroext) #3

; 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
declare dso_local void @bitarray_fprint(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #5

; Function Attrs: nounwind uwtable
declare hidden void @testutil_expect_internal(ptr noundef, ptr noundef, i32 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 willreturn memory(read) "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 = { "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 #4 = { noreturn nounwind "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 #5 = { nounwind "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn 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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!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"

@test_bitarray = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [22 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [140 x i8], align 1
@__PRETTY_FUNCTION__.testutil_frmstr = external hidden unnamed_addr constant [40 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@test_verbose = external hidden local_unnamed_addr global i8, align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__func__.testutil_frmstr = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @testutil_frmstr(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #5
  %3 = load ptr, ptr @test_bitarray, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %5, label %4

4:                                                ; preds = %1
  tail call void @bitarray_free(ptr noundef nonnull %3) #6
  br label %5

5:                                                ; preds = %4, %1
  %6 = tail call ptr @bitarray_new(i64 noundef %2) #6
  store ptr %6, ptr @test_bitarray, align 8, !tbaa !5
  %.not11 = icmp eq ptr %6, null
  br i1 %.not11, label %7, label %.preheader

.preheader:                                       ; preds = %5
  %.not13 = icmp eq i64 %2, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph

7:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 172, ptr noundef nonnull @__PRETTY_FUNCTION__.testutil_frmstr) #7
  unreachable

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr @test_bitarray, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %8 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %6, %.preheader ]
  %9 = load ptr, ptr @stdout, align 8, !tbaa !5
  tail call void @bitarray_fprint(ptr noundef %9, ptr noundef %8)
  %10 = load i8, ptr @test_verbose, align 1, !tbaa !9, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %17, label %20

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.012 = phi i64 [ %16, %.lr.ph ], [ 0, %.preheader ]
  %12 = getelementptr inbounds i8, ptr %0, i64 %.012
  %13 = load i8, ptr %12, align 1, !tbaa !13
  %14 = tail call zeroext i1 @boolfromchar(i8 noundef signext %13)
  %15 = load ptr, ptr @test_bitarray, align 8, !tbaa !5
  tail call void @bitarray_set(ptr noundef %15, i64 noundef %.012, i1 noundef zeroext %14) #6
  %16 = add nuw i64 %.012, 1
  %exitcond.not = icmp eq i64 %16, %2
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

17:                                               ; preds = %._crit_edge
  %18 = load ptr, ptr @stdout, align 8, !tbaa !5
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.2, ptr noundef %0) #6
  tail call void @testutil_expect_internal(ptr noundef %0, ptr noundef nonnull @__func__.testutil_frmstr, i32 noundef 182)
  br label %20

20:                                               ; preds = %17, %._crit_edge
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

declare void @bitarray_free(ptr noundef) local_unnamed_addr #2

declare ptr @bitarray_new(i64 noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @boolfromchar(i8 noundef signext) local_unnamed_addr #0

declare void @bitarray_set(ptr noundef, i64 noundef, i1 noundef zeroext) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @testutil_expect_internal(ptr noundef, ptr noundef, i32 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" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { noreturn nounwind "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 #4 = { nofree nounwind "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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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