; LLVM IR from LeoVen/C-Macro-Collections :: examples (callbacks)

; 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.list = type { ptr, i64, i64, i32, ptr, ptr, ptr }

@__func__.l_get = external hidden unnamed_addr constant [6 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @l_get(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call zeroext i1 @l_empty(ptr noundef %8)
  br i1 %9, label %10, label %24

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.list, ptr %11, i32 0, i32 3
  store i32 2, ptr %12, align 8, !tbaa !11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.list, ptr %13, i32 0, i32 6
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %22

17:                                               ; preds = %10
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.list, ptr %18, i32 0, i32 6
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  call void %20(ptr noundef @__func__.l_get, ptr noundef %21)
  br label %22

22:                                               ; preds = %17, %10
  store i32 0, ptr %6, align 4, !tbaa !15
  %23 = load i32, ptr %6, align 4, !tbaa !15
  store i32 %23, ptr %3, align 4
  br label %63

24:                                               ; preds = %2
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.list, ptr %26, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !16
  %29 = icmp uge i64 %25, %28
  br i1 %29, label %30, label %44

30:                                               ; preds = %24
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.list, ptr %31, i32 0, i32 3
  store i32 5, ptr %32, align 8, !tbaa !11
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.list, ptr %33, i32 0, i32 6
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %42

37:                                               ; preds = %30
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.list, ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  call void %40(ptr noundef @__func__.l_get, ptr noundef %41)
  br label %42

42:                                               ; preds = %37, %30
  store i32 0, ptr %7, align 4, !tbaa !15
  %43 = load i32, ptr %7, align 4, !tbaa !15
  store i32 %43, ptr %3, align 4
  br label %63

44:                                               ; preds = %24
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.list, ptr %45, i32 0, i32 3
  store i32 0, ptr %46, align 8, !tbaa !11
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.list, ptr %47, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %56

51:                                               ; preds = %44
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.list, ptr %52, i32 0, i32 6
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void %54(ptr noundef @__func__.l_get, ptr noundef %55)
  br label %56

56:                                               ; preds = %51, %44
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.list, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !17
  %60 = load i64, ptr %5, align 8, !tbaa !9
  %61 = getelementptr inbounds i32, ptr %59, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !15
  store i32 %62, ptr %3, align 4
  br label %63

63:                                               ; preds = %56, %42, %22
  %64 = load i32, ptr %3, align 4
  ret i32 %64
}

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 24}
!12 = !{!"list", !6, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 48}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !6, 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"

@__func__.l_get = external hidden unnamed_addr constant [6 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @l_get(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call zeroext i1 @l_empty(ptr noundef %0)
  br i1 %3, label %4, label %9

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 2, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %.not25 = icmp eq ptr %7, null
  br i1 %.not25, label %24, label %8

8:                                                ; preds = %4
  tail call void %7(ptr noundef nonnull @__func__.l_get, ptr noundef nonnull %0) #1
  br label %24

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %.not = icmp ugt i64 %11, %1
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = getelementptr inbounds i8, ptr %0, i64 48
  br i1 %.not, label %17, label %14

14:                                               ; preds = %9
  store i32 5, ptr %12, align 8, !tbaa !5
  %15 = load ptr, ptr %13, align 8, !tbaa !12
  %.not24 = icmp eq ptr %15, null
  br i1 %.not24, label %24, label %16

16:                                               ; preds = %14
  tail call void %15(ptr noundef nonnull @__func__.l_get, ptr noundef nonnull %0) #1
  br label %24

17:                                               ; preds = %9
  store i32 0, ptr %12, align 8, !tbaa !5
  %18 = load ptr, ptr %13, align 8, !tbaa !12
  %.not23 = icmp eq ptr %18, null
  br i1 %.not23, label %20, label %19

19:                                               ; preds = %17
  tail call void %18(ptr noundef nonnull @__func__.l_get, ptr noundef nonnull %0) #1
  br label %20

20:                                               ; preds = %19, %17
  %21 = load ptr, ptr %0, align 8, !tbaa !14
  %22 = getelementptr inbounds i32, ptr %21, i64 %1
  %23 = load i32, ptr %22, align 4, !tbaa !15
  br label %24

24:                                               ; preds = %14, %16, %4, %8, %20
  %.0 = phi i32 [ %23, %20 ], [ 0, %8 ], [ 0, %4 ], [ 0, %16 ], [ 0, %14 ]
  ret i32 %.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" }
attributes #1 = { nounwind }

!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 = !{!"list", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 48}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !7, i64 0}
!15 = !{!11, !11, i64 0}


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