; LLVM IR from lfarcaro/ARINC653_ARMV7A_AM335X :: Hardware (cmdline)

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

@CmdLineProcess.argv = external hidden global [9 x ptr], align 16
@g_sCmdTable = external global [0 x %struct.tCmdLineEntry], align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @CmdLineProcess(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %9, ptr %4, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %37, %1
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %14, label %40

14:                                               ; preds = %10
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = sext i8 %16 to i32
  %18 = icmp eq i32 %17, 32
  br i1 %18, label %19, label %21

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 0, ptr %20, align 1, !tbaa !11
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %37

21:                                               ; preds = %14
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %36

24:                                               ; preds = %21
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 8
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [9 x ptr], ptr @CmdLineProcess.argv, i64 0, i64 %30
  store ptr %28, ptr %31, align 8, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %35

34:                                               ; preds = %24
  store i32 -2, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %67

35:                                               ; preds = %27
  br label %36

36:                                               ; preds = %35, %21
  br label %37

37:                                               ; preds = %36, %19
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %4, align 8, !tbaa !5
  br label %10, !llvm.loop !12

40:                                               ; preds = %10
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %66

43:                                               ; preds = %40
  store ptr @g_sCmdTable, ptr %7, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %62, %43
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.tCmdLineEntry, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %65

49:                                               ; preds = %44
  %50 = load ptr, ptr @CmdLineProcess.argv, align 16, !tbaa !5
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.tCmdLineEntry, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = call i32 @strcmp(ptr noundef %50, ptr noundef %53) #4
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %62, label %56

56:                                               ; preds = %49
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.tCmdLineEntry, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = call i32 %59(i32 noundef %60, ptr noundef @CmdLineProcess.argv)
  store i32 %61, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %67

62:                                               ; preds = %49
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.tCmdLineEntry, ptr %63, i32 1
  store ptr %64, ptr %7, align 8, !tbaa !5
  br label %44, !llvm.loop !17

65:                                               ; preds = %44
  br label %66

66:                                               ; preds = %65, %40
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %67

67:                                               ; preds = %66, %56, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %68 = load i32, ptr %2, align 4
  ret i32 %68
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

; 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 willreturn memory(read) "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 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

!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"}
!14 = !{!15, !6, i64 0}
!15 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!15, !6, i64 8}
!17 = distinct !{!17, !13}


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

@CmdLineProcess.argv = external hidden global [9 x ptr], align 16
@g_sCmdTable = external local_unnamed_addr global [0 x %struct.tCmdLineEntry], align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @CmdLineProcess(ptr noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %12, %1
  %.019 = phi ptr [ %0, %1 ], [ %13, %12 ]
  %.017 = phi i32 [ 0, %1 ], [ %.118, %12 ]
  %.016 = phi i32 [ 1, %1 ], [ %.1, %12 ]
  %3 = load i8, ptr %.019, align 1, !tbaa !5
  switch i8 %3, label %5 [
    i8 0, label %14
    i8 32, label %4
  ]

4:                                                ; preds = %2
  store i8 0, ptr %.019, align 1, !tbaa !5
  br label %12

5:                                                ; preds = %2
  %.not26 = icmp eq i32 %.016, 0
  br i1 %.not26, label %12, label %6

6:                                                ; preds = %5
  %7 = icmp slt i32 %.017, 8
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %6
  %9 = sext i32 %.017 to i64
  %10 = getelementptr inbounds [9 x ptr], ptr @CmdLineProcess.argv, i64 0, i64 %9
  store ptr %.019, ptr %10, align 8, !tbaa !8
  %11 = add nsw i32 %.017, 1
  br label %12

12:                                               ; preds = %5, %8, %4
  %.118 = phi i32 [ %.017, %4 ], [ %11, %8 ], [ %.017, %5 ]
  %.1 = phi i32 [ 1, %4 ], [ 0, %8 ], [ 0, %5 ]
  %13 = getelementptr inbounds i8, ptr %.019, i64 1
  br label %2, !llvm.loop !10

14:                                               ; preds = %2
  %.not23 = icmp eq i32 %.017, 0
  br i1 %.not23, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %14
  %15 = load ptr, ptr @g_sCmdTable, align 8, !tbaa !12
  %.not2430 = icmp eq ptr %15, null
  br i1 %.not2430, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %16 = load ptr, ptr @CmdLineProcess.argv, align 16, !tbaa !8
  br label %17

17:                                               ; preds = %.lr.ph, %24
  %18 = phi ptr [ %15, %.lr.ph ], [ %26, %24 ]
  %.031 = phi ptr [ @g_sCmdTable, %.lr.ph ], [ %25, %24 ]
  %19 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %16, ptr noundef nonnull dereferenceable(1) %18) #2
  %.not25 = icmp eq i32 %19, 0
  br i1 %.not25, label %20, label %24

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %.031, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = tail call i32 %22(i32 noundef %.017, ptr noundef nonnull @CmdLineProcess.argv) #3
  br label %.loopexit

24:                                               ; preds = %17
  %25 = getelementptr inbounds i8, ptr %.031, i64 24
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %.not24 = icmp eq ptr %26, null
  br i1 %.not24, label %.loopexit, label %17, !llvm.loop !15

.loopexit:                                        ; preds = %6, %24, %.preheader, %14, %20
  %.020 = phi i32 [ %23, %20 ], [ -1, %14 ], [ -1, %.preheader ], [ -1, %24 ], [ -2, %6 ]
  ret i32 %.020
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }
attributes #3 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !9, i64 0}
!13 = !{!"", !9, i64 0, !9, i64 8, !9, i64 16}
!14 = !{!13, !9, i64 8}
!15 = distinct !{!15, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass