; LLVM IR from tastangh/TI-RSLK-Texas-Instruments-Robotics-System-The-Maze-Edition :: tirslk_maze_1_00_00/Switch (Switchmain)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @Switch_Init()
  call void @LaunchPad_Init()
  br label %3

3:                                                ; preds = %13, %0
  br label %4

4:                                                ; preds = %3
  %5 = call zeroext i8 @LaunchPad_Input()
  %6 = zext i8 %5 to i32
  store i32 %6, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %7, label %12 [
    i32 0, label %8
    i32 1, label %9
    i32 2, label %10
    i32 3, label %11
  ]

8:                                                ; preds = %4
  call void @LaunchPad_Output(i8 noundef zeroext 0)
  br label %13

9:                                                ; preds = %4
  call void @LaunchPad_Output(i8 noundef zeroext 1)
  br label %13

10:                                               ; preds = %4
  call void @LaunchPad_Output(i8 noundef zeroext 4)
  br label %13

11:                                               ; preds = %4
  call void @LaunchPad_Output(i8 noundef zeroext 2)
  br label %13

12:                                               ; preds = %4
  call void @LaunchPad_Output(i8 noundef zeroext 7)
  br label %13

13:                                               ; preds = %12, %11, %10, %9, %8
  %14 = call i32 @Switch_Input()
  store i32 %14, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = lshr i32 %15, 5
  %17 = trunc i32 %16 to i8
  call void @LaunchPad_LED(i8 noundef zeroext %17)
  br label %3
}

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

declare void @Switch_Init() #2

declare void @LaunchPad_Init() #2

declare zeroext i8 @LaunchPad_Input() #2

declare void @LaunchPad_Output(i8 noundef zeroext) #2

declare i32 @Switch_Input() #2

declare void @LaunchPad_LED(i8 noundef zeroext) #2

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 = { "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 }

!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"}


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

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @Switch_Init() #2
  tail call void @LaunchPad_Init() #2
  br label %1

1:                                                ; preds = %1, %0
  %2 = tail call zeroext i8 @LaunchPad_Input() #2
  %3 = icmp ult i8 %2, 4
  %switch.cast = zext i8 %2 to i32
  %switch.shiftamt = shl nuw nsw i32 %switch.cast, 3
  %switch.downshift = lshr i32 33816832, %switch.shiftamt
  %switch.masked = trunc i32 %switch.downshift to i8
  %.sink = select i1 %3, i8 %switch.masked, i8 7
  tail call void @LaunchPad_Output(i8 noundef zeroext %.sink) #2
  %4 = tail call i32 @Switch_Input() #2
  %5 = lshr i32 %4, 5
  %6 = trunc i32 %5 to i8
  tail call void @LaunchPad_LED(i8 noundef zeroext %6) #2
  br label %1
}

declare void @Switch_Init() local_unnamed_addr #1

declare void @LaunchPad_Init() local_unnamed_addr #1

declare zeroext i8 @LaunchPad_Input() local_unnamed_addr #1

declare void @LaunchPad_Output(i8 noundef zeroext) local_unnamed_addr #1

declare i32 @Switch_Input() local_unnamed_addr #1

declare void @LaunchPad_LED(i8 noundef zeroext) local_unnamed_addr #1

attributes #0 = { noreturn 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 = { "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)"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass