; LLVM IR from asllop/AppOS :: boot/arch/pc32 (cmdline_args)

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

@grub_struct = external global ptr, align 8
@string_pointers = external hidden global [256 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local ptr @setup_cmdline(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %10 = load ptr, ptr @grub_struct, align 8, !tbaa !5
  %11 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %11, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = and i32 %12, 4
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %81

15:                                               ; preds = %1
  store ptr @string_pointers, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %16 = load ptr, ptr @grub_struct, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  store ptr %17, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %19, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [256 x ptr], ptr @string_pointers, i64 0, i64 %25
  store ptr %23, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %74, %15
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %28, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %36, label %35

35:                                               ; preds = %27
  store i32 2, ptr %9, align 4
  br label %77

36:                                               ; preds = %27
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = sext i8 %41 to i32
  %43 = icmp eq i32 %42, 32
  br i1 %43, label %44, label %69

44:                                               ; preds = %36
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  store i8 0, ptr %48, align 1, !tbaa !11
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %49, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = sext i8 %54 to i32
  %56 = icmp ne i32 %55, 32
  br i1 %56, label %57, label %68

57:                                               ; preds = %44
  %58 = load i32, ptr %3, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %3, align 4, !tbaa !9
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i8, ptr %60, i64 %63
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [256 x ptr], ptr @string_pointers, i64 0, i64 %66
  store ptr %64, ptr %67, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %57, %44
  br label %69

69:                                               ; preds = %68, %36
  %70 = load i32, ptr %3, align 4, !tbaa !9
  %71 = icmp sge i32 %70, 256
  br i1 %71, label %72, label %73

72:                                               ; preds = %69
  store i32 2, ptr %9, align 4
  br label %77

73:                                               ; preds = %69
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %8, align 4, !tbaa !9
  br label %27, !llvm.loop !12

77:                                               ; preds = %72, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %3, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %81

81:                                               ; preds = %78, %1
  %82 = load i32, ptr %3, align 4, !tbaa !9
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  store i32 %82, ptr %83, align 4, !tbaa !9
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret ptr %84
}

; 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

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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@grub_struct = external local_unnamed_addr global ptr, align 8
@string_pointers = external hidden global [256 x ptr], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @setup_cmdline(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @grub_struct, align 8, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !9
  %4 = and i32 %3, 4
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %21, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %2, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %7, ptr @string_pointers, align 16, !tbaa !5
  br label %8

8:                                                ; preds = %.thread, %5
  %indvars.iv = phi i64 [ %indvars.iv.next, %.thread ], [ 0, %5 ]
  %.022 = phi i32 [ %.128, %.thread ], [ 0, %5 ]
  %9 = getelementptr inbounds i8, ptr %7, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !11
  switch i8 %10, label %.thread [
    i8 0, label %19
    i8 32, label %11
  ]

11:                                               ; preds = %8
  store i8 0, ptr %9, align 1, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %9, i64 1
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %.not26 = icmp eq i8 %13, 32
  br i1 %.not26, label %.thread, label %14

14:                                               ; preds = %11
  %15 = add nsw i32 %.022, 1
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [256 x ptr], ptr @string_pointers, i64 0, i64 %16
  store ptr %12, ptr %17, align 8, !tbaa !5
  %18 = icmp sgt i32 %.022, 254
  br i1 %18, label %19, label %.thread

.thread:                                          ; preds = %8, %11, %14
  %.128 = phi i32 [ %15, %14 ], [ %.022, %11 ], [ %.022, %8 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %8, !llvm.loop !12

19:                                               ; preds = %14, %8
  %.2 = phi i32 [ %.022, %8 ], [ 256, %14 ]
  %20 = add nsw i32 %.2, 1
  br label %21

21:                                               ; preds = %19, %1
  %.023 = phi ptr [ @string_pointers, %19 ], [ null, %1 ]
  %.3 = phi i32 [ %20, %19 ], [ 0, %1 ]
  store i32 %.3, ptr %0, align 4, !tbaa !9
  ret ptr %.023
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass