; LLVM IR from xing1357/SimpleOS :: src (console)

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

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 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 uwtable
declare dso_local void @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @getstr(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %8, label %7

7:                                                ; preds = %1
  br label %25

8:                                                ; preds = %1
  br label %9

9:                                                ; preds = %24, %8
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %10 = call signext i8 (...) @kb_getchar()
  store i8 %10, ptr %3, align 1, !tbaa !9
  %11 = load i8, ptr %3, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 10
  br i1 %13, label %14, label %15

14:                                               ; preds = %9
  call void (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 1, ptr %4, align 4
  br label %22

15:                                               ; preds = %9
  %16 = load i8, ptr %3, align 1, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i32 1
  store ptr %18, ptr %2, align 8, !tbaa !5
  store i8 %16, ptr %17, align 1, !tbaa !9
  %19 = load i8, ptr %3, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  call void (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %20)
  br label %21

21:                                               ; preds = %15
  store i32 0, ptr %4, align 4
  br label %22

22:                                               ; preds = %21, %14
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  %23 = load i32, ptr %4, align 4
  switch i32 %23, label %26 [
    i32 0, label %24
    i32 1, label %25
  ]

24:                                               ; preds = %22
  br label %9

25:                                               ; preds = %22, %7
  ret void

26:                                               ; preds = %22
  unreachable
}

declare signext i8 @kb_getchar(...) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


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

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @printf(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @getstr(ptr noundef writeonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %9, label %.preheader

.preheader:                                       ; preds = %1
  %2 = tail call signext i8 (...) @kb_getchar() #2
  %3 = icmp eq i8 %2, 10
  br i1 %3, label %.thread, label %.lr.ph

.thread:                                          ; preds = %.lr.ph, %.preheader
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.1)
  br label %9

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %4 = phi i8 [ %7, %.lr.ph ], [ %2, %.preheader ]
  %.0510 = phi ptr [ %6, %.lr.ph ], [ %0, %.preheader ]
  %5 = sext i8 %4 to i32
  %6 = getelementptr inbounds i8, ptr %.0510, i64 1
  store i8 %4, ptr %.0510, align 1, !tbaa !5
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.2, i32 noundef %5)
  %7 = tail call signext i8 (...) @kb_getchar() #2
  %8 = icmp eq i8 %7, 10
  br i1 %8, label %.thread, label %.lr.ph

9:                                                ; preds = %.thread, %1
  ret void
}

declare signext i8 @kb_getchar(...) 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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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