; LLVM IR from aap/pdp6 :: fe6 (fe)

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

@base = external dso_local global i32, align 4
@buf = external dso_local global [201 x i8], align 16
@nbuf = external dso_local global i32, align 4
@bufstart = external dso_local global ptr, align 8

; 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 @parsenum() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr @bufstart, align 8, !tbaa !9
  store ptr %5, ptr %3, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %36, %0
  %7 = load ptr, ptr %3, align 8, !tbaa !9
  %8 = load i32, ptr @nbuf, align 4, !tbaa !11
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [201 x i8], ptr @buf, i64 0, i64 %9
  %11 = icmp ult ptr %7, %10
  br i1 %11, label %12, label %39

12:                                               ; preds = %6
  %13 = load ptr, ptr %3, align 8, !tbaa !9
  %14 = load i8, ptr %13, align 1, !tbaa !13
  %15 = sext i8 %14 to i32
  %16 = icmp sge i32 %15, 48
  br i1 %16, label %17, label %32

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

22:                                               ; preds = %17
  %23 = load i64, ptr %2, align 8, !tbaa !5
  %24 = load i32, ptr @base, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = mul i64 %23, %25
  %27 = load ptr, ptr %3, align 8, !tbaa !9
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = sext i8 %28 to i64
  %30 = add i64 %26, %29
  %31 = sub i64 %30, 48
  store i64 %31, ptr %2, align 8, !tbaa !5
  br label %33

32:                                               ; preds = %17, %12
  store i64 -1, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %41

33:                                               ; preds = %22
  %34 = load i64, ptr %2, align 8, !tbaa !5
  %35 = and i64 %34, 68719476735
  store i64 %35, ptr %2, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr %3, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %3, align 8, !tbaa !9
  br label %6, !llvm.loop !14

39:                                               ; preds = %6
  %40 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %40, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %41

41:                                               ; preds = %39, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  %42 = load i64, ptr %1, align 8
  ret i64 %42
}

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 = { 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 = !{!"long", !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 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@base = external dso_local local_unnamed_addr global i32, align 4
@buf = external dso_local global [201 x i8], align 16
@nbuf = external dso_local local_unnamed_addr global i32, align 4
@bufstart = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local range(i64 -1, 68719476736) i64 @parsenum() local_unnamed_addr #0 {
  %1 = load ptr, ptr @bufstart, align 8, !tbaa !5
  %2 = load i32, ptr @nbuf, align 4, !tbaa !9
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [201 x i8], ptr @buf, i64 0, i64 %3
  %5 = icmp ult ptr %1, %4
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %6 = load i32, ptr @base, align 4
  %7 = sext i32 %6 to i64
  br label %8

8:                                                ; preds = %.lr.ph, %11
  %.012 = phi ptr [ %1, %.lr.ph ], [ %17, %11 ]
  %.0811 = phi i64 [ 0, %.lr.ph ], [ %16, %11 ]
  %9 = load i8, ptr %.012, align 1, !tbaa !11
  %10 = add i8 %9, -48
  %or.cond = icmp ult i8 %10, 10
  br i1 %or.cond, label %11, label %._crit_edge

11:                                               ; preds = %8
  %12 = mul i64 %.0811, %7
  %13 = zext nneg i8 %9 to i64
  %14 = add nuw nsw i64 %13, 68719476688
  %15 = add i64 %14, %12
  %16 = and i64 %15, 68719476735
  %17 = getelementptr inbounds i8, ptr %.012, i64 1
  %18 = icmp ult ptr %17, %4
  br i1 %18, label %8, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %8, %11, %0
  %.09 = phi i64 [ 0, %0 ], [ %16, %11 ], [ -1, %8 ]
  ret i64 %.09
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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 = !{!"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"}


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