; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms/232.ll (qTransfer)

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

; Function Attrs: nounwind uwtable
define dso_local void @_qTransfer(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.MyQueue, ptr %3, i32 0, i32 5
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %61

7:                                                ; preds = %1
  br label %8

8:                                                ; preds = %40, %7
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.MyQueue, ptr %9, i32 0, i32 3
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %60

13:                                               ; preds = %8
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MyQueue, ptr %14, i32 0, i32 5
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = add nsw i32 %16, 1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.MyQueue, ptr %18, i32 0, i32 4
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = icmp eq i32 %17, %20
  br i1 %21, label %22, label %40

22:                                               ; preds = %13
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MyQueue, ptr %23, i32 0, i32 4
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = sitofp i32 %25 to double
  %27 = fmul double %26, 1.500000e+00
  %28 = fptosi double %27 to i32
  store i32 %28, ptr %24, align 8, !tbaa !13
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MyQueue, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.MyQueue, ptr %32, i32 0, i32 4
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = sext i32 %34 to i64
  %36 = mul i64 %35, 4
  %37 = call ptr @realloc(ptr noundef %31, i64 noundef %36) #2
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.MyQueue, ptr %38, i32 0, i32 1
  store ptr %37, ptr %39, align 8, !tbaa !14
  br label %40

40:                                               ; preds = %22, %13
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MyQueue, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.MyQueue, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr %45, align 4, !tbaa !12
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %43, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !16
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.MyQueue, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.MyQueue, ptr %54, i32 0, i32 5
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %55, align 4, !tbaa !9
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds i32, ptr %53, i64 %58
  store i32 %50, ptr %59, align 4, !tbaa !16
  br label %8, !llvm.loop !17

60:                                               ; preds = %8
  br label %61

61:                                               ; preds = %60, %1
  ret void
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #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 = { nounwind allocsize(1) "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 allocsize(1) }

!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 28}
!10 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 20}
!13 = !{!10, !11, i64 24}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 0}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local void @_qTransfer(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 28
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %.not12 = icmp eq i32 %6, 0
  br i1 %.not12, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %.pre13.pre = load ptr, ptr %8, align 8, !tbaa !12
  br label %9

9:                                                ; preds = %.lr.ph, %22
  %.pre13 = phi ptr [ %.pre13.pre, %.lr.ph ], [ %.pre1315, %22 ]
  %10 = phi i32 [ %6, %.lr.ph ], [ %32, %22 ]
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = load i32, ptr %7, align 8, !tbaa !13
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %22

15:                                               ; preds = %9
  %16 = sitofp i32 %12 to double
  %17 = fmul double %16, 1.500000e+00
  %18 = fptosi double %17 to i32
  store i32 %18, ptr %7, align 8, !tbaa !13
  %19 = sext i32 %18 to i64
  %20 = shl nsw i64 %19, 2
  %21 = tail call ptr @realloc(ptr noundef %.pre13, i64 noundef %20) #2
  store ptr %21, ptr %8, align 8, !tbaa !12
  %.pre = load i32, ptr %5, align 4, !tbaa !11
  %.pre14 = load i32, ptr %2, align 4, !tbaa !5
  %.pre17 = add nsw i32 %.pre14, 1
  br label %22

22:                                               ; preds = %15, %9
  %.pre-phi = phi i32 [ %.pre17, %15 ], [ %12, %9 ]
  %.pre1315 = phi ptr [ %21, %15 ], [ %.pre13, %9 ]
  %23 = phi i32 [ %.pre14, %15 ], [ %11, %9 ]
  %24 = phi i32 [ %.pre, %15 ], [ %10, %9 ]
  %25 = load ptr, ptr %0, align 8, !tbaa !14
  %26 = add nsw i32 %24, -1
  store i32 %26, ptr %5, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %25, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !15
  store i32 %.pre-phi, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %23 to i64
  %31 = getelementptr inbounds i32, ptr %.pre1315, i64 %30
  store i32 %29, ptr %31, align 4, !tbaa !15
  %32 = load i32, ptr %5, align 4, !tbaa !11
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %.loopexit, label %9, !llvm.loop !16

.loopexit:                                        ; preds = %22, %.preheader, %1
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(1) }

!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, !10, i64 28}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 20}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !7, i64 0}
!15 = !{!10, !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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