; 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_next(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 4
  %6 = load i8, ptr %5, align 1, !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 %47

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 = add i64 %12, 1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.queue_iter, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = getelementptr inbounds %struct.queue, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 8, !tbaa !17
  %19 = icmp eq i64 %13, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.queue_iter, ptr %21, i32 0, i32 4
  store i8 1, ptr %22, align 1, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %47

23:                                               ; preds = %9
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.queue_iter, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = call zeroext i1 @q_empty(ptr noundef %26)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.queue_iter, ptr %28, i32 0, i32 3
  %30 = zext i1 %27 to i8
  store i8 %30, ptr %29, align 8, !tbaa !20
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.queue_iter, ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !21
  %34 = add i64 %33, 1
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.queue_iter, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds %struct.queue, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !22
  %40 = urem i64 %34, %39
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.queue_iter, ptr %41, i32 0, i32 1
  store i64 %40, ptr %42, align 8, !tbaa !21
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.queue_iter, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !15
  %46 = add i64 %45, 1
  store i64 %46, ptr %44, align 8, !tbaa !15
  store i1 true, ptr %2, align 1
  br label %47

47:                                               ; preds = %23, %20, %8
  %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, !12, i64 25}
!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 = !{!18, !11, i64 16}
!18 = !{!"queue", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !19, i64 40, !6, i64 48, !6, i64 56}
!19 = !{!"int", !7, i64 0}
!20 = !{!10, !12, i64 24}
!21 = !{!10, !11, i64 8}
!22 = !{!18, !11, i64 8}


; 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_next(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 25
  %3 = load i8, ptr %2, align 1, !tbaa !5, !range !12, !noundef !13
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %27, label %5

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

13:                                               ; preds = %5
  store i8 1, ptr %2, align 1, !tbaa !5
  br label %27

14:                                               ; preds = %5
  %15 = tail call zeroext i1 @q_empty(ptr noundef nonnull %9)
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  %17 = zext i1 %15 to i8
  store i8 %17, ptr %16, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !20
  %20 = add i64 %19, 1
  %21 = load ptr, ptr %0, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !21
  %24 = urem i64 %20, %23
  store i64 %24, ptr %18, align 8, !tbaa !20
  %25 = load i64, ptr %6, align 8, !tbaa !14
  %26 = add i64 %25, 1
  store i64 %26, ptr %6, align 8, !tbaa !14
  br label %27

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


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