; LLVM IR from LeoVen/C-Macro-Collections :: examples (sac_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 { [100 x i32], i64, i32, ptr, ptr }
%struct.list_iter = type { ptr, i64, i8, i8 }
%struct.list_fval = type { ptr, ptr, ptr, ptr, ptr, ptr }

@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1
@stderr = external global ptr, align 8
@.str.5 = 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.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @l_release(ptr noundef byval(%struct.list) align 8) #2

; 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) #2

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

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

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

; 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) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.list, 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 432, ptr %2) #6
  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
  call void @l_init(ptr dead_on_unwind writable sret(%struct.list) align 8 %2, ptr noundef %3)
  %15 = call i32 @l_flag(ptr noundef %2)
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %0
  store i32 1, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %66

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

19:                                               ; preds = %41, %18
  %20 = load i32, ptr %5, align 4, !tbaa !10
  %21 = icmp slt i32 %20, 1000
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i32 2, ptr %4, align 4
  br label %44

23:                                               ; preds = %19
  %24 = load i32, ptr %5, align 4, !tbaa !10
  %25 = call zeroext i1 @l_push_back(ptr noundef %2, i32 noundef %24)
  br i1 %25, label %40, label %26

26:                                               ; preds = %23
  %27 = call i32 @l_flag(ptr noundef %2)
  %28 = icmp eq i32 %27, 10
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  store i32 2, ptr %4, align 4
  br label %44

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

39:                                               ; preds = %31
  br label %40

40:                                               ; preds = %39, %23
  br label %41

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

44:                                               ; preds = %29, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %45

45:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #6
  call void @l_iter_start(ptr dead_on_unwind writable sret(%struct.list_iter) align 8 %7, ptr noundef %2)
  br label %46

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

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

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %51 = call ptr @l_iter_rvalue(ptr noundef %7)
  store ptr %51, ptr %8, align 8, !tbaa !12
  %52 = load ptr, ptr %8, align 8, !tbaa !12
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %58

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

58:                                               ; preds = %54, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %59

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

61:                                               ; preds = %49
  %62 = load ptr, ptr @stdout, align 8, !tbaa !12
  %63 = call zeroext i1 @l_print(ptr noundef %2, ptr noundef %62, ptr noundef @.str.6, ptr noundef @.str.7, ptr noundef @.str.8)
  br i1 %63, label %65, label %64

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

65:                                               ; preds = %61
  call void @l_release(ptr noundef byval(%struct.list) align 8 %2)
  store i32 0, ptr %4, align 4
  br label %66

66:                                               ; preds = %65, %64, %17
  call void @llvm.lifetime.end.p0(i64 432, ptr %2) #6
  %67 = load i32, ptr %4, align 4
  switch i32 %67, label %70 [
    i32 0, label %68
    i32 1, label %68
  ]

68:                                               ; preds = %66, %66
  %69 = load i32, ptr %1, align 4
  ret i32 %69

70:                                               ; preds = %66
  unreachable
}

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

declare i32 @printf(ptr noundef, ...) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #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 = { "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 #6 = { 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 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, 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 = type { [100 x i32], i64, i32, ptr, ptr }
%struct.list_iter = type { ptr, i64, i8, i8 }
%struct.list_fval = type { ptr, ptr, ptr, ptr, ptr, ptr }

@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.5 = 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.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @l_release(ptr noundef byval(%struct.list) align 8) local_unnamed_addr #2

; 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 #2

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

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

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

; 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 #2

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

.preheader:                                       ; preds = %0, %19
  %.069 = phi i32 [ %20, %19 ], [ 1, %0 ]
  %6 = call zeroext i1 @l_push_back(ptr noundef nonnull %1, i32 noundef %.069)
  br i1 %6, label %19, label %7

7:                                                ; preds = %.preheader
  %8 = call i32 @l_flag(ptr noundef nonnull %1)
  %9 = icmp eq i32 %8, 10
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %.loopexit

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

19:                                               ; preds = %.preheader, %12
  %20 = add nuw nsw i32 %.069, 1
  %exitcond.not = icmp eq i32 %20, 1000
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !11

.loopexit:                                        ; preds = %19, %10
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @l_iter_start(ptr dead_on_unwind nonnull writable sret(%struct.list_iter) align 8 %3, ptr noundef nonnull %1)
  %21 = call zeroext i1 @l_iter_at_end(ptr noundef nonnull %3)
  br i1 %21, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %28, %.loopexit
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  %22 = load ptr, ptr @stdout, align 8, !tbaa !10
  %23 = call zeroext i1 @l_print(ptr noundef nonnull %1, ptr noundef %22, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.8)
  br i1 %23, label %31, label %32

.lr.ph:                                           ; preds = %.loopexit, %28
  %24 = call ptr @l_iter_rvalue(ptr noundef nonnull %3)
  %.not8 = icmp eq ptr %24, null
  br i1 %.not8, label %28, label %25

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

28:                                               ; preds = %25, %.lr.ph
  %29 = call zeroext i1 @l_iter_next(ptr noundef nonnull %3)
  %30 = call zeroext i1 @l_iter_at_end(ptr noundef nonnull %3)
  br i1 %30, label %._crit_edge, label %.lr.ph, !llvm.loop !15

31:                                               ; preds = %._crit_edge
  call void @l_release(ptr noundef nonnull byval(%struct.list) align 8 %1)
  br label %32

32:                                               ; preds = %._crit_edge, %0, %31
  %.0 = phi i32 [ 0, %31 ], [ 1, %0 ], [ 2, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 432, ptr nonnull %1) #5
  ret i32 %.0
}

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #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