; LLVM IR from MaJerle/lwpkt :: tests (test_main)

; 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.lwrb = type { ptr, i64, i64, i64, ptr }
%struct.lwpkt = type { i32, [256 x i8], ptr, ptr, i32, ptr, i8, %struct.anon }
%struct.anon = type { i32, %struct.lwpkt_crc_t, i32, i32, i32, i32, i32, i64, i64 }
%struct.lwpkt_crc_t = type { i32 }

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@pkt_tx_rb = external hidden global %struct.lwrb, align 8
@pkt_tx_rb_data = external hidden global [256 x i8], align 16
@pkt_rx_rb = external hidden global %struct.lwrb, align 8
@pkt_rx_rb_data = external hidden global [256 x i8], align 16
@pkt = external hidden global %struct.lwpkt, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %6 = call zeroext i8 @lwrb_init(ptr noundef @pkt_tx_rb, ptr noundef @pkt_tx_rb_data, i64 noundef 256)
  %7 = call zeroext i8 @lwrb_init(ptr noundef @pkt_rx_rb, ptr noundef @pkt_rx_rb_data, i64 noundef 256)
  %8 = call i32 @lwpkt_init(ptr noundef @pkt, ptr noundef @pkt_tx_rb, ptr noundef @pkt_rx_rb)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %74, %0
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp ult i32 %10, 128
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %4, align 4
  br label %77

13:                                               ; preds = %9
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = add i32 %14, 1
  %16 = trunc i32 %15 to i8
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = and i32 %17, 1
  %19 = icmp ne i32 %18, 0
  %20 = xor i1 %19, true
  %21 = xor i1 %20, true
  %22 = zext i1 %21 to i32
  %23 = trunc i32 %22 to i8
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = and i32 %24, 2
  %26 = icmp ne i32 %25, 0
  %27 = xor i1 %26, true
  %28 = xor i1 %27, true
  %29 = zext i1 %28 to i32
  %30 = trunc i32 %29 to i8
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = and i32 %31, 4
  %33 = icmp ne i32 %32, 0
  %34 = xor i1 %33, true
  %35 = xor i1 %34, true
  %36 = zext i1 %35 to i32
  %37 = trunc i32 %36 to i8
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = and i32 %38, 8
  %40 = icmp ne i32 %39, 0
  %41 = xor i1 %40, true
  %42 = xor i1 %41, true
  %43 = zext i1 %42 to i32
  %44 = trunc i32 %43 to i8
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = and i32 %45, 16
  %47 = icmp ne i32 %46, 0
  %48 = xor i1 %47, true
  %49 = xor i1 %48, true
  %50 = zext i1 %49 to i32
  %51 = trunc i32 %50 to i8
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = and i32 %52, 32
  %54 = icmp ne i32 %53, 0
  %55 = xor i1 %54, true
  %56 = xor i1 %55, true
  %57 = zext i1 %56 to i32
  %58 = trunc i32 %57 to i8
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = and i32 %59, 64
  %61 = icmp ne i32 %60, 0
  %62 = xor i1 %61, true
  %63 = xor i1 %62, true
  %64 = zext i1 %63 to i32
  %65 = trunc i32 %64 to i8
  %66 = call i32 @run_test(i8 noundef zeroext %16, i8 noundef zeroext %23, i8 noundef zeroext %30, i8 noundef zeroext %37, i8 noundef zeroext %44, i8 noundef zeroext %51, i8 noundef zeroext %58, i8 noundef zeroext %65)
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = or i32 %67, %66
  store i32 %68, ptr %2, align 4, !tbaa !5
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %73

71:                                               ; preds = %13
  %72 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %72, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %77

73:                                               ; preds = %13
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = add i32 %75, 1
  store i32 %76, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !9

77:                                               ; preds = %71, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %78 = load i32, ptr %4, align 4
  switch i32 %78, label %81 [
    i32 2, label %79
  ]

79:                                               ; preds = %77
  %80 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %80, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %81

81:                                               ; preds = %79, %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %82 = load i32, ptr %1, align 4
  ret i32 %82
}

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

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

declare zeroext i8 @lwrb_init(ptr noundef, ptr noundef, i64 noundef) #2

declare i32 @lwpkt_init(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @run_test(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #0

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

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 = { "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 = distinct !{!9, !10}
!10 = !{!"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"

%struct.lwrb = type { ptr, i64, i64, i64, ptr }
%struct.lwpkt = type { i32, [256 x i8], ptr, ptr, i32, ptr, i8, %struct.anon }
%struct.anon = type { i32, %struct.lwpkt_crc_t, i32, i32, i32, i32, i32, i64, i64 }
%struct.lwpkt_crc_t = type { i32 }

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@pkt_tx_rb = external hidden global %struct.lwrb, align 8
@pkt_tx_rb_data = external hidden global [256 x i8], align 16
@pkt_rx_rb = external hidden global %struct.lwrb, align 8
@pkt_rx_rb_data = external hidden global [256 x i8], align 16
@pkt = external hidden global %struct.lwpkt, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %2 = tail call zeroext i8 @lwrb_init(ptr noundef nonnull @pkt_tx_rb, ptr noundef nonnull @pkt_tx_rb_data, i64 noundef 256) #3
  %3 = tail call zeroext i8 @lwrb_init(ptr noundef nonnull @pkt_rx_rb, ptr noundef nonnull @pkt_rx_rb_data, i64 noundef 256) #3
  %4 = tail call i32 @lwpkt_init(ptr noundef nonnull @pkt, ptr noundef nonnull @pkt_tx_rb, ptr noundef nonnull @pkt_rx_rb) #3
  br label %5

5:                                                ; preds = %6, %0
  %.016 = phi i32 [ 0, %0 ], [ %7, %6 ]
  %exitcond = icmp eq i32 %.016, 128
  br i1 %exitcond, label %24, label %6

6:                                                ; preds = %5
  %7 = add nuw nsw i32 %.016, 1
  %8 = trunc nuw i32 %7 to i8
  %9 = trunc nuw i32 %.016 to i8
  %10 = and i8 %9, 1
  %11 = lshr i8 %9, 1
  %12 = and i8 %11, 1
  %13 = lshr i8 %9, 2
  %14 = and i8 %13, 1
  %15 = lshr i8 %9, 3
  %16 = and i8 %15, 1
  %17 = lshr i8 %9, 4
  %18 = and i8 %17, 1
  %19 = lshr i8 %9, 5
  %20 = and i8 %19, 1
  %21 = icmp ugt i32 %.016, 63
  %22 = zext i1 %21 to i8
  %23 = tail call i32 @run_test(i8 noundef zeroext %8, i8 noundef zeroext %10, i8 noundef zeroext %12, i8 noundef zeroext %14, i8 noundef zeroext %16, i8 noundef zeroext %18, i8 noundef zeroext %20, i8 noundef zeroext %22)
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %5, label %24, !llvm.loop !5

24:                                               ; preds = %6, %5
  %.1 = phi i32 [ 0, %5 ], [ %23, %6 ]
  ret i32 %.1
}

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

declare zeroext i8 @lwrb_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @lwpkt_init(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @run_test(i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) 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 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass