; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (344)

; 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 void @reverseString(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  br label %60

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %10 = load ptr, ptr %3, 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 = getelementptr inbounds i8, ptr %13, i64 -1
  store ptr %14, ptr %5, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %53, %9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = icmp ne ptr %16, %17
  br i1 %18, label %19, label %52

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !11
  %25 = sext i8 %24 to i32
  %26 = icmp ne i32 %22, %25
  br i1 %26, label %27, label %52

27:                                               ; preds = %19
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = sext i8 %29 to i32
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = xor i32 %33, %30
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %31, align 1, !tbaa !11
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = sext i8 %40 to i32
  %42 = xor i32 %41, %38
  %43 = trunc i32 %42 to i8
  store i8 %43, ptr %39, align 1, !tbaa !11
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = xor i32 %49, %46
  %51 = trunc i32 %50 to i8
  store i8 %51, ptr %47, align 1, !tbaa !11
  br label %52

52:                                               ; preds = %27, %19, %15
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %3, align 8, !tbaa !5
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i32 -1
  store ptr %57, ptr %5, align 8, !tbaa !5
  %58 = icmp ult ptr %55, %57
  br i1 %58, label %15, label %59, !llvm.loop !12

59:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %60

60:                                               ; preds = %59, %8
  ret void
}

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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @reverseString(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %1, 0
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %2
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 %5
  %7 = getelementptr inbounds i8, ptr %6, i64 -1
  br label %8

8:                                                ; preds = %18, %4
  %.014 = phi ptr [ %0, %4 ], [ %19, %18 ]
  %.0 = phi ptr [ %7, %4 ], [ %20, %18 ]
  %.not = icmp eq ptr %.0, %.014
  br i1 %.not, label %18, label %9

9:                                                ; preds = %8
  %10 = load i8, ptr %.0, align 1, !tbaa !5
  %11 = load i8, ptr %.014, align 1, !tbaa !5
  %.not20 = icmp eq i8 %10, %11
  br i1 %.not20, label %18, label %12

12:                                               ; preds = %9
  %13 = xor i8 %11, %10
  store i8 %13, ptr %.0, align 1, !tbaa !5
  %14 = load i8, ptr %.014, align 1, !tbaa !5
  %15 = xor i8 %14, %13
  store i8 %15, ptr %.014, align 1, !tbaa !5
  %16 = load i8, ptr %.0, align 1, !tbaa !5
  %17 = xor i8 %16, %15
  store i8 %17, ptr %.0, align 1, !tbaa !5
  br label %18

18:                                               ; preds = %8, %9, %12
  %19 = getelementptr inbounds i8, ptr %.014, i64 1
  %20 = getelementptr inbounds i8, ptr %.0, i64 -1
  %21 = icmp ult ptr %19, %20
  br i1 %21, label %8, label %.loopexit, !llvm.loop !8

.loopexit:                                        ; preds = %18, %2
  ret void
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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