; LLVM IR from xxks-kkk/algo :: queue/deque (deque)

; 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.DequeRecord = type { i32, i32, i32, i32, ptr }

@.str = external hidden unnamed_addr constant [15 x i8], align 1

declare void @fatal(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @push(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds %struct.DequeRecord, ptr %5, i32 0, i32 3
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.DequeRecord, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = icmp eq i32 %7, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  call void @fatal(ptr noundef @.str)
  br label %13

13:                                               ; preds = %12, %2
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.DequeRecord, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %33

18:                                               ; preds = %13
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.DequeRecord, ptr %20, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.DequeRecord, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr %24, align 4, !tbaa !14
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds i32, ptr %22, i64 %27
  store i32 %19, ptr %28, align 4, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.DequeRecord, ptr %29, i32 0, i32 3
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %30, align 4, !tbaa !11
  br label %59

33:                                               ; preds = %13
  %34 = load ptr, ptr %4, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.DequeRecord, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %58

38:                                               ; preds = %33
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.DequeRecord, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.DequeRecord, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !14
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %42, i64 %46
  store i32 %39, ptr %47, align 4, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.DequeRecord, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !13
  %51 = sub nsw i32 %50, 1
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.DequeRecord, ptr %52, i32 0, i32 1
  store i32 %51, ptr %53, align 4, !tbaa !14
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.DequeRecord, ptr %54, i32 0, i32 3
  %56 = load i32, ptr %55, align 4, !tbaa !11
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %55, align 4, !tbaa !11
  br label %58

58:                                               ; preds = %38, %33
  br label %59

59:                                               ; preds = %58, %18
  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 = { 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, !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, !6, i64 12}
!12 = !{!"DequeRecord", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !10, i64 16}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 4}
!15 = !{!12, !10, i64 16}


; 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 = external hidden unnamed_addr constant [15 x i8], align 1

declare void @fatal(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @push(i32 noundef %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 12
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr %1, align 8, !tbaa !11
  %6 = icmp eq i32 %4, %5
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  tail call void @fatal(ptr noundef nonnull @.str) #2
  br label %8

8:                                                ; preds = %7, %2
  %9 = getelementptr inbounds i8, ptr %1, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %18

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %1, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = add nsw i32 %10, -1
  store i32 %15, ptr %9, align 4, !tbaa !12
  %16 = zext nneg i32 %10 to i64
  %17 = getelementptr inbounds i32, ptr %14, i64 %16
  store i32 %0, ptr %17, align 4, !tbaa !14
  br label %.sink.split

18:                                               ; preds = %8
  %19 = icmp eq i32 %10, 0
  br i1 %19, label %20, label %27

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %1, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  store i32 %0, ptr %22, align 4, !tbaa !14
  %23 = load i32, ptr %1, align 8, !tbaa !11
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %9, align 4, !tbaa !12
  br label %.sink.split

.sink.split:                                      ; preds = %12, %20
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %.sink.split, %18
  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 = { 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 = { 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, !7, i64 12}
!6 = !{!"DequeRecord", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !10, i64 16}
!14 = !{!7, !7, i64 0}


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