; 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_to_end(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.queue_iter, ptr %4, i32 0, i32 0
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = call zeroext i1 @q_empty(ptr noundef %6)
  br i1 %7, label %46, label %8

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.queue_iter, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.queue, ptr %11, i32 0, i32 4
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %15, label %24

15:                                               ; preds = %8
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.queue_iter, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.queue, ptr %18, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !16
  %21 = sub i64 %20, 1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.queue_iter, ptr %22, i32 0, i32 1
  store i64 %21, ptr %23, align 8, !tbaa !17
  br label %33

24:                                               ; preds = %8
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.queue_iter, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.queue, ptr %27, i32 0, i32 4
  %29 = load i64, ptr %28, align 8, !tbaa !13
  %30 = sub i64 %29, 1
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.queue_iter, ptr %31, i32 0, i32 1
  store i64 %30, ptr %32, align 8, !tbaa !17
  br label %33

33:                                               ; preds = %24, %15
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.queue_iter, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.queue, ptr %36, i32 0, i32 2
  %38 = load i64, ptr %37, align 8, !tbaa !18
  %39 = sub i64 %38, 1
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.queue_iter, ptr %40, i32 0, i32 2
  store i64 %39, ptr %41, align 8, !tbaa !19
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.queue_iter, ptr %42, i32 0, i32 3
  store i8 0, ptr %43, align 8, !tbaa !20
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.queue_iter, ptr %44, i32 0, i32 4
  store i8 1, ptr %45, align 1, !tbaa !21
  store i1 true, ptr %2, align 1
  br label %47

46:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %47

47:                                               ; preds = %46, %33
  %48 = load i1, ptr %2, align 1
  ret i1 %48
}

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


; 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_to_end(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = tail call zeroext i1 @q_empty(ptr noundef %2)
  br i1 %3, label %20, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 32
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !15
  br label %12

12:                                               ; preds = %4, %9
  %.sink.in = phi i64 [ %11, %9 ], [ %7, %4 ]
  %.sink = add i64 %.sink.in, -1
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %.sink, ptr %13, align 8
  %14 = getelementptr inbounds i8, ptr %5, i64 16
  %15 = load i64, ptr %14, align 8, !tbaa !16
  %16 = add i64 %15, -1
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %16, ptr %17, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 0, ptr %18, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %0, i64 25
  store i8 1, ptr %19, align 1, !tbaa !19
  br label %20

20:                                               ; preds = %1, %12
  %.0 = xor i1 %3, true
  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, !7, i64 0}
!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 = !{!13, !10, i64 32}
!13 = !{!"queue", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !14, i64 40, !7, i64 48, !7, i64 56}
!14 = !{!"int", !8, i64 0}
!15 = !{!13, !10, i64 8}
!16 = !{!13, !10, i64 16}
!17 = !{!6, !10, i64 16}
!18 = !{!6, !11, i64 24}
!19 = !{!6, !11, i64 25}


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