; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhangjianan/作业/第二次直播手敲代码 (ringbuffer)

; 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.Queue = type { [10 x i32], i32, i32 }

@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

declare i32 @printf(ptr 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: nounwind uwtable
define dso_local void @printQueue(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.Queue, ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Queue, ptr %9, i32 0, i32 2
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = icmp slt i32 %8, %11
  br i1 %12, label %13, label %36

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Queue, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !9
  store i32 %16, ptr %3, align 4, !tbaa !13
  br label %17

17:                                               ; preds = %31, %13
  %18 = load i32, ptr %3, align 4, !tbaa !13
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Queue, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %34

23:                                               ; preds = %17
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Queue, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %3, align 4, !tbaa !13
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [10 x i32], ptr %25, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %29)
  br label %31

31:                                               ; preds = %23
  %32 = load i32, ptr %3, align 4, !tbaa !13
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %3, align 4, !tbaa !13
  br label %17, !llvm.loop !14

34:                                               ; preds = %17
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %74

36:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Queue, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !9
  store i32 %39, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %40

40:                                               ; preds = %51, %36
  %41 = load i32, ptr %4, align 4, !tbaa !13
  %42 = icmp slt i32 %41, 10
  br i1 %42, label %43, label %54

43:                                               ; preds = %40
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Queue, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %4, align 4, !tbaa !13
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10 x i32], ptr %45, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !13
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %49)
  br label %51

51:                                               ; preds = %43
  %52 = load i32, ptr %4, align 4, !tbaa !13
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %4, align 4, !tbaa !13
  br label %40, !llvm.loop !16

54:                                               ; preds = %40
  br label %55

55:                                               ; preds = %69, %54
  %56 = load i32, ptr %5, align 4, !tbaa !13
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Queue, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !12
  %60 = icmp slt i32 %56, %59
  br i1 %60, label %61, label %72

61:                                               ; preds = %55
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Queue, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %5, align 4, !tbaa !13
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [10 x i32], ptr %63, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !13
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %67)
  br label %69

69:                                               ; preds = %61
  %70 = load i32, ptr %5, align 4, !tbaa !13
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %5, align 4, !tbaa !13
  br label %55, !llvm.loop !17

72:                                               ; preds = %55
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %74

74:                                               ; preds = %72, %34
  ret void
}

attributes #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 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/C++ TBAA"}
!9 = !{!10, !11, i64 40}
!10 = !{!"Queue", !7, i64 0, !11, i64 40, !11, i64 44}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 44}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


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

@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @printQueue(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 44
  %5 = load i32, ptr %4, align 4, !tbaa !10
  %6 = icmp slt i32 %3, %5
  br i1 %6, label %.lr.ph26.preheader, label %.preheader21

.preheader21:                                     ; preds = %1
  %7 = icmp slt i32 %3, 10
  br i1 %7, label %.lr.ph.preheader, label %.preheader20

.lr.ph.preheader:                                 ; preds = %.preheader21
  %8 = sext i32 %3 to i64
  br label %.lr.ph

.lr.ph26.preheader:                               ; preds = %1
  %9 = sext i32 %3 to i64
  br label %.lr.ph26

.lr.ph26:                                         ; preds = %.lr.ph26.preheader, %.lr.ph26
  %indvars.iv32 = phi i64 [ %9, %.lr.ph26.preheader ], [ %indvars.iv.next33, %.lr.ph26 ]
  %10 = getelementptr inbounds [10 x i32], ptr %0, i64 0, i64 %indvars.iv32
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %11)
  %indvars.iv.next33 = add nsw i64 %indvars.iv32, 1
  %13 = load i32, ptr %4, align 4, !tbaa !10
  %14 = sext i32 %13 to i64
  %15 = icmp slt i64 %indvars.iv.next33, %14
  br i1 %15, label %.lr.ph26, label %._crit_edge27, !llvm.loop !12

.preheader20.loopexit:                            ; preds = %.lr.ph
  %.pre = load i32, ptr %4, align 4, !tbaa !10
  br label %.preheader20

.preheader20:                                     ; preds = %.preheader20.loopexit, %.preheader21
  %16 = phi i32 [ %.pre, %.preheader20.loopexit ], [ %5, %.preheader21 ]
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph24, label %._crit_edge27

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %8, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %18 = getelementptr inbounds [10 x i32], ptr %0, i64 0, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %19)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %21 = and i64 %indvars.iv.next, 4294967295
  %exitcond.not = icmp eq i64 %21, 10
  br i1 %exitcond.not, label %.preheader20.loopexit, label %.lr.ph, !llvm.loop !14

.lr.ph24:                                         ; preds = %.preheader20, %.lr.ph24
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %.lr.ph24 ], [ 0, %.preheader20 ]
  %22 = getelementptr inbounds [10 x i32], ptr %0, i64 0, i64 %indvars.iv29
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %23)
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %25 = load i32, ptr %4, align 4, !tbaa !10
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next30, %26
  br i1 %27, label %.lr.ph24, label %._crit_edge27, !llvm.loop !15

._crit_edge27:                                    ; preds = %.lr.ph24, %.lr.ph26, %.preheader20
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  ret void
}

attributes #0 = { 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 #1 = { nofree 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" }

!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, !9, i64 40}
!6 = !{!"Queue", !7, i64 0, !9, i64 40, !9, i64 44}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 44}
!11 = !{!9, !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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