; 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_advance(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 4
  %8 = load i8, ptr %7, align 1, !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 %67

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

22:                                               ; preds = %11
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.queue_iter, ptr %23, i32 0, i32 4
  store i8 1, ptr %24, align 1, !tbaa !11
  store i1 false, ptr %3, align 1
  br label %67

25:                                               ; preds = %11
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %40, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.queue_iter, ptr %29, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !16
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = add i64 %31, %32
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.queue_iter, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = getelementptr inbounds %struct.queue, ptr %36, i32 0, i32 2
  %38 = load i64, ptr %37, align 8, !tbaa !18
  %39 = icmp uge i64 %33, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %28, %25
  store i1 false, ptr %3, align 1
  br label %67

41:                                               ; preds = %28
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.queue_iter, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = call zeroext i1 @q_empty(ptr noundef %44)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.queue_iter, ptr %46, i32 0, i32 3
  %48 = zext i1 %45 to i8
  store i8 %48, ptr %47, align 8, !tbaa !21
  %49 = load i64, ptr %5, align 8, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.queue_iter, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !16
  %53 = add i64 %52, %49
  store i64 %53, ptr %51, align 8, !tbaa !16
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.queue_iter, ptr %54, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !22
  %57 = load i64, ptr %5, align 8, !tbaa !9
  %58 = add i64 %56, %57
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.queue_iter, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !17
  %62 = getelementptr inbounds %struct.queue, ptr %61, i32 0, i32 1
  %63 = load i64, ptr %62, align 8, !tbaa !23
  %64 = urem i64 %58, %63
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.queue_iter, ptr %65, i32 0, i32 1
  store i64 %64, ptr %66, align 8, !tbaa !22
  store i1 true, ptr %3, align 1
  br label %67

67:                                               ; preds = %41, %40, %22, %10
  %68 = load i1, ptr %3, align 1
  ret i1 %68
}

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 25}
!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 = !{!19, !10, i64 16}
!19 = !{!"queue", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !20, i64 40, !6, i64 48, !6, i64 56}
!20 = !{!"int", !7, i64 0}
!21 = !{!12, !13, i64 24}
!22 = !{!12, !10, i64 8}
!23 = !{!19, !10, 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_advance(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 25
  %4 = load i8, ptr %3, align 1, !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 = add i64 %8, 1
  %10 = load ptr, ptr %0, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load i64, ptr %11, align 8, !tbaa !16
  %13 = icmp eq i64 %9, %12
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %6
  %16 = icmp ne i64 %1, 0
  %17 = add i64 %8, %1
  %.not = icmp ult i64 %17, %12
  %or.cond = and i1 %16, %.not
  br i1 %or.cond, label %18, label %31

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

31:                                               ; preds = %15, %2, %18, %14
  %.0 = phi i1 [ false, %14 ], [ true, %18 ], [ false, %2 ], [ false, %15 ]
  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