; LLVM IR from AdaptiveCpp/AdaptiveCpp :: src/libkernel/sscp/amdgpu/print.ll_ (acpp_sscp_print)

; 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: alwaysinline mustprogress uwtable
define dso_local void @__acpp_sscp_print(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 65536, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %23, %1
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 65536
  br i1 %8, label %9, label %24

9:                                                ; preds = %6
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %10, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = sext i8 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %9
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %4, align 4, !tbaa !9
  br label %24

20:                                               ; preds = %9
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %4, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %20
  br label %6, !llvm.loop !12

24:                                               ; preds = %17, %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %25 = call i64 @__ockl_fprintf_stdout_begin()
  store i64 %25, ptr %5, align 8, !tbaa !14
  %26 = load i64, ptr %5, align 8, !tbaa !14
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = call i64 @__ockl_fprintf_append_string_n(i64 noundef %26, ptr noundef %27, i64 noundef %29, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

declare i64 @__ockl_fprintf_stdout_begin() #2

declare i64 @__ockl_fprintf_append_string_n(i64 noundef, ptr noundef, i64 noundef, i32 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 = { alwaysinline mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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, !15, i64 0}
!15 = !{!"long long", !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"

; Function Attrs: alwaysinline mustprogress uwtable
define dso_local void @__acpp_sscp_print(ptr noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %21, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.3, %21 ]
  %3 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = icmp eq i8 %4, 0
  br i1 %5, label %6, label %9

6:                                                ; preds = %17, %13, %9, %2
  %indvars.iv.lcssa = phi i64 [ %indvars.iv, %2 ], [ %indvars.iv.next, %9 ], [ %indvars.iv.next.1, %13 ], [ %indvars.iv.next.2, %17 ]
  %7 = shl i64 %indvars.iv.lcssa, 32
  %sext = add i64 %7, 4294967296
  %8 = ashr exact i64 %sext, 32
  br label %.loopexit

9:                                                ; preds = %2
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %10 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = icmp eq i8 %11, 0
  br i1 %12, label %6, label %13

13:                                               ; preds = %9
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %14 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.1
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = icmp eq i8 %15, 0
  br i1 %16, label %6, label %17

17:                                               ; preds = %13
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %18 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.2
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = icmp eq i8 %19, 0
  br i1 %20, label %6, label %21

21:                                               ; preds = %17
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 65536
  br i1 %exitcond.not.3, label %.loopexit, label %2, !llvm.loop !8

.loopexit:                                        ; preds = %21, %6
  %.1 = phi i64 [ %8, %6 ], [ 65536, %21 ]
  %22 = tail call i64 @__ockl_fprintf_stdout_begin()
  %23 = tail call i64 @__ockl_fprintf_append_string_n(i64 noundef %22, ptr noundef nonnull %0, i64 noundef %.1, i32 noundef 1)
  ret void
}

declare i64 @__ockl_fprintf_stdout_begin() local_unnamed_addr #1

declare i64 @__ockl_fprintf_append_string_n(i64 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { alwaysinline mustprogress 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" }

!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++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass