; 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 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @l_fits(ptr noundef, i64 noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @l_seq_push_front(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @l_seq_push_at(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #1 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  %10 = load i64, ptr %8, align 8, !tbaa !9
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %4
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.list, ptr %13, i32 0, i32 2
  store i32 4, ptr %14, align 8, !tbaa !11
  store i1 false, ptr %5, align 1
  br label %85

15:                                               ; preds = %4
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.list, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !14
  %20 = icmp ugt i64 %16, %19
  br i1 %20, label %21, label %24

21:                                               ; preds = %15
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.list, ptr %22, i32 0, i32 2
  store i32 5, ptr %23, align 8, !tbaa !11
  store i1 false, ptr %5, align 1
  br label %85

24:                                               ; preds = %15
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %24
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = call zeroext i1 @l_seq_push_front(ptr noundef %28, ptr noundef %29, i64 noundef %30)
  store i1 %31, ptr %5, align 1
  br label %85

32:                                               ; preds = %24
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.list, ptr %34, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !14
  %37 = icmp eq i64 %33, %36
  br i1 %37, label %38, label %43

38:                                               ; preds = %32
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = call zeroext i1 @l_seq_push_back(ptr noundef %39, ptr noundef %40, i64 noundef %41)
  store i1 %42, ptr %5, align 1
  br label %85

43:                                               ; preds = %32
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = call zeroext i1 @l_fits(ptr noundef %45, i64 noundef %46)
  br i1 %47, label %51, label %48

48:                                               ; preds = %44
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.list, ptr %49, i32 0, i32 2
  store i32 10, ptr %50, align 8, !tbaa !11
  store i1 false, ptr %5, align 1
  br label %85

51:                                               ; preds = %44
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.list, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [100 x i32], ptr %53, i64 0, i64 0
  %55 = load i64, ptr %9, align 8, !tbaa !9
  %56 = getelementptr inbounds i32, ptr %54, i64 %55
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = getelementptr inbounds i32, ptr %56, i64 %57
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.list, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds [100 x i32], ptr %60, i64 0, i64 0
  %62 = load i64, ptr %9, align 8, !tbaa !9
  %63 = getelementptr inbounds i32, ptr %61, i64 %62
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.list, ptr %64, i32 0, i32 1
  %66 = load i64, ptr %65, align 8, !tbaa !14
  %67 = load i64, ptr %9, align 8, !tbaa !9
  %68 = sub i64 %66, %67
  %69 = mul i64 %68, 4
  call void @llvm.memmove.p0.p0.i64(ptr align 4 %58, ptr align 4 %63, i64 %69, i1 false)
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.list, ptr %70, i32 0, i32 0
  %72 = getelementptr inbounds [100 x i32], ptr %71, i64 0, i64 0
  %73 = load i64, ptr %9, align 8, !tbaa !9
  %74 = getelementptr inbounds i32, ptr %72, i64 %73
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = load i64, ptr %8, align 8, !tbaa !9
  %77 = mul i64 %76, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %74, ptr align 4 %75, i64 %77, i1 false)
  %78 = load i64, ptr %8, align 8, !tbaa !9
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.list, ptr %79, i32 0, i32 1
  %81 = load i64, ptr %80, align 8, !tbaa !14
  %82 = add i64 %81, %78
  store i64 %82, ptr %80, align 8, !tbaa !14
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.list, ptr %83, i32 0, i32 2
  store i32 0, ptr %84, align 8, !tbaa !11
  store i1 true, ptr %5, align 1
  br label %85

85:                                               ; preds = %51, %48, %38, %27, %21, %12
  %86 = load i1, ptr %5, align 1
  ret i1 %86
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @l_seq_push_back(ptr noundef, ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 408}
!12 = !{!"list", !7, i64 0, !10, i64 400, !13, i64 408, !6, i64 416, !6, i64 424}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 400}


; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @l_fits(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @l_seq_push_front(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @l_seq_push_at(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = icmp eq i64 %2, 0
  br i1 %5, label %6, label %8

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 408
  store i32 4, ptr %7, align 8, !tbaa !5
  br label %36

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 400
  %10 = load i64, ptr %9, align 8, !tbaa !12
  %11 = icmp ult i64 %10, %3
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 408
  store i32 5, ptr %13, align 8, !tbaa !5
  br label %36

14:                                               ; preds = %8
  %15 = icmp eq i64 %3, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %14
  %17 = tail call zeroext i1 @l_seq_push_front(ptr noundef nonnull %0, ptr noundef %1, i64 noundef %2)
  br label %36

18:                                               ; preds = %14
  %19 = icmp eq i64 %10, %3
  br i1 %19, label %20, label %22

20:                                               ; preds = %18
  %21 = tail call zeroext i1 @l_seq_push_back(ptr noundef nonnull %0, ptr noundef %1, i64 noundef %2)
  br label %36

22:                                               ; preds = %18
  %23 = tail call zeroext i1 @l_fits(ptr noundef nonnull %0, i64 noundef %2)
  br i1 %23, label %26, label %24

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %0, i64 408
  store i32 10, ptr %25, align 8, !tbaa !5
  br label %36

26:                                               ; preds = %22
  %27 = getelementptr inbounds i32, ptr %0, i64 %3
  %28 = getelementptr inbounds i32, ptr %27, i64 %2
  %29 = load i64, ptr %9, align 8, !tbaa !12
  %30 = sub i64 %29, %3
  %31 = shl i64 %30, 2
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 4 %28, ptr nonnull align 4 %27, i64 %31, i1 false)
  %32 = shl i64 %2, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %27, ptr align 4 %1, i64 %32, i1 false)
  %33 = load i64, ptr %9, align 8, !tbaa !12
  %34 = add i64 %33, %2
  store i64 %34, ptr %9, align 8, !tbaa !12
  %35 = getelementptr inbounds i8, ptr %0, i64 408
  store i32 0, ptr %35, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %26, %24, %20, %16, %12, %6
  %.0 = phi i1 [ false, %6 ], [ false, %12 ], [ %17, %16 ], [ %21, %20 ], [ true, %26 ], [ false, %24 ]
  ret i1 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @l_seq_push_back(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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, !10, i64 408}
!6 = !{!"list", !7, i64 0, !9, i64 400, !10, i64 408, !11, i64 416, !11, i64 424}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!6, !9, i64 400}


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