; LLVM IR from Softmotions/iowow :: src/utils (iwconv)

; 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.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [70 x i8], align 1
@__PRETTY_FUNCTION__.iwatoi = external hidden unnamed_addr constant [29 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
define dso_local i64 @iwatoi(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %11

10:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.5, i32 noundef 222, ptr noundef @__PRETTY_FUNCTION__.iwatoi) #4
  unreachable

11:                                               ; preds = %9
  br label %12

12:                                               ; preds = %24, %11
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = sext i8 %14 to i32
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %22

17:                                               ; preds = %12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = icmp sle i32 %20, 32
  br label %22

22:                                               ; preds = %17, %12
  %23 = phi i1 [ false, %12 ], [ %21, %17 ]
  br i1 %23, label %24, label %27

24:                                               ; preds = %22
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i32 1
  store ptr %26, ptr %3, align 8, !tbaa !5
  br label %12, !llvm.loop !10

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !14
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = sext i8 %29 to i32
  %31 = icmp eq i32 %30, 45
  br i1 %31, label %32, label %35

32:                                               ; preds = %27
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i32 1
  store ptr %34, ptr %3, align 8, !tbaa !5
  store i32 -1, ptr %4, align 4, !tbaa !12
  br label %44

35:                                               ; preds = %27
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = icmp eq i32 %38, 43
  br i1 %39, label %40, label %43

40:                                               ; preds = %35
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i32 1
  store ptr %42, ptr %3, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %40, %35
  br label %44

44:                                               ; preds = %43, %32
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = call i32 @strcmp(ptr noundef %45, ptr noundef @.str.2) #6
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %52, label %48

48:                                               ; preds = %44
  %49 = load i32, ptr %4, align 4, !tbaa !12
  %50 = sext i32 %49 to i64
  %51 = mul nsw i64 9223372036854775807, %50
  store i64 %51, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %84

52:                                               ; preds = %44
  br label %53

53:                                               ; preds = %69, %52
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load i8, ptr %54, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %79

58:                                               ; preds = %53
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = load i8, ptr %59, align 1, !tbaa !9
  %61 = sext i8 %60 to i32
  %62 = icmp slt i32 %61, 48
  br i1 %62, label %68, label %63

63:                                               ; preds = %58
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = load i8, ptr %64, align 1, !tbaa !9
  %66 = sext i8 %65 to i32
  %67 = icmp sgt i32 %66, 57
  br i1 %67, label %68, label %69

68:                                               ; preds = %63, %58
  br label %79

69:                                               ; preds = %63
  %70 = load i64, ptr %5, align 8, !tbaa !14
  %71 = mul nsw i64 %70, 10
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = load i8, ptr %72, align 1, !tbaa !9
  %74 = sext i8 %73 to i64
  %75 = add nsw i64 %71, %74
  %76 = sub nsw i64 %75, 48
  store i64 %76, ptr %5, align 8, !tbaa !14
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i32 1
  store ptr %78, ptr %3, align 8, !tbaa !5
  br label %53, !llvm.loop !16

79:                                               ; preds = %68, %53
  %80 = load i64, ptr %5, align 8, !tbaa !14
  %81 = load i32, ptr %4, align 4, !tbaa !12
  %82 = sext i32 %81 to i64
  %83 = mul nsw i64 %80, %82
  store i64 %83, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %84

84:                                               ; preds = %79, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %85 = load i64, ptr %2, align 8
  ret i64 %85
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

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


; 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.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [70 x i8], align 1
@__PRETTY_FUNCTION__.iwatoi = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @iwatoi(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %.preheader29

2:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5, i32 noundef 222, ptr noundef nonnull @__PRETTY_FUNCTION__.iwatoi) #3
  unreachable

.preheader29:                                     ; preds = %1, %.preheader29
  %.019 = phi ptr [ %5, %.preheader29 ], [ %0, %1 ]
  %3 = load i8, ptr %.019, align 1, !tbaa !5
  %4 = add i8 %3, -1
  %or.cond = icmp ult i8 %4, 32
  %5 = getelementptr inbounds i8, ptr %.019, i64 1
  br i1 %or.cond, label %.preheader29, label %.critedge, !llvm.loop !8

.critedge:                                        ; preds = %.preheader29
  switch i8 %3, label %8 [
    i8 45, label %6
    i8 43, label %7
  ]

6:                                                ; preds = %.critedge
  br label %8

7:                                                ; preds = %.critedge
  br label %8

8:                                                ; preds = %.critedge, %7, %6
  %.1 = phi ptr [ %5, %6 ], [ %5, %7 ], [ %.019, %.critedge ]
  %.018 = phi i64 [ -1, %6 ], [ 1, %7 ], [ 1, %.critedge ]
  %9 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %.1, ptr noundef nonnull dereferenceable(1) @.str.2) #4
  %.not25 = icmp eq i32 %9, 0
  br i1 %.not25, label %12, label %.preheader

.preheader:                                       ; preds = %8
  %10 = load i8, ptr %.1, align 1, !tbaa !5
  %11 = add i8 %10, -58
  %or.cond2830 = icmp ult i8 %11, -10
  br i1 %or.cond2830, label %._crit_edge, label %.lr.ph

12:                                               ; preds = %8
  %13 = mul nsw i64 %.018, 9223372036854775807
  br label %23

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %14 = phi i8 [ %20, %.lr.ph ], [ %10, %.preheader ]
  %.032 = phi i64 [ %18, %.lr.ph ], [ 0, %.preheader ]
  %.231 = phi ptr [ %19, %.lr.ph ], [ %.1, %.preheader ]
  %15 = mul nsw i64 %.032, 10
  %16 = zext nneg i8 %14 to i64
  %17 = add i64 %15, -48
  %18 = add i64 %17, %16
  %19 = getelementptr inbounds i8, ptr %.231, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = add i8 %20, -58
  %or.cond28 = icmp ult i8 %21, -10
  br i1 %or.cond28, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ %18, %.lr.ph ]
  %22 = mul nsw i64 %.0.lcssa, %.018
  br label %23

23:                                               ; preds = %._crit_edge, %12
  %.020 = phi i64 [ %22, %._crit_edge ], [ %13, %12 ]
  ret i64 %.020
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #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 = { noreturn 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 #2 = { 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 #3 = { noreturn nounwind }
attributes #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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