; LLVM IR from bytecodealliance/sightglass :: benchmarks/bz2 (benchmark)

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

@serviceFn = external hidden global ptr, align 8
@inbuf = external dso_local global ptr, align 8
@zbuf = external dso_local global [1010600 x i8], align 16
@.str.9 = external hidden unnamed_addr constant [14 x i8], align 1
@nIn = external dso_local global i32, align 4
@nZ = external dso_local global i32, align 4
@.str.10 = external hidden unnamed_addr constant [23 x i8], align 1
@nOut = external dso_local global i32, align 4
@outbuf = external dso_local global [2000000 x i8], align 16
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @BZ2_bzBuffToBuffDecompress(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @set_inbuf(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store ptr @g_serviceFn, ptr @serviceFn, align 8, !tbaa !9
  %11 = call i32 @puts(ptr noundef @.str.9)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !11
  call void @set_inbuf(ptr noundef %10)
  %12 = load i64, ptr %10, align 8, !tbaa !11
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr @nIn, align 4, !tbaa !5
  call void (...) @bench_start()
  store i32 1000000, ptr @nZ, align 4, !tbaa !5
  %14 = load ptr, ptr @inbuf, align 8, !tbaa !9
  %15 = load i32, ptr @nIn, align 4, !tbaa !5
  %16 = call i32 @BZ2_bzBuffToBuffCompress(ptr noundef @zbuf, ptr noundef @nZ, ptr noundef %14, i32 noundef %15, i32 noundef 9, i32 noundef 3, i32 noundef 30)
  store i32 %16, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr @nZ, align 4, !tbaa !5
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, i32 noundef %17)
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %2
  %22 = load ptr, ptr @serviceFn, align 8, !tbaa !9
  %23 = call i64 %22(i64 noundef 0, i64 noundef 3)
  br label %24

24:                                               ; preds = %21, %2
  store i32 2000000, ptr @nOut, align 4, !tbaa !5
  %25 = load i32, ptr @nZ, align 4, !tbaa !5
  %26 = call i32 @BZ2_bzBuffToBuffDecompress(ptr noundef @outbuf, ptr noundef @nOut, ptr noundef @zbuf, i32 noundef %25, i32 noundef 1, i32 noundef 0)
  store i32 %26, ptr %6, align 4, !tbaa !5
  call void (...) @bench_end()
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %32

29:                                               ; preds = %24
  %30 = load ptr, ptr @serviceFn, align 8, !tbaa !9
  %31 = call i64 %30(i64 noundef 0, i64 noundef 4)
  br label %32

32:                                               ; preds = %29, %24
  %33 = load i32, ptr @nOut, align 4, !tbaa !5
  %34 = load i32, ptr @nIn, align 4, !tbaa !5
  %35 = icmp ne i32 %33, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %32
  %37 = load ptr, ptr @serviceFn, align 8, !tbaa !9
  %38 = call i64 %37(i64 noundef 0, i64 noundef 5)
  br label %65

39:                                               ; preds = %32
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %61, %39
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = load i32, ptr @nOut, align 4, !tbaa !5
  %43 = icmp ult i32 %41, %42
  br i1 %43, label %44, label %64

44:                                               ; preds = %40
  %45 = load ptr, ptr @inbuf, align 8, !tbaa !9
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !13
  %50 = sext i8 %49 to i32
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [2000000 x i8], ptr @outbuf, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !13
  %55 = sext i8 %54 to i32
  %56 = icmp ne i32 %50, %55
  br i1 %56, label %57, label %60

57:                                               ; preds = %44
  %58 = load ptr, ptr @serviceFn, align 8, !tbaa !9
  %59 = call i64 %58(i64 noundef 0, i64 noundef 6)
  br label %60

60:                                               ; preds = %57, %44
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %8, align 4, !tbaa !5
  br label %40, !llvm.loop !14

64:                                               ; preds = %40
  br label %65

65:                                               ; preds = %64, %36
  %66 = call i32 @puts(ptr noundef @.str.11)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @g_serviceFn(i64 noundef, i64 noundef) #1

declare i32 @puts(ptr noundef) #2

declare void @bench_start(...) #2

declare i32 @printf(ptr noundef, ...) #2

declare void @bench_end(...) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@serviceFn = external hidden local_unnamed_addr global ptr, align 8
@inbuf = external dso_local local_unnamed_addr global ptr, align 8
@zbuf = external dso_local global [1010600 x i8], align 16
@.str.9 = external hidden unnamed_addr constant [14 x i8], align 1
@nIn = external dso_local local_unnamed_addr global i32, align 4
@nZ = external dso_local global i32, align 4
@.str.10 = external hidden unnamed_addr constant [23 x i8], align 1
@nOut = external dso_local global i32, align 4
@outbuf = external dso_local global [2000000 x i8], align 16
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @BZ2_bzBuffToBuffDecompress(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %3 = alloca i64, align 8
  store ptr @g_serviceFn, ptr @serviceFn, align 8, !tbaa !5
  %4 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.9)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @set_inbuf(ptr noundef nonnull %3)
  %5 = load i64, ptr %3, align 8, !tbaa !9
  %6 = trunc i64 %5 to i32
  store i32 %6, ptr @nIn, align 4, !tbaa !11
  call void (...) @bench_start() #4
  store i32 1000000, ptr @nZ, align 4, !tbaa !11
  %7 = load ptr, ptr @inbuf, align 8, !tbaa !5
  %8 = load i32, ptr @nIn, align 4, !tbaa !11
  %9 = call i32 @BZ2_bzBuffToBuffCompress(ptr noundef nonnull @zbuf, ptr noundef nonnull @nZ, ptr noundef %7, i32 noundef %8, i32 noundef 9, i32 noundef 3, i32 noundef 30)
  %10 = load i32, ptr @nZ, align 4, !tbaa !11
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, i32 noundef %10)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %15, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr @serviceFn, align 8, !tbaa !5
  %14 = call i64 %13(i64 noundef 0, i64 noundef 3) #4
  br label %15

15:                                               ; preds = %12, %2
  store i32 2000000, ptr @nOut, align 4, !tbaa !11
  %16 = load i32, ptr @nZ, align 4, !tbaa !11
  %17 = call i32 @BZ2_bzBuffToBuffDecompress(ptr noundef nonnull @outbuf, ptr noundef nonnull @nOut, ptr noundef nonnull @zbuf, i32 noundef %16, i32 noundef 1, i32 noundef 0)
  call void (...) @bench_end() #4
  %.not6 = icmp eq i32 %17, 0
  br i1 %.not6, label %21, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr @serviceFn, align 8, !tbaa !5
  %20 = call i64 %19(i64 noundef 0, i64 noundef 4) #4
  br label %21

21:                                               ; preds = %18, %15
  %22 = load i32, ptr @nOut, align 4, !tbaa !11
  %23 = load i32, ptr @nIn, align 4, !tbaa !11
  %.not7 = icmp eq i32 %22, %23
  br i1 %.not7, label %.preheader, label %24

.preheader:                                       ; preds = %21
  %.not10 = icmp eq i32 %22, 0
  br i1 %.not10, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %.pre12 = load ptr, ptr @inbuf, align 8, !tbaa !5
  br label %.lr.ph

24:                                               ; preds = %21
  %25 = load ptr, ptr @serviceFn, align 8, !tbaa !5
  %26 = call i64 %25(i64 noundef 0, i64 noundef 5) #4
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph.preheader, %36
  %27 = phi i32 [ %22, %.lr.ph.preheader ], [ %37, %36 ]
  %28 = phi ptr [ %.pre12, %.lr.ph.preheader ], [ %38, %36 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %36 ]
  %29 = getelementptr inbounds i8, ptr %28, i64 %indvars.iv
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = getelementptr inbounds [2000000 x i8], ptr @outbuf, i64 0, i64 %indvars.iv
  %32 = load i8, ptr %31, align 1, !tbaa !13
  %.not8 = icmp eq i8 %30, %32
  br i1 %.not8, label %36, label %33

33:                                               ; preds = %.lr.ph
  %34 = load ptr, ptr @serviceFn, align 8, !tbaa !5
  %35 = call i64 %34(i64 noundef 0, i64 noundef 6) #4
  %.pre = load ptr, ptr @inbuf, align 8, !tbaa !5
  %.pre13 = load i32, ptr @nOut, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %.lr.ph, %33
  %37 = phi i32 [ %27, %.lr.ph ], [ %.pre13, %33 ]
  %38 = phi ptr [ %28, %.lr.ph ], [ %.pre, %33 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = zext i32 %37 to i64
  %40 = icmp ult i64 %indvars.iv.next, %39
  br i1 %40, label %.lr.ph, label %.loopexit, !llvm.loop !14

.loopexit:                                        ; preds = %36, %.preheader, %24
  %41 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.11)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @g_serviceFn(i64 noundef, i64 noundef) #1

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

declare void @bench_start(...) local_unnamed_addr #3

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

declare void @bench_end(...) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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