; LLVM IR from facebook/hermes :: external/llvh/lib/Support (regerror)

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

@rerrs = external hidden global [17 x %struct.rerr], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @llvh_regerror(i32 noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca [50 x i8], align 16
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = and i32 %14, -257
  store i32 %15, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 50, ptr %13) #5
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 255
  br i1 %17, label %18, label %22

18:                                               ; preds = %4
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = getelementptr inbounds [50 x i8], ptr %13, i64 0, i64 0
  %21 = call ptr @regatoi(ptr noundef %19, ptr noundef %20, i32 noundef 50)
  store ptr %21, ptr %12, align 8, !tbaa !9
  br label %65

22:                                               ; preds = %4
  store ptr @rerrs, ptr %9, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %36, %22
  %24 = load ptr, ptr %9, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.rerr, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !13
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %39

28:                                               ; preds = %23
  %29 = load ptr, ptr %9, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.rerr, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !13
  %32 = load i32, ptr %11, align 4, !tbaa !5
  %33 = icmp eq i32 %31, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %28
  br label %39

35:                                               ; preds = %28
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %9, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.rerr, ptr %37, i32 1
  store ptr %38, ptr %9, align 8, !tbaa !9
  br label %23, !llvm.loop !15

39:                                               ; preds = %34, %23
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = and i32 %40, 256
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %60

43:                                               ; preds = %39
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.rerr, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !13
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %54

48:                                               ; preds = %43
  %49 = getelementptr inbounds [50 x i8], ptr %13, i64 0, i64 0
  %50 = load ptr, ptr %9, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.rerr, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = call i64 @llvh_strlcpy(ptr noundef %49, ptr noundef %52, i64 noundef 50)
  br label %58

54:                                               ; preds = %43
  %55 = getelementptr inbounds [50 x i8], ptr %13, i64 0, i64 0
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %55, i64 noundef 50, ptr noundef @.str, i32 noundef %56) #5
  br label %58

58:                                               ; preds = %54, %48
  %59 = getelementptr inbounds [50 x i8], ptr %13, i64 0, i64 0
  store ptr %59, ptr %12, align 8, !tbaa !9
  br label %64

60:                                               ; preds = %39
  %61 = load ptr, ptr %9, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.rerr, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !18
  store ptr %63, ptr %12, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %60, %58
  br label %65

65:                                               ; preds = %64, %18
  %66 = load ptr, ptr %12, align 8, !tbaa !9
  %67 = call i64 @strlen(ptr noundef %66) #6
  %68 = add i64 %67, 1
  store i64 %68, ptr %10, align 8, !tbaa !11
  %69 = load i64, ptr %8, align 8, !tbaa !11
  %70 = icmp ugt i64 %69, 0
  br i1 %70, label %71, label %76

71:                                               ; preds = %65
  %72 = load ptr, ptr %7, align 8, !tbaa !9
  %73 = load ptr, ptr %12, align 8, !tbaa !9
  %74 = load i64, ptr %8, align 8, !tbaa !11
  %75 = call i64 @llvh_strlcpy(ptr noundef %72, ptr noundef %73, i64 noundef %74)
  br label %76

76:                                               ; preds = %71, %65
  %77 = load i64, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 50, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret i64 %77
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @regatoi(ptr noundef, ptr noundef, i32 noundef) #0

declare i64 @llvh_strlcpy(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

; 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 = { "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 "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 #4 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"rerr", !6, i64 0, !10, i64 8, !10, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!14, !10, i64 8}
!18 = !{!14, !10, i64 16}


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

@rerrs = external hidden local_unnamed_addr global [17 x %struct.rerr], align 16
@.str = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @llvh_regerror(i32 noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [50 x i8], align 16
  %6 = and i32 %0, -257
  call void @llvm.lifetime.start.p0(i64 50, ptr nonnull %5) #5
  %7 = icmp eq i32 %0, 255
  br i1 %7, label %8, label %.preheader

8:                                                ; preds = %4
  %9 = call ptr @regatoi(ptr noundef %1, ptr noundef nonnull %5, i32 noundef 50)
  br label %25

.preheader:                                       ; preds = %4, %.preheader
  %.017 = phi ptr [ %12, %.preheader ], [ @rerrs, %4 ]
  %10 = load i32, ptr %.017, align 8, !tbaa !5
  %.not = icmp eq i32 %10, 0
  %11 = icmp eq i32 %10, %6
  %or.cond = or i1 %.not, %11
  %12 = getelementptr inbounds i8, ptr %.017, i64 24
  br i1 %or.cond, label %13, label %.preheader, !llvm.loop !11

13:                                               ; preds = %.preheader
  %14 = and i32 %0, 256
  %.not21 = icmp eq i32 %14, 0
  br i1 %.not21, label %22, label %15

15:                                               ; preds = %13
  br i1 %.not, label %20, label %16

16:                                               ; preds = %15
  %17 = getelementptr inbounds i8, ptr %.017, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = call i64 @llvh_strlcpy(ptr noundef nonnull %5, ptr noundef %18, i64 noundef 50) #5
  br label %25

20:                                               ; preds = %15
  %21 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %5, i64 noundef 50, ptr noundef nonnull @.str, i32 noundef %6) #5
  br label %25

22:                                               ; preds = %13
  %23 = getelementptr inbounds i8, ptr %.017, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  br label %25

25:                                               ; preds = %16, %20, %22, %8
  %.0 = phi ptr [ %9, %8 ], [ %24, %22 ], [ %5, %20 ], [ %5, %16 ]
  %26 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.0) #6
  %.not23 = icmp eq i64 %3, 0
  br i1 %.not23, label %29, label %27

27:                                               ; preds = %25
  %28 = call i64 @llvh_strlcpy(ptr noundef %2, ptr noundef %.0, i64 noundef %3) #5
  br label %29

29:                                               ; preds = %27, %25
  %30 = add i64 %26, 1
  call void @llvm.lifetime.end.p0(i64 50, ptr nonnull %5) #5
  ret i64 %30
}

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

; Function Attrs: nounwind uwtable
declare hidden ptr @regatoi(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare i64 @llvh_strlcpy(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress 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 = { mustprogress 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 = { nofree nounwind "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 #4 = { 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 #5 = { nounwind }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"rerr", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !10, i64 16}


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