; LLVM IR from LeoVen/C-Macro-Collections :: examples (ice_cream)

; 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_iter = type { ptr, i64, i64, i8, i8 }
%struct.queue = type { ptr, i64, i64, i64, i64, i32, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @q_empty(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @q_iter_rewind(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.queue_iter, ptr %6, i32 0, i32 3
  %8 = load i8, ptr %7, align 8, !tbaa !11, !range !14, !noundef !15
  %9 = trunc i8 %8 to i1
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %63

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.queue_iter, ptr %12, i32 0, i32 2
  %14 = load i64, ptr %13, align 8, !tbaa !16
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.queue_iter, ptr %17, i32 0, i32 3
  store i8 1, ptr %18, align 8, !tbaa !11
  store i1 false, ptr %3, align 1
  br label %63

19:                                               ; preds = %11
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %28, label %22

22:                                               ; preds = %19
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.queue_iter, ptr %23, i32 0, i32 2
  %25 = load i64, ptr %24, align 8, !tbaa !16
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %22, %19
  store i1 false, ptr %3, align 1
  br label %63

29:                                               ; preds = %22
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.queue_iter, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = call zeroext i1 @q_empty(ptr noundef %32)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.queue_iter, ptr %34, i32 0, i32 4
  %36 = zext i1 %33 to i8
  store i8 %36, ptr %35, align 1, !tbaa !18
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.queue_iter, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %39, align 8, !tbaa !16
  %41 = sub i64 %40, %37
  store i64 %41, ptr %39, align 8, !tbaa !16
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.queue_iter, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !19
  %45 = load i64, ptr %5, align 8, !tbaa !9
  %46 = icmp ult i64 %44, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %29
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.queue_iter, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = getelementptr inbounds %struct.queue, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !20
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.queue_iter, ptr %53, i32 0, i32 1
  %55 = load i64, ptr %54, align 8, !tbaa !19
  %56 = add i64 %55, %52
  store i64 %56, ptr %54, align 8, !tbaa !19
  br label %57

57:                                               ; preds = %47, %29
  %58 = load i64, ptr %5, align 8, !tbaa !9
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.queue_iter, ptr %59, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !19
  %62 = sub i64 %61, %58
  store i64 %62, ptr %60, align 8, !tbaa !19
  store i1 true, ptr %3, align 1
  br label %63

63:                                               ; preds = %57, %28, %16, %10
  %64 = load i1, ptr %3, align 1
  ret i1 %64
}

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

!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, !13, i64 24}
!12 = !{!"queue_iter", !6, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !13, i64 25}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !6, i64 0}
!18 = !{!12, !13, i64 25}
!19 = !{!12, !10, i64 8}
!20 = !{!21, !10, i64 8}
!21 = !{!"queue", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !22, i64 40, !6, i64 48, !6, i64 56}
!22 = !{!"int", !7, i64 0}


; 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
declare dso_local zeroext i1 @q_empty(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @q_iter_rewind(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i8, ptr %3, align 8, !tbaa !5, !range !12, !noundef !13
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %31, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %6
  store i8 1, ptr %3, align 8, !tbaa !5
  br label %31

11:                                               ; preds = %6
  %12 = add i64 %1, -1
  %or.cond.not = icmp ult i64 %12, %8
  br i1 %or.cond.not, label %13, label %31

13:                                               ; preds = %11
  %14 = load ptr, ptr %0, align 8, !tbaa !15
  %15 = tail call zeroext i1 @q_empty(ptr noundef %14)
  %16 = getelementptr inbounds i8, ptr %0, i64 25
  %17 = zext i1 %15 to i8
  store i8 %17, ptr %16, align 1, !tbaa !16
  %18 = load i64, ptr %7, align 8, !tbaa !14
  %19 = sub i64 %18, %1
  store i64 %19, ptr %7, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !17
  %22 = icmp ult i64 %21, %1
  br i1 %22, label %23, label %28

23:                                               ; preds = %13
  %24 = load ptr, ptr %0, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load i64, ptr %25, align 8, !tbaa !18
  %27 = add i64 %26, %21
  br label %28

28:                                               ; preds = %23, %13
  %29 = phi i64 [ %27, %23 ], [ %21, %13 ]
  %30 = sub i64 %29, %1
  store i64 %30, ptr %20, align 8, !tbaa !17
  br label %31

31:                                               ; preds = %11, %2, %28, %10
  %.0 = phi i1 [ false, %10 ], [ true, %28 ], [ false, %2 ], [ false, %11 ]
  ret i1 %.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" }

!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, !11, i64 24}
!6 = !{!"queue_iter", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !11, i64 25}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !11, i64 25}
!17 = !{!6, !10, i64 8}
!18 = !{!19, !10, i64 8}
!19 = !{!"queue", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !20, i64 40, !7, i64 48, !7, i64 56}
!20 = !{!"int", !8, i64 0}


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