; LLVM IR from sysprog21/shecc :: src (ssa)

; 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.func_list_t = type { ptr, ptr }
%struct.func = type { %struct.var, [8 x %struct.var], i32, i32, i32, ptr, ptr, %struct.symbol_list_t, i32, i32, ptr }
%struct.var = type { [32 x i8], [32 x i8], i32, i8, i8, i32, i32, i32, i32, i32, ptr, i32, [64 x ptr], i32, %struct.rename_t, %struct.ref_block_list, ptr, ptr, ptr, i32, i8, i8, i8 }
%struct.rename_t = type { i32, [64 x i32], i32 }
%struct.ref_block_list = type { ptr, ptr }
%struct.symbol_list_t = type { ptr, ptr }

@FUNC_LIST = external dso_local global %struct.func_list_t, align 8
@.str.88 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.118 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.119 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.120 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.121 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.122 = external hidden unnamed_addr constant [12 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @bb_dump(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @dump_cfg(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call noalias ptr @fopen(ptr noundef %5, ptr noundef @.str.119)
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef @.str.120) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef @.str.121) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %11 = load ptr, ptr @FUNC_LIST, align 8, !tbaa !9
  store ptr %11, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %34, %1
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %38

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.func, ptr %17, i32 0, i32 9
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !11
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.88, ptr noundef %22) #4
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.122, ptr noundef %25) #4
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.func, ptr %29, i32 0, i32 5
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  call void @bb_dump(ptr noundef %27, ptr noundef %28, ptr noundef %31)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.118) #4
  br label %34

34:                                               ; preds = %16
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.func, ptr %35, i32 0, i32 10
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  store ptr %37, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !20

38:                                               ; preds = %15
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str.118) #4
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = call i32 @fclose(ptr noundef %41)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

declare i32 @fclose(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = { 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, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 8}
!11 = !{!12, !14, i64 8548}
!12 = !{!"func", !13, i64 0, !7, i64 944, !14, i64 8496, !14, i64 8500, !14, i64 8504, !6, i64 8512, !6, i64 8520, !10, i64 8528, !14, i64 8544, !14, i64 8548, !6, i64 8552}
!13 = !{!"var", !7, i64 0, !7, i64 32, !14, i64 64, !15, i64 68, !15, i64 69, !14, i64 72, !14, i64 76, !14, i64 80, !14, i64 84, !14, i64 88, !6, i64 96, !14, i64 104, !7, i64 112, !14, i64 624, !16, i64 628, !17, i64 896, !6, i64 912, !6, i64 920, !6, i64 928, !14, i64 936, !15, i64 940, !15, i64 941, !15, i64 942}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"", !14, i64 0, !7, i64 4, !14, i64 260}
!17 = !{!"ref_block_list", !6, i64 0, !6, i64 8}
!18 = !{!12, !6, i64 8512}
!19 = !{!12, !6, i64 8552}
!20 = distinct !{!20, !21}
!21 = !{!"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.func_list_t = type { ptr, ptr }

@FUNC_LIST = external dso_local local_unnamed_addr global %struct.func_list_t, align 8
@.str.88 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.118 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.119 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.120 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.121 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.122 = external hidden unnamed_addr constant [12 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local void @bb_dump(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @dump_cfg(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str.119)
  %3 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.120) #2
  %4 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.121) #2
  %.016 = load ptr, ptr @FUNC_LIST, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.016, null
  br i1 %.not17, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.118) #2
  %6 = tail call i32 @fclose(ptr noundef %2)
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.018 = phi ptr [ %.0, %.lr.ph ], [ %.016, %1 ]
  %7 = getelementptr inbounds i8, ptr %.018, i64 8548
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %7, align 4, !tbaa !9
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.88, ptr noundef nonnull %.018) #2
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.122, ptr noundef nonnull %.018) #2
  %12 = getelementptr inbounds i8, ptr %.018, i64 8512
  %13 = load ptr, ptr %12, align 8, !tbaa !17
  tail call void @bb_dump(ptr noundef %2, ptr noundef nonnull %.018, ptr noundef %13)
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.118) #2
  %15 = getelementptr inbounds i8, ptr %.018, i64 8552
  %.0 = load ptr, ptr %15, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #0

attributes #0 = { 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 #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" }
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, !12, i64 8548}
!10 = !{!"func", !11, i64 0, !7, i64 944, !12, i64 8496, !12, i64 8500, !12, i64 8504, !6, i64 8512, !6, i64 8520, !16, i64 8528, !12, i64 8544, !12, i64 8548, !6, i64 8552}
!11 = !{!"var", !7, i64 0, !7, i64 32, !12, i64 64, !13, i64 68, !13, i64 69, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !12, i64 88, !6, i64 96, !12, i64 104, !7, i64 112, !12, i64 624, !14, i64 628, !15, i64 896, !6, i64 912, !6, i64 920, !6, i64 928, !12, i64 936, !13, i64 940, !13, i64 941, !13, i64 942}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"", !12, i64 0, !7, i64 4, !12, i64 260}
!15 = !{!"ref_block_list", !6, i64 0, !6, i64 8}
!16 = !{!"", !6, i64 0, !6, i64 8}
!17 = !{!10, !6, i64 8512}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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