; 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_prev(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 3
  %6 = load i8, ptr %5, align 8, !tbaa !9, !range !13, !noundef !14
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i1 false, ptr %2, align 1
  br label %49

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

14:                                               ; preds = %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.queue_iter, ptr %15, i32 0, i32 3
  store i8 1, ptr %16, align 8, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %49

17:                                               ; preds = %9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.queue_iter, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = call zeroext i1 @q_empty(ptr noundef %20)
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.queue_iter, ptr %22, i32 0, i32 4
  %24 = zext i1 %21 to i8
  store i8 %24, ptr %23, align 1, !tbaa !17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.queue_iter, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !18
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %36

29:                                               ; preds = %17
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.queue_iter, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds %struct.queue, ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !19
  %35 = sub i64 %34, 1
  br label %41

36:                                               ; preds = %17
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.queue_iter, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !18
  %40 = sub i64 %39, 1
  br label %41

41:                                               ; preds = %36, %29
  %42 = phi i64 [ %35, %29 ], [ %40, %36 ]
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.queue_iter, ptr %43, i32 0, i32 1
  store i64 %42, ptr %44, align 8, !tbaa !18
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.queue_iter, ptr %45, i32 0, i32 2
  %47 = load i64, ptr %46, align 8, !tbaa !15
  %48 = add i64 %47, -1
  store i64 %48, ptr %46, align 8, !tbaa !15
  store i1 true, ptr %2, align 1
  br label %49

49:                                               ; preds = %41, %14, %8
  %50 = load i1, ptr %2, align 1
  ret i1 %50
}

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, !12, i64 24}
!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 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !6, i64 0}
!17 = !{!10, !12, i64 25}
!18 = !{!10, !11, i64 8}
!19 = !{!20, !11, i64 8}
!20 = !{!"queue", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !21, i64 40, !6, i64 48, !6, i64 56}
!21 = !{!"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_prev(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load i8, ptr %2, align 8, !tbaa !5, !range !12, !noundef !13
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %26, label %5

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

9:                                                ; preds = %5
  store i8 1, ptr %2, align 8, !tbaa !5
  br label %26

10:                                               ; preds = %5
  %11 = load ptr, ptr %0, align 8, !tbaa !15
  %12 = tail call zeroext i1 @q_empty(ptr noundef %11)
  %13 = getelementptr inbounds i8, ptr %0, i64 25
  %14 = zext i1 %12 to i8
  store i8 %14, ptr %13, align 1, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !17
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %10
  %19 = load ptr, ptr %0, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !18
  br label %22

22:                                               ; preds = %10, %18
  %.in = phi i64 [ %21, %18 ], [ %16, %10 ]
  %23 = add i64 %.in, -1
  store i64 %23, ptr %15, align 8, !tbaa !17
  %24 = load i64, ptr %6, align 8, !tbaa !14
  %25 = add i64 %24, -1
  store i64 %25, ptr %6, align 8, !tbaa !14
  br label %26

26:                                               ; preds = %1, %22, %9
  %.0 = phi i1 [ false, %9 ], [ true, %22 ], [ false, %1 ]
  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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass