; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/qrduino (qrencode)

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

@strinbuf = external global ptr, align 8
@qrframe = external global ptr, align 8
@WD = external global i8, align 1
@WDB = external global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local void @qrencode() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 30000, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #3
  store i8 0, ptr %2, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @stringtoqr()
  call void @fillframe()
  %5 = load ptr, ptr @strinbuf, align 8, !tbaa !10
  %6 = load ptr, ptr @qrframe, align 8, !tbaa !10
  %7 = load i8, ptr @WD, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = load i8, ptr @WDB, align 1, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = mul nsw i32 %8, %10
  %12 = sext i32 %11 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 1 %6, i64 %12, i1 false)
  store i8 0, ptr %3, align 1, !tbaa !9
  br label %13

13:                                               ; preds = %40, %0
  %14 = load i8, ptr %3, align 1, !tbaa !9
  %15 = zext i8 %14 to i32
  %16 = icmp slt i32 %15, 8
  br i1 %16, label %17, label %43

17:                                               ; preds = %13
  %18 = load i8, ptr %3, align 1, !tbaa !9
  call void @applymask(i8 noundef zeroext %18)
  %19 = call i32 @badcheck()
  store i32 %19, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %23, label %26

23:                                               ; preds = %17
  %24 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %24, ptr %1, align 4, !tbaa !5
  %25 = load i8, ptr %3, align 1, !tbaa !9
  store i8 %25, ptr %2, align 1, !tbaa !9
  br label %26

26:                                               ; preds = %23, %17
  %27 = load i8, ptr %2, align 1, !tbaa !9
  %28 = zext i8 %27 to i32
  %29 = icmp eq i32 %28, 7
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  br label %43

31:                                               ; preds = %26
  %32 = load ptr, ptr @qrframe, align 8, !tbaa !10
  %33 = load ptr, ptr @strinbuf, align 8, !tbaa !10
  %34 = load i8, ptr @WD, align 1, !tbaa !9
  %35 = zext i8 %34 to i32
  %36 = load i8, ptr @WDB, align 1, !tbaa !9
  %37 = zext i8 %36 to i32
  %38 = mul nsw i32 %35, %37
  %39 = sext i32 %38 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %32, ptr align 1 %33, i64 %39, i1 false)
  br label %40

40:                                               ; preds = %31
  %41 = load i8, ptr %3, align 1, !tbaa !9
  %42 = add i8 %41, 1
  store i8 %42, ptr %3, align 1, !tbaa !9
  br label %13, !llvm.loop !12

43:                                               ; preds = %30, %13
  %44 = load i8, ptr %2, align 1, !tbaa !9
  %45 = zext i8 %44 to i32
  %46 = load i8, ptr %3, align 1, !tbaa !9
  %47 = zext i8 %46 to i32
  %48 = icmp ne i32 %45, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %43
  %50 = load i8, ptr %2, align 1, !tbaa !9
  call void @applymask(i8 noundef zeroext %50)
  br label %51

51:                                               ; preds = %49, %43
  %52 = load i8, ptr %2, align 1, !tbaa !9
  call void @addfmt(i8 noundef zeroext %52)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  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: nounwind uwtable
declare hidden void @stringtoqr() #0

; Function Attrs: nounwind uwtable
declare hidden void @fillframe() #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden void @applymask(i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare hidden void @addfmt(i8 noundef zeroext) #0

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

; Function Attrs: nounwind uwtable
declare hidden i32 @badcheck() #0

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !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"

@strinbuf = external local_unnamed_addr global ptr, align 8
@qrframe = external local_unnamed_addr global ptr, align 8
@WD = external local_unnamed_addr global i8, align 1
@WDB = external local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local void @qrencode() local_unnamed_addr #0 {
  tail call void @stringtoqr()
  tail call void @fillframe()
  %1 = load ptr, ptr @strinbuf, align 8, !tbaa !5
  %2 = load ptr, ptr @qrframe, align 8, !tbaa !5
  %3 = load i8, ptr @WD, align 1, !tbaa !9
  %4 = zext i8 %3 to i64
  %5 = load i8, ptr @WDB, align 1, !tbaa !9
  %6 = zext i8 %5 to i64
  %7 = mul nuw nsw i64 %6, %4
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr align 1 %2, i64 %7, i1 false)
  tail call void @applymask(i8 noundef zeroext 0)
  %8 = tail call i32 @badcheck()
  %9 = load ptr, ptr @qrframe, align 8, !tbaa !5
  %10 = load ptr, ptr @strinbuf, align 8, !tbaa !5
  %11 = load i8, ptr @WD, align 1, !tbaa !9
  %12 = zext i8 %11 to i64
  %13 = load i8, ptr @WDB, align 1, !tbaa !9
  %14 = zext i8 %13 to i64
  %15 = mul nuw nsw i64 %14, %12
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %9, ptr align 1 %10, i64 %15, i1 false)
  tail call void @applymask(i8 noundef zeroext 1)
  %16 = tail call i32 @badcheck()
  %17 = load ptr, ptr @qrframe, align 8, !tbaa !5
  %18 = load ptr, ptr @strinbuf, align 8, !tbaa !5
  %19 = load i8, ptr @WD, align 1, !tbaa !9
  %20 = zext i8 %19 to i64
  %21 = load i8, ptr @WDB, align 1, !tbaa !9
  %22 = zext i8 %21 to i64
  %23 = mul nuw nsw i64 %22, %20
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %17, ptr align 1 %18, i64 %23, i1 false)
  tail call void @applymask(i8 noundef zeroext 2)
  %24 = tail call i32 @badcheck()
  %25 = load ptr, ptr @qrframe, align 8, !tbaa !5
  %26 = load ptr, ptr @strinbuf, align 8, !tbaa !5
  %27 = load i8, ptr @WD, align 1, !tbaa !9
  %28 = zext i8 %27 to i64
  %29 = load i8, ptr @WDB, align 1, !tbaa !9
  %30 = zext i8 %29 to i64
  %31 = mul nuw nsw i64 %30, %28
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 1 %26, i64 %31, i1 false)
  tail call void @applymask(i8 noundef zeroext 3)
  %32 = tail call i32 @badcheck()
  %33 = load ptr, ptr @qrframe, align 8, !tbaa !5
  %34 = load ptr, ptr @strinbuf, align 8, !tbaa !5
  %35 = load i8, ptr @WD, align 1, !tbaa !9
  %36 = zext i8 %35 to i64
  %37 = load i8, ptr @WDB, align 1, !tbaa !9
  %38 = zext i8 %37 to i64
  %39 = mul nuw nsw i64 %38, %36
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr align 1 %34, i64 %39, i1 false)
  tail call void @applymask(i8 noundef zeroext 4)
  %40 = tail call i32 @badcheck()
  %41 = load ptr, ptr @qrframe, align 8, !tbaa !5
  %42 = load ptr, ptr @strinbuf, align 8, !tbaa !5
  %43 = load i8, ptr @WD, align 1, !tbaa !9
  %44 = zext i8 %43 to i64
  %45 = load i8, ptr @WDB, align 1, !tbaa !9
  %46 = zext i8 %45 to i64
  %47 = mul nuw nsw i64 %46, %44
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %41, ptr align 1 %42, i64 %47, i1 false)
  tail call void @applymask(i8 noundef zeroext 5)
  %48 = tail call i32 @badcheck()
  %49 = load ptr, ptr @qrframe, align 8, !tbaa !5
  %50 = load ptr, ptr @strinbuf, align 8, !tbaa !5
  %51 = load i8, ptr @WD, align 1, !tbaa !9
  %52 = zext i8 %51 to i64
  %53 = load i8, ptr @WDB, align 1, !tbaa !9
  %54 = zext i8 %53 to i64
  %55 = mul nuw nsw i64 %54, %52
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %49, ptr align 1 %50, i64 %55, i1 false)
  tail call void @applymask(i8 noundef zeroext 6)
  %56 = tail call i32 @badcheck()
  %spec.select16 = tail call i32 @llvm.umin.i32(i32 %8, i32 30000)
  %spec.select16.1 = tail call i32 @llvm.umin.i32(i32 %16, i32 %spec.select16)
  %spec.select16.2 = tail call i32 @llvm.umin.i32(i32 %24, i32 %spec.select16.1)
  %spec.select16.3 = tail call i32 @llvm.umin.i32(i32 %32, i32 %spec.select16.2)
  %spec.select16.4 = tail call i32 @llvm.umin.i32(i32 %40, i32 %spec.select16.3)
  %spec.select16.5 = tail call i32 @llvm.umin.i32(i32 %48, i32 %spec.select16.4)
  %spec.select16.6 = tail call i32 @llvm.umin.i32(i32 %56, i32 %spec.select16.5)
  %57 = load ptr, ptr @qrframe, align 8, !tbaa !5
  %58 = load ptr, ptr @strinbuf, align 8, !tbaa !5
  %59 = load i8, ptr @WD, align 1, !tbaa !9
  %60 = zext i8 %59 to i64
  %61 = load i8, ptr @WDB, align 1, !tbaa !9
  %62 = zext i8 %61 to i64
  %63 = mul nuw nsw i64 %62, %60
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %57, ptr align 1 %58, i64 %63, i1 false)
  tail call void @applymask(i8 noundef zeroext 7)
  %64 = tail call i32 @badcheck()
  %65 = icmp ult i32 %64, %spec.select16.6
  br i1 %65, label %.thread, label %66

66:                                               ; preds = %0
  %67 = icmp ult i32 %56, %spec.select16.5
  %68 = icmp ult i32 %48, %spec.select16.4
  %69 = icmp ult i32 %40, %spec.select16.3
  %70 = icmp ult i32 %32, %spec.select16.2
  %71 = icmp ult i32 %24, %spec.select16.1
  %72 = icmp ult i32 %16, %spec.select16
  %spec.select.1 = zext i1 %72 to i8
  %spec.select.2 = select i1 %71, i8 2, i8 %spec.select.1
  %spec.select.3 = select i1 %70, i8 3, i8 %spec.select.2
  %spec.select.4 = select i1 %69, i8 4, i8 %spec.select.3
  %spec.select.5 = select i1 %68, i8 5, i8 %spec.select.4
  %spec.select.6 = select i1 %67, i8 6, i8 %spec.select.5
  %73 = load ptr, ptr @qrframe, align 8, !tbaa !5
  %74 = load ptr, ptr @strinbuf, align 8, !tbaa !5
  %75 = load i8, ptr @WD, align 1, !tbaa !9
  %76 = zext i8 %75 to i64
  %77 = load i8, ptr @WDB, align 1, !tbaa !9
  %78 = zext i8 %77 to i64
  %79 = mul nuw nsw i64 %78, %76
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %73, ptr align 1 %74, i64 %79, i1 false)
  tail call void @applymask(i8 noundef zeroext %spec.select.6)
  br label %.thread

.thread:                                          ; preds = %0, %66
  %.229 = phi i8 [ %spec.select.6, %66 ], [ 7, %0 ]
  tail call void @addfmt(i8 noundef zeroext %.229)
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @stringtoqr() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @fillframe() local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden void @applymask(i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @addfmt(i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @badcheck() local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass