; LLVM IR from control-flow-attestation/c-flat :: samples/soldering (arduino)

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

@PROBEPIN_value = external dso_local global i32, align 4
@HEATERPIN_value = external dso_local global i32, align 4
@tempCounter = external dso_local global i32, align 4

; 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 void @updateTemperature() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = load i32, ptr @tempCounter, align 4, !tbaa !5
  %4 = icmp sge i32 %3, 400
  br i1 %4, label %5, label %45

5:                                                ; preds = %0
  store i32 0, ptr @tempCounter, align 4, !tbaa !5
  %6 = load i32, ptr @HEATERPIN_value, align 4, !tbaa !5
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %33

8:                                                ; preds = %5
  %9 = load i32, ptr @PROBEPIN_value, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 1023
  br i1 %10, label %11, label %33

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %12 = load i32, ptr @HEATERPIN_value, align 4, !tbaa !5
  %13 = call i32 @map(i32 noundef %12, i32 noundef 0, i32 noundef 255, i32 noundef 256, i32 noundef 700)
  store i32 %13, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = load i32, ptr @PROBEPIN_value, align 4, !tbaa !5
  %16 = sub nsw i32 %14, %15
  store i32 %16, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %11
  br label %29

20:                                               ; preds = %11
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = icmp slt i32 %21, 10
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  br label %27

24:                                               ; preds = %20
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sdiv i32 %25, 10
  br label %27

27:                                               ; preds = %24, %23
  %28 = phi i32 [ 1, %23 ], [ %26, %24 ]
  br label %29

29:                                               ; preds = %27, %19
  %30 = phi i32 [ -1, %19 ], [ %28, %27 ]
  %31 = load i32, ptr @PROBEPIN_value, align 4, !tbaa !5
  %32 = add nsw i32 %31, %30
  store i32 %32, ptr @PROBEPIN_value, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %44

33:                                               ; preds = %8, %5
  %34 = load i32, ptr @PROBEPIN_value, align 4, !tbaa !5
  %35 = icmp sgt i32 %34, 256
  br i1 %35, label %36, label %43

36:                                               ; preds = %33
  %37 = load i32, ptr @PROBEPIN_value, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 2
  store i32 %38, ptr @PROBEPIN_value, align 4, !tbaa !5
  %39 = load i32, ptr @PROBEPIN_value, align 4, !tbaa !5
  %40 = icmp slt i32 %39, 256
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  store i32 256, ptr @PROBEPIN_value, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %41, %36
  br label %43

43:                                               ; preds = %42, %33
  br label %44

44:                                               ; preds = %43, %29
  br label %45

45:                                               ; preds = %44, %0
  %46 = load i32, ptr @tempCounter, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr @tempCounter, align 4, !tbaa !5
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @map(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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

@PROBEPIN_value = external dso_local local_unnamed_addr global i32, align 4
@HEATERPIN_value = external dso_local local_unnamed_addr global i32, align 4
@tempCounter = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @updateTemperature() local_unnamed_addr #0 {
  %1 = load i32, ptr @tempCounter, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 399
  br i1 %2, label %3, label %24

3:                                                ; preds = %0
  store i32 0, ptr @tempCounter, align 4, !tbaa !5
  %4 = load i32, ptr @HEATERPIN_value, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 0
  %6 = load i32, ptr @PROBEPIN_value, align 4
  %7 = icmp slt i32 %6, 1023
  %or.cond = select i1 %5, i1 %7, i1 false
  br i1 %or.cond, label %8, label %20

8:                                                ; preds = %3
  %9 = tail call i32 @map(i32 noundef %4, i32 noundef 0, i32 noundef 255, i32 noundef 256, i32 noundef 700)
  %10 = load i32, ptr @PROBEPIN_value, align 4, !tbaa !5
  %11 = sub nsw i32 %9, %10
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %17, label %13

13:                                               ; preds = %8
  %14 = icmp ult i32 %11, 10
  br i1 %14, label %17, label %15

15:                                               ; preds = %13
  %16 = udiv i32 %11, 10
  br label %17

17:                                               ; preds = %15, %13, %8
  %18 = phi i32 [ -1, %8 ], [ %16, %15 ], [ 1, %13 ]
  %19 = add nsw i32 %18, %10
  store i32 %19, ptr @PROBEPIN_value, align 4, !tbaa !5
  %.pre = load i32, ptr @tempCounter, align 4, !tbaa !5
  br label %24

20:                                               ; preds = %3
  %21 = icmp sgt i32 %6, 256
  br i1 %21, label %22, label %24

22:                                               ; preds = %20
  %23 = tail call i32 @llvm.umax.i32(i32 %6, i32 258)
  %spec.store.select = add nsw i32 %23, -2
  store i32 %spec.store.select, ptr @PROBEPIN_value, align 4
  br label %24

24:                                               ; preds = %17, %22, %20, %0
  %25 = phi i32 [ %.pre, %17 ], [ 0, %22 ], [ 0, %20 ], [ %1, %0 ]
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @tempCounter, align 4, !tbaa !5
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @map(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass