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

@stderr = external global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [23 x i8], align 1
@cmc_flags_to_str = external hidden global [12 x ptr], align 16
@stdout = external global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local void @l_free(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @l_flag(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @l_iter_start(ptr dead_on_unwind noalias writable sret(%struct.list_iter) align 8, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @l_iter_rvalue(ptr noundef) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca %struct.list_fval, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.list_iter, align 8
  %8 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 48, i1 false)
  %9 = getelementptr inbounds %struct.list_fval, ptr %3, i32 0, i32 0
  %10 = getelementptr inbounds %struct.list_fval, ptr %3, i32 0, i32 1
  %11 = getelementptr inbounds %struct.list_fval, ptr %3, i32 0, i32 2
  store ptr @cmc_i32_str, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.list_fval, ptr %3, i32 0, i32 3
  %13 = getelementptr inbounds %struct.list_fval, ptr %3, i32 0, i32 4
  %14 = getelementptr inbounds %struct.list_fval, ptr %3, i32 0, i32 5
  %15 = call ptr @l_new(i64 noundef 32, ptr noundef %3)
  store ptr %15, ptr %2, align 8, !tbaa !10
  %16 = load ptr, ptr %2, align 8, !tbaa !10
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %22

18:                                               ; preds = %0
  %19 = load ptr, ptr %2, align 8, !tbaa !10
  %20 = call i32 @l_flag(ptr noundef %19)
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %18, %0
  store i32 1, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %69

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %42, %23
  %25 = load i32, ptr %5, align 4, !tbaa !11
  %26 = icmp slt i32 %25, 100
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %45

28:                                               ; preds = %24
  %29 = load ptr, ptr %2, align 8, !tbaa !10
  %30 = load i32, ptr %5, align 4, !tbaa !11
  %31 = call zeroext i1 @l_push_back(ptr noundef %29, i32 noundef %30)
  br i1 %31, label %41, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %33 = load ptr, ptr %2, align 8, !tbaa !10
  %34 = call i32 @l_flag(ptr noundef %33)
  store i32 %34, ptr %6, align 4, !tbaa !11
  %35 = load ptr, ptr @stderr, align 8, !tbaa !10
  %36 = load i32, ptr %6, align 4, !tbaa !11
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds [12 x ptr], ptr @cmc_flags_to_str, i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !10
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.7, ptr noundef %39) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %41

41:                                               ; preds = %32, %28
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %5, align 4, !tbaa !11
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %5, align 4, !tbaa !11
  br label %24, !llvm.loop !13

45:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #5
  %46 = load ptr, ptr %2, align 8, !tbaa !10
  call void @l_iter_start(ptr dead_on_unwind writable sret(%struct.list_iter) align 8 %7, ptr noundef %46)
  br label %47

47:                                               ; preds = %60, %45
  %48 = call zeroext i1 @l_iter_at_end(ptr noundef %7)
  %49 = xor i1 %48, true
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #5
  br label %62

51:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %52 = call ptr @l_iter_rvalue(ptr noundef %7)
  store ptr %52, ptr %8, align 8, !tbaa !10
  %53 = load ptr, ptr %8, align 8, !tbaa !10
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %59

55:                                               ; preds = %51
  %56 = load ptr, ptr %8, align 8, !tbaa !10
  %57 = load i32, ptr %56, align 4, !tbaa !11
  %58 = mul nsw i32 %57, 2
  store i32 %58, ptr %56, align 4, !tbaa !11
  br label %59

59:                                               ; preds = %55, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %60

60:                                               ; preds = %59
  %61 = call zeroext i1 @l_iter_next(ptr noundef %7)
  br label %47, !llvm.loop !15

62:                                               ; preds = %50
  %63 = load ptr, ptr %2, align 8, !tbaa !10
  %64 = load ptr, ptr @stdout, align 8, !tbaa !10
  %65 = call zeroext i1 @l_print(ptr noundef %63, ptr noundef %64, ptr noundef @.str.8, ptr noundef @.str.9, ptr noundef @.str.10)
  br i1 %65, label %67, label %66

66:                                               ; preds = %62
  store i32 2, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %69

67:                                               ; preds = %62
  %68 = load ptr, ptr %2, align 8, !tbaa !10
  call void @l_free(ptr noundef %68)
  store i32 0, ptr %4, align 4
  br label %69

69:                                               ; preds = %67, %66, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %70 = load i32, ptr %4, align 4
  switch i32 %70, label %73 [
    i32 0, label %71
    i32 1, label %71
  ]

71:                                               ; preds = %69, %69
  %72 = load i32, ptr %1, align 4
  ret i32 %72

73:                                               ; preds = %69
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @cmc_i32_str(ptr noundef, i32 noundef) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind "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 #4 = { inlinehint 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 #5 = { 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 16}
!6 = !{!"list_fval", !7, i64 0, !7, i64 8, !7, i64 16, !7, 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 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [23 x i8], align 1
@cmc_flags_to_str = external hidden local_unnamed_addr global [12 x ptr], align 16
@stdout = external local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @l_new(i64 noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare dso_local void @l_free(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @l_flag(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @l_iter_start(ptr dead_on_unwind noalias writable sret(%struct.list_iter) align 8, ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.list_fval, align 8
  %2 = alloca %struct.list_iter, align 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %1, i8 0, i64 48, i1 false)
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr @cmc_i32_str, ptr %3, align 8, !tbaa !5
  %4 = call ptr @l_new(i64 noundef 32, ptr noundef nonnull %1)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %29, label %5

5:                                                ; preds = %0
  %6 = call i32 @l_flag(ptr noundef nonnull %4)
  %.not16 = icmp eq i32 %6, 0
  br i1 %.not16, label %.preheader, label %29

7:                                                ; preds = %17
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  call void @l_iter_start(ptr dead_on_unwind nonnull writable sret(%struct.list_iter) align 8 %2, ptr noundef nonnull %4)
  %8 = call zeroext i1 @l_iter_at_end(ptr noundef nonnull %2)
  br i1 %8, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %5, %17
  %.01318 = phi i32 [ %18, %17 ], [ 0, %5 ]
  %9 = call zeroext i1 @l_push_back(ptr noundef nonnull %4, i32 noundef %.01318)
  br i1 %9, label %17, label %10

10:                                               ; preds = %.preheader
  %11 = call i32 @l_flag(ptr noundef nonnull %4)
  %12 = load ptr, ptr @stderr, align 8, !tbaa !10
  %13 = zext i32 %11 to i64
  %14 = getelementptr inbounds [12 x ptr], ptr @cmc_flags_to_str, i64 0, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.7, ptr noundef %15) #6
  br label %17

17:                                               ; preds = %.preheader, %10
  %18 = add nuw nsw i32 %.01318, 1
  %exitcond.not = icmp eq i32 %18, 100
  br i1 %exitcond.not, label %7, label %.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %25, %7
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  %19 = load ptr, ptr @stdout, align 8, !tbaa !10
  %20 = call zeroext i1 @l_print(ptr noundef nonnull %4, ptr noundef %19, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.10)
  br i1 %20, label %28, label %29

.lr.ph:                                           ; preds = %7, %25
  %21 = call ptr @l_iter_rvalue(ptr noundef nonnull %2)
  %.not17 = icmp eq ptr %21, null
  br i1 %.not17, label %25, label %22

22:                                               ; preds = %.lr.ph
  %23 = load i32, ptr %21, align 4, !tbaa !13
  %24 = shl nsw i32 %23, 1
  store i32 %24, ptr %21, align 4, !tbaa !13
  br label %25

25:                                               ; preds = %22, %.lr.ph
  %26 = call zeroext i1 @l_iter_next(ptr noundef nonnull %2)
  %27 = call zeroext i1 @l_iter_at_end(ptr noundef nonnull %2)
  br i1 %27, label %._crit_edge, label %.lr.ph, !llvm.loop !15

28:                                               ; preds = %._crit_edge
  call void @l_free(ptr noundef nonnull %4)
  br label %29

29:                                               ; preds = %._crit_edge, %0, %5, %28
  %.0 = phi i32 [ 0, %28 ], [ 1, %5 ], [ 1, %0 ], [ 2, %._crit_edge ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @cmc_i32_str(ptr noundef, i32 noundef) #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nofree nounwind "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 #4 = { inlinehint 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 #5 = { nounwind }
attributes #6 = { cold 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 16}
!6 = !{!"list_fval", !7, i64 0, !7, i64 8, !7, i64 16, !7, 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 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = distinct !{!15, !12}


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