; LLVM IR from LeoVen/C-Macro-Collections :: examples (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.int_list_fval = type { ptr, ptr, ptr, ptr, ptr, ptr }

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @intl_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 @intl_free(ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @intl_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.int_list_fval, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  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)
  %7 = getelementptr inbounds %struct.int_list_fval, ptr %3, i32 0, i32 0
  %8 = getelementptr inbounds %struct.int_list_fval, ptr %3, i32 0, i32 1
  %9 = getelementptr inbounds %struct.int_list_fval, ptr %3, i32 0, i32 2
  store ptr @cmc_i32_str, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.int_list_fval, ptr %3, i32 0, i32 3
  %11 = getelementptr inbounds %struct.int_list_fval, ptr %3, i32 0, i32 4
  %12 = getelementptr inbounds %struct.int_list_fval, ptr %3, i32 0, i32 5
  %13 = call ptr @intl_new(i64 noundef 32, ptr noundef %3)
  store ptr %13, ptr %2, align 8, !tbaa !10
  %14 = load ptr, ptr %2, align 8, !tbaa !10
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %0
  store i32 1, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %44

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

18:                                               ; preds = %36, %17
  %19 = load i32, ptr %5, align 4, !tbaa !11
  %20 = icmp slt i32 %19, 100
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %18
  %23 = load ptr, ptr %2, align 8, !tbaa !10
  %24 = load i32, ptr %5, align 4, !tbaa !11
  %25 = call zeroext i1 @intl_push_back(ptr noundef %23, i32 noundef %24)
  br i1 %25, label %35, label %26

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

35:                                               ; preds = %26, %22
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %5, align 4, !tbaa !11
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !11
  br label %18, !llvm.loop !13

39:                                               ; preds = %21
  %40 = load ptr, ptr %2, align 8, !tbaa !10
  %41 = load ptr, ptr @stdout, align 8, !tbaa !10
  %42 = call zeroext i1 @intl_print(ptr noundef %40, ptr noundef %41, ptr noundef @.str.5, ptr noundef @.str.6, ptr noundef @.str.7)
  %43 = load ptr, ptr %2, align 8, !tbaa !10
  call void @intl_free(ptr noundef %43)
  store i32 0, ptr %4, align 4
  br label %44

44:                                               ; preds = %39, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %45 = load i32, ptr %4, align 4
  switch i32 %45, label %48 [
    i32 0, label %46
    i32 1, label %46
  ]

46:                                               ; preds = %44, %44
  %47 = load i32, ptr %1, align 4
  ret i32 %47

48:                                               ; preds = %44
  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 = !{!"int_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"}


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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @intl_new(i64 noundef, ptr noundef) local_unnamed_addr #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: nounwind uwtable
declare dso_local void @intl_free(ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @intl_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, 2) i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.int_list_fval, align 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %1, i8 0, i64 48, i1 false)
  %2 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr @cmc_i32_str, ptr %2, align 8, !tbaa !5
  %3 = call ptr @intl_new(i64 noundef 32, ptr noundef nonnull %1)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %17, label %.preheader

4:                                                ; preds = %15
  %5 = load ptr, ptr @stdout, align 8, !tbaa !10
  %6 = call zeroext i1 @intl_print(ptr noundef nonnull %3, ptr noundef %5, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.7)
  call void @intl_free(ptr noundef nonnull %3)
  br label %17

.preheader:                                       ; preds = %0, %15
  %.0911 = phi i32 [ %16, %15 ], [ 0, %0 ]
  %7 = call zeroext i1 @intl_push_back(ptr noundef nonnull %3, i32 noundef %.0911)
  br i1 %7, label %15, label %8

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

15:                                               ; preds = %.preheader, %8
  %16 = add nuw nsw i32 %.0911, 1
  %exitcond.not = icmp eq i32 %16, 100
  br i1 %exitcond.not, label %4, label %.preheader, !llvm.loop !11

17:                                               ; preds = %0, %4
  %.0 = phi i32 [ 0, %4 ], [ 1, %0 ]
  ret i32 %.0
}

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

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { 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 #4 = { 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 = !{!"int_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"}


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