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

; 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 }
%struct.list_fval = type { ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@__func__.l_index_of = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden void @cmc_log(i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ...) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @l_index_of(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  %12 = zext i1 %2 to i8
  store i8 %12, ptr %7, align 1, !tbaa !11
  call void (i32, ptr, ptr, i32, ptr, ...) @cmc_log(i32 noundef 1, ptr noundef @.str, ptr noundef @__func__.l_index_of, i32 noundef 415, ptr noundef @.str.1)
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.list, ptr %13, i32 0, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = icmp eq ptr %15, null
  br i1 %16, label %24, label %17

17:                                               ; preds = %3
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.list, ptr %18, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds %struct.list_fval, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %17, %3
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.list, ptr %25, i32 0, i32 3
  store i32 11, ptr %26, align 8, !tbaa !18
  store i64 0, ptr %4, align 8
  br label %101

27:                                               ; preds = %17
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.list, ptr %28, i32 0, i32 3
  store i32 0, ptr %29, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.list, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !19
  store i64 %32, ptr %8, align 8, !tbaa !20
  %33 = load i8, ptr %7, align 1, !tbaa !11, !range !21, !noundef !22
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %66

35:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !20
  br label %36

36:                                               ; preds = %61, %35
  %37 = load i64, ptr %9, align 8, !tbaa !20
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.list, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %39, align 8, !tbaa !19
  %41 = icmp ult i64 %37, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %36
  store i32 2, ptr %10, align 4
  br label %64

43:                                               ; preds = %36
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.list, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  %47 = getelementptr inbounds %struct.list_fval, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.list, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !23
  %52 = load i64, ptr %9, align 8, !tbaa !20
  %53 = getelementptr inbounds i32, ptr %51, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = call i32 %48(i32 noundef %54, i32 noundef %55)
  %57 = icmp eq i32 0, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %43
  %59 = load i64, ptr %9, align 8, !tbaa !20
  store i64 %59, ptr %8, align 8, !tbaa !20
  store i32 2, ptr %10, align 4
  br label %64

60:                                               ; preds = %43
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr %9, align 8, !tbaa !20
  %63 = add i64 %62, 1
  store i64 %63, ptr %9, align 8, !tbaa !20
  br label %36, !llvm.loop !24

64:                                               ; preds = %58, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %65

65:                                               ; preds = %64
  br label %99

66:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.list, ptr %67, i32 0, i32 2
  %69 = load i64, ptr %68, align 8, !tbaa !19
  store i64 %69, ptr %11, align 8, !tbaa !20
  br label %70

70:                                               ; preds = %94, %66
  %71 = load i64, ptr %11, align 8, !tbaa !20
  %72 = icmp ugt i64 %71, 0
  br i1 %72, label %74, label %73

73:                                               ; preds = %70
  store i32 5, ptr %10, align 4
  br label %97

74:                                               ; preds = %70
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.list, ptr %75, i32 0, i32 4
  %77 = load ptr, ptr %76, align 8, !tbaa !13
  %78 = getelementptr inbounds %struct.list_fval, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !16
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.list, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !23
  %83 = load i64, ptr %11, align 8, !tbaa !20
  %84 = sub i64 %83, 1
  %85 = getelementptr inbounds i32, ptr %82, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !9
  %87 = load i32, ptr %6, align 4, !tbaa !9
  %88 = call i32 %79(i32 noundef %86, i32 noundef %87)
  %89 = icmp eq i32 0, %88
  br i1 %89, label %90, label %93

90:                                               ; preds = %74
  %91 = load i64, ptr %11, align 8, !tbaa !20
  %92 = sub i64 %91, 1
  store i64 %92, ptr %8, align 8, !tbaa !20
  store i32 5, ptr %10, align 4
  br label %97

93:                                               ; preds = %74
  br label %94

94:                                               ; preds = %93
  %95 = load i64, ptr %11, align 8, !tbaa !20
  %96 = add i64 %95, -1
  store i64 %96, ptr %11, align 8, !tbaa !20
  br label %70, !llvm.loop !26

97:                                               ; preds = %90, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %98

98:                                               ; preds = %97
  br label %99

99:                                               ; preds = %98, %65
  %100 = load i64, ptr %8, align 8, !tbaa !20
  store i64 %100, ptr %4, align 8
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %101

101:                                              ; preds = %99, %24
  %102 = load i64, ptr %4, align 8
  ret i64 %102
}

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !6, i64 32}
!14 = !{!"list", !6, i64 0, !15, i64 8, !15, i64 16, !10, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"list_fval", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!14, !10, i64 24}
!19 = !{!14, !15, i64 16}
!20 = !{!15, !15, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!14, !6, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !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"

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@__func__.l_index_of = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden void @cmc_log(i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @l_index_of(ptr nocapture noundef %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  tail call void (i32, ptr, ptr, i32, ptr, ...) @cmc_log(i32 noundef 1, ptr noundef nonnull @.str, ptr noundef nonnull @__func__.l_index_of, i32 noundef 415, ptr noundef nonnull @.str.1)
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %10, label %7

7:                                                ; preds = %3
  %8 = load ptr, ptr %5, align 8, !tbaa !12
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %7, %3
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 11, ptr %11, align 8, !tbaa !14
  br label %.loopexit

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 0, ptr %13, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load i64, ptr %14, align 8, !tbaa !15
  br i1 %2, label %.preheader, label %.preheader27

.preheader:                                       ; preds = %12
  %.not33 = icmp eq i64 %15, 0
  br i1 %.not33, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %23
  %.02330 = phi i64 [ %24, %23 ], [ 0, %.preheader ]
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = load ptr, ptr %0, align 8, !tbaa !16
  %19 = getelementptr inbounds i32, ptr %18, i64 %.02330
  %20 = load i32, ptr %19, align 4, !tbaa !17
  %21 = tail call i32 %17(i32 noundef %20, i32 noundef %1) #1
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.loopexit, label %23

23:                                               ; preds = %.lr.ph
  %24 = add nuw i64 %.02330, 1
  %25 = load i64, ptr %14, align 8, !tbaa !15
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %.lr.ph, label %.loopexit, !llvm.loop !18

.preheader27:                                     ; preds = %12, %27
  %.0 = phi i64 [ %31, %27 ], [ %15, %12 ]
  %.not = icmp eq i64 %.0, 0
  br i1 %.not, label %.loopexit, label %27

27:                                               ; preds = %.preheader27
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = load ptr, ptr %0, align 8, !tbaa !16
  %31 = add i64 %.0, -1
  %32 = getelementptr inbounds i32, ptr %30, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !17
  %34 = tail call i32 %29(i32 noundef %33, i32 noundef %1) #1
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %.loopexit, label %.preheader27, !llvm.loop !20

.loopexit:                                        ; preds = %27, %.preheader27, %23, %.lr.ph, %.preheader, %10
  %.025 = phi i64 [ 0, %10 ], [ 0, %.preheader ], [ %15, %23 ], [ %.02330, %.lr.ph ], [ %31, %27 ], [ %15, %.preheader27 ]
  ret i64 %.025
}

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, !7, i64 32}
!6 = !{!"list", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40}
!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 = !{!13, !7, i64 0}
!13 = !{!"list_fval", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!14 = !{!6, !11, i64 24}
!15 = !{!6, !10, i64 16}
!16 = !{!6, !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass