; LLVM IR from aap/pdp6 :: emu (mem)

; 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.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [26 x i8], align 1

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

17:                                               ; preds = %3
  store i32 1, ptr %12, align 4
  br label %85

18:                                               ; preds = %3
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %81, %18
  %20 = getelementptr inbounds [100 x i8], ptr %8, i64 0, i64 0
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = call ptr @fgets(ptr noundef %20, i32 noundef 100, ptr noundef %21)
  store ptr %22, ptr %9, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %82

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %80, %24
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !13
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %29, label %81

29:                                               ; preds = %25
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !13
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 59
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  br label %81

35:                                               ; preds = %29
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = sext i8 %37 to i32
  %39 = icmp sle i32 48, %38
  br i1 %39, label %40, label %76

40:                                               ; preds = %35
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = sext i8 %42 to i32
  %44 = icmp sle i32 %43, 55
  br i1 %44, label %45, label %76

45:                                               ; preds = %40
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = call i64 @strtol(ptr noundef %46, ptr noundef %9, i32 noundef 8) #4
  store i64 %47, ptr %11, align 8, !tbaa !9
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = load i8, ptr %48, align 1, !tbaa !13
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %50, 58
  br i1 %51, label %52, label %57

52:                                               ; preds = %45
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = trunc i64 %53 to i32
  store i32 %54, ptr %10, align 4, !tbaa !11
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i32 1
  store ptr %56, ptr %9, align 8, !tbaa !5
  br label %75

57:                                               ; preds = %45
  %58 = load i32, ptr %10, align 4, !tbaa !11
  %59 = zext i32 %58 to i64
  %60 = load i64, ptr %6, align 8, !tbaa !9
  %61 = icmp ult i64 %59, %60
  br i1 %61, label %62, label %69

62:                                               ; preds = %57
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !11
  %66 = add i32 %65, 1
  store i32 %66, ptr %10, align 4, !tbaa !11
  %67 = zext i32 %65 to i64
  %68 = getelementptr inbounds i64, ptr %64, i64 %67
  store i64 %63, ptr %68, align 8, !tbaa !9
  br label %74

69:                                               ; preds = %57
  %70 = load ptr, ptr @stderr, align 8, !tbaa !5
  %71 = load i32, ptr %10, align 4, !tbaa !11
  %72 = add i32 %71, 1
  store i32 %72, ptr %10, align 4, !tbaa !11
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.4, i32 noundef %71) #4
  br label %74

74:                                               ; preds = %69, %62
  br label %75

75:                                               ; preds = %74, %52
  br label %79

76:                                               ; preds = %40, %35
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i32 1
  store ptr %78, ptr %9, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %76, %75
  br label %80

80:                                               ; preds = %79
  br label %25, !llvm.loop !14

81:                                               ; preds = %34, %25
  br label %19, !llvm.loop !16

82:                                               ; preds = %19
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = call i32 @fclose(ptr noundef %83)
  store i32 0, ptr %12, align 4
  br label %85

85:                                               ; preds = %82, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 100, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %86 = load i32, ptr %12, align 4
  switch i32 %86, label %88 [
    i32 0, label %87
    i32 1, label %87
  ]

87:                                               ; preds = %85, %85
  ret void

88:                                               ; preds = %85
  unreachable
}

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #2

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

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

declare i32 @fclose(ptr 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 = { 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 }

!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 = !{!"long", !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"}
!16 = distinct !{!16, !15}


; 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.3 = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @readmem(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [100 x i8], align 16
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %6 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str.3)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %36, label %.preheader15

.preheader15:                                     ; preds = %3
  %8 = call ptr @fgets(ptr noundef nonnull %4, i32 noundef 100, ptr noundef nonnull %6)
  store ptr %8, ptr %5, align 8, !tbaa !5
  %.not16 = icmp eq ptr %8, null
  br i1 %.not16, label %._crit_edge, label %.preheader.outer

.preheader.outer:                                 ; preds = %.preheader15, %.preheader.outer.backedge
  %.ph = phi ptr [ %.ph.be, %.preheader.outer.backedge ], [ %8, %.preheader15 ]
  %.1.ph = phi i32 [ %.1.ph.be, %.preheader.outer.backedge ], [ 0, %.preheader15 ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.backedge, %.preheader.outer
  %9 = phi ptr [ %.ph, %.preheader.outer ], [ %.be, %.preheader.backedge ]
  %10 = load i8, ptr %9, align 1, !tbaa !9
  switch i8 %10, label %11 [
    i8 0, label %33
    i8 59, label %33
  ]

11:                                               ; preds = %.preheader
  %12 = and i8 %10, -8
  %or.cond = icmp eq i8 %12, 48
  br i1 %or.cond, label %13, label %31

13:                                               ; preds = %11
  %14 = call i64 @strtol(ptr noundef nonnull %9, ptr noundef nonnull %5, i32 noundef 8) #4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = icmp eq i8 %16, 58
  br i1 %17, label %18, label %21

18:                                               ; preds = %13
  %19 = trunc i64 %14 to i32
  %20 = getelementptr inbounds i8, ptr %15, i64 1
  store ptr %20, ptr %5, align 8, !tbaa !5
  br label %.preheader.outer.backedge

.preheader.outer.backedge:                        ; preds = %18, %24, %27
  %.ph.be = phi ptr [ %15, %27 ], [ %15, %24 ], [ %20, %18 ]
  %.1.ph.be = phi i32 [ %29, %27 ], [ %25, %24 ], [ %19, %18 ]
  br label %.preheader.outer, !llvm.loop !10

21:                                               ; preds = %13
  %22 = zext i32 %.1.ph to i64
  %23 = icmp ult i64 %22, %2
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  %25 = add i32 %.1.ph, 1
  %26 = getelementptr inbounds i64, ptr %1, i64 %22
  store i64 %14, ptr %26, align 8, !tbaa !12
  br label %.preheader.outer.backedge

27:                                               ; preds = %21
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = add i32 %.1.ph, 1
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.4, i32 noundef %.1.ph) #5
  br label %.preheader.outer.backedge

31:                                               ; preds = %11
  %32 = getelementptr inbounds i8, ptr %9, i64 1
  store ptr %32, ptr %5, align 8, !tbaa !5
  br label %.preheader.backedge

33:                                               ; preds = %.preheader, %.preheader
  %34 = call ptr @fgets(ptr noundef nonnull %4, i32 noundef 100, ptr noundef nonnull %6)
  store ptr %34, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %34, null
  br i1 %.not, label %._crit_edge, label %.preheader.backedge

.preheader.backedge:                              ; preds = %33, %31
  %.be = phi ptr [ %34, %33 ], [ %32, %31 ]
  br label %.preheader, !llvm.loop !10

._crit_edge:                                      ; preds = %33, %.preheader15
  %35 = call i32 @fclose(ptr noundef nonnull %6)
  br label %36

36:                                               ; preds = %3, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %4) #4
  ret void
}

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef ptr @fgets(ptr noundef, i32 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn
declare i64 @strtol(ptr noundef readonly, ptr nocapture noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

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

attributes #0 = { nofree 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 = { 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 #3 = { mustprogress nofree nounwind willreturn "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 }
attributes #5 = { cold 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}


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