; LLVM IR from nickmqb/muon :: bootstrap/mu.ll_Environment (getCommandLineArgs__)

; 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.tag_____IAllocator__ = type { ptr, ptr, ptr, ptr }
%struct.tag_____Array__cstring____ = type { ptr, i32 }
%struct.tag_____Array__string____ = type { ptr, i32 }
%struct.string__ = type { ptr, i32 }

@top_____currentAllocator__ = external dso_local thread_local global %struct.tag_____IAllocator__, align 8
@top_____abandonFn__ = external dso_local thread_local global ptr, align 8
@mu_____argc = external hidden global i32, align 4
@mu_____argv = external hidden global ptr, align 8

; 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 speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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) #2

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

; Function Attrs: nounwind uwtable
declare dso_local { ptr, i32 } @string__from_cstring__(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local { ptr, i32 } @Array__cons__string____(i32 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @Environment__getCommandLineArgs__() #4 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca %struct.tag_____Array__cstring____, align 8
  %4 = alloca %struct.tag_____Array__cstring____, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.tag_____Array__string____, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca %struct.string__, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store ptr null, ptr %2, align 8, !tbaa !9
  %14 = load i32, ptr @mu_____argc, align 4, !tbaa !5
  store i32 %14, ptr %1, align 4, !tbaa !5
  %15 = load ptr, ptr @mu_____argv, align 8, !tbaa !9
  store ptr %15, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #5
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 16, i1 false)
  %16 = load ptr, ptr %2, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.tag_____Array__cstring____, ptr %3, i32 0, i32 0
  store ptr %16, ptr %17, align 8, !tbaa !11
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = getelementptr inbounds %struct.tag_____Array__cstring____, ptr %3, i32 0, i32 1
  store i32 %18, ptr %19, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %3, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %20 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____currentAllocator__)
  %21 = getelementptr inbounds %struct.tag_____IAllocator__, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____currentAllocator__)
  %24 = getelementptr inbounds %struct.tag_____IAllocator__, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = call ptr %22(ptr noundef %25, i64 noundef 16)
  store ptr %26, ptr %5, align 8, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = call { ptr, i32 } @Array__cons__string____(i32 noundef %28)
  %30 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 0
  %31 = extractvalue { ptr, i32 } %29, 0
  store ptr %31, ptr %30, align 8
  %32 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 1
  %33 = extractvalue { ptr, i32 } %29, 1
  store i32 %33, ptr %32, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %27, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %34, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr %4, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %59, %0
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.tag_____Array__cstring____, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 8, !tbaa !13
  %40 = icmp slt i32 %36, %39
  br i1 %40, label %41, label %74

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.tag_____Array__cstring____, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds ptr, ptr %44, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  store ptr %48, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %49, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %50 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %50, ptr %12, align 4, !tbaa !5
  %51 = load i32, ptr %12, align 4, !tbaa !5
  %52 = load ptr, ptr %11, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.tag_____Array__string____, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !18
  %55 = icmp ult i32 %51, %54
  br i1 %55, label %59, label %56

56:                                               ; preds = %41
  %57 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  call void %58(i32 noundef -3)
  br label %59

59:                                               ; preds = %56, %41
  %60 = load ptr, ptr %11, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.tag_____Array__string____, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !20
  %63 = load i32, ptr %12, align 4, !tbaa !5
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds %struct.string__, ptr %62, i64 %64
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #5
  %66 = load ptr, ptr %10, align 8, !tbaa !9
  %67 = call { ptr, i32 } @string__from_cstring__(ptr noundef %66)
  %68 = getelementptr inbounds { ptr, i32 }, ptr %13, i32 0, i32 0
  %69 = extractvalue { ptr, i32 } %67, 0
  store ptr %69, ptr %68, align 8
  %70 = getelementptr inbounds { ptr, i32 }, ptr %13, i32 0, i32 1
  %71 = extractvalue { ptr, i32 } %67, 1
  store i32 %71, ptr %70, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %65, ptr align 8 %13, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #5
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %35, !llvm.loop !21

74:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %75 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret ptr %75
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"tag_____Array__cstring____", !10, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{i64 0, i64 8, !9, i64 8, i64 4, !5}
!15 = !{!16, !10, i64 8}
!16 = !{!"tag_____IAllocator__", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!17 = !{!16, !10, i64 0}
!18 = !{!19, !6, i64 8}
!19 = !{!"tag_____Array__string____", !10, i64 0, !6, i64 8}
!20 = !{!19, !10, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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.tag_____IAllocator__ = type { ptr, ptr, ptr, ptr }
%struct.string__ = type { ptr, i32 }

@top_____currentAllocator__ = external dso_local thread_local local_unnamed_addr global %struct.tag_____IAllocator__, align 8
@top_____abandonFn__ = external dso_local thread_local local_unnamed_addr global ptr, align 8
@mu_____argc = external hidden local_unnamed_addr global i32, align 4
@mu_____argv = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: nounwind uwtable
declare dso_local { ptr, i32 } @string__from_cstring__(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local { ptr, i32 } @Array__cons__string____(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @Environment__getCommandLineArgs__() local_unnamed_addr #1 {
  %1 = load i32, ptr @mu_____argc, align 4, !tbaa !5
  %2 = load ptr, ptr @mu_____argv, align 8, !tbaa !9
  %3 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____currentAllocator__)
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = load ptr, ptr %3, align 8, !tbaa !13
  %7 = tail call ptr %5(ptr noundef %6, i64 noundef 16) #2
  %8 = tail call { ptr, i32 } @Array__cons__string____(i32 noundef %1)
  %9 = extractvalue { ptr, i32 } %8, 0
  %10 = extractvalue { ptr, i32 } %8, 1
  store ptr %9, ptr %7, align 8, !tbaa !9
  %.sroa.413.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 8
  store i32 %10, ptr %.sroa.413.0..sroa_idx, align 8, !tbaa !5
  %11 = icmp sgt i32 %1, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %12 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %13

13:                                               ; preds = %.lr.ph, %21
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %21 ]
  %14 = getelementptr inbounds ptr, ptr %2, i64 %indvars.iv
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = load i32, ptr %.sroa.413.0..sroa_idx, align 8, !tbaa !14
  %17 = zext i32 %16 to i64
  %18 = icmp ult i64 %indvars.iv, %17
  br i1 %18, label %21, label %19

19:                                               ; preds = %13
  %20 = load ptr, ptr %12, align 8, !tbaa !9
  tail call void %20(i32 noundef -3) #2
  br label %21

21:                                               ; preds = %19, %13
  %22 = load ptr, ptr %7, align 8, !tbaa !16
  %23 = getelementptr inbounds %struct.string__, ptr %22, i64 %indvars.iv
  %24 = tail call { ptr, i32 } @string__from_cstring__(ptr noundef %15)
  %25 = extractvalue { ptr, i32 } %24, 0
  %26 = extractvalue { ptr, i32 } %24, 1
  store ptr %25, ptr %23, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 8
  store i32 %26, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %13, !llvm.loop !17

._crit_edge:                                      ; preds = %21, %0
  ret ptr %7
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"tag_____IAllocator__", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"tag_____Array__string____", !10, i64 0, !6, i64 8}
!16 = !{!15, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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