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

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

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

21:                                               ; preds = %8
  %22 = getelementptr inbounds %struct.queue_iter, ptr %0, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.queue, ptr %23, i32 0, i32 4
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = sub i64 %25, 1
  %27 = getelementptr inbounds %struct.queue_iter, ptr %0, i32 0, i32 1
  store i64 %26, ptr %27, align 8, !tbaa !17
  br label %28

28:                                               ; preds = %21, %14
  %29 = getelementptr inbounds %struct.queue_iter, ptr %0, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.queue, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !18
  %33 = sub i64 %32, 1
  %34 = getelementptr inbounds %struct.queue_iter, ptr %0, i32 0, i32 2
  store i64 %33, ptr %34, align 8, !tbaa !19
  br label %38

35:                                               ; preds = %2
  %36 = getelementptr inbounds %struct.queue_iter, ptr %0, i32 0, i32 1
  store i64 0, ptr %36, align 8, !tbaa !17
  %37 = getelementptr inbounds %struct.queue_iter, ptr %0, i32 0, i32 2
  store i64 0, ptr %37, align 8, !tbaa !19
  br label %38

38:                                               ; preds = %35, %28
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = call zeroext i1 @q_empty(ptr noundef %39)
  %41 = getelementptr inbounds %struct.queue_iter, ptr %0, i32 0, i32 3
  %42 = zext i1 %40 to i8
  store i8 %42, ptr %41, align 8, !tbaa !20
  %43 = getelementptr inbounds %struct.queue_iter, ptr %0, i32 0, i32 4
  store i8 1, ptr %43, align 1, !tbaa !21
  ret void
}

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"

%struct.queue_iter = type { ptr, i64, i64, i8, i8 }

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

; Function Attrs: nounwind uwtable
define dso_local void @q_iter_end(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.queue_iter) align 8 %0, ptr noundef %1) local_unnamed_addr #0 {
  store ptr %1, ptr %0, align 8, !tbaa !5
  %3 = tail call zeroext i1 @q_empty(ptr noundef %1)
  br i1 %3, label %17, label %4

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

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

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

17:                                               ; preds = %2
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %18, i8 0, i64 16, i1 false)
  br label %19

19:                                               ; preds = %17, %11
  %20 = tail call zeroext i1 @q_empty(ptr noundef %1)
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = zext i1 %20 to i8
  store i8 %22, ptr %21, align 8, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %0, i64 25
  store i8 1, ptr %23, align 1, !tbaa !19
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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,MemCpyOptPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass