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

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

%struct.ScreenWorkStruct = type { %struct.ScreenStruct, ptr, ptr, ptr, ptr, %struct.HistoryStruct, i8, i32, i8 }
%struct.ScreenStruct = type { ptr, ptr, ptr, i8, i16, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.HistoryStruct = type { i8, [8 x i32] }

; Function Attrs: nounwind uwtable
define dso_local void @showScreenWork(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i16, align 2
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %11, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  store ptr %17, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.ScreenStruct, ptr %19, i32 0, i32 3
  %21 = load i8, ptr %20, align 8, !tbaa !17, !range !18, !noundef !19
  %22 = trunc i8 %21 to i1
  br i1 %22, label %31, label %23

23:                                               ; preds = %1
  %24 = call i64 @millis()
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %25, i32 0, i32 7
  %27 = load i32, ptr %26, align 8, !tbaa !20
  %28 = zext i32 %27 to i64
  %29 = icmp ult i64 %24, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  store i32 1, ptr %6, align 4
  br label %111

31:                                               ; preds = %23, %1
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.ScreenStruct, ptr %33, i32 0, i32 3
  store i8 0, ptr %34, align 8, !tbaa !17
  %35 = call i64 @millis()
  %36 = add i64 %35, 1000
  %37 = trunc i64 %36 to i32
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %38, i32 0, i32 7
  store i32 %37, ptr %39, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #4
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = call zeroext i16 @lastTemp(ptr noundef %40)
  store i16 %41, ptr %7, align 2, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #4
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = call zeroext i16 @getTemp(ptr noundef %42)
  store i16 %43, ptr %8, align 2, !tbaa !21
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %44, i32 0, i32 5
  %46 = load i16, ptr %7, align 2, !tbaa !21
  %47 = zext i16 %46 to i32
  call void @put(ptr noundef %45, i32 noundef %47)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %48, i32 0, i32 5
  %50 = call i32 @average(ptr noundef %49)
  store i32 %50, ptr %9, align 4, !tbaa !22
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !22
  %53 = trunc i32 %52 to i16
  %54 = call zeroext i16 @temp2humanUnits(ptr noundef %51, i16 noundef zeroext %53)
  store i16 %54, ptr %7, align 2, !tbaa !21
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i16, ptr %7, align 2, !tbaa !21
  %57 = zext i16 %56 to i32
  call void @number(ptr noundef %55, i32 noundef %57, i8 noundef zeroext 0)
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = call zeroext i8 @appliedPower(ptr noundef %58)
  store i8 %59, ptr %10, align 1, !tbaa !23
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load i8, ptr %10, align 1, !tbaa !23
  call void @percent(ptr noundef %60, i8 noundef zeroext %61)
  %62 = load i16, ptr %8, align 2, !tbaa !21
  %63 = zext i16 %62 to i32
  %64 = load i32, ptr %9, align 4, !tbaa !22
  %65 = sub nsw i32 %63, %64
  %66 = call i32 @llvm.abs.i32(i32 %65, i1 true)
  %67 = icmp slt i32 %66, 4
  br i1 %67, label %68, label %88

68:                                               ; preds = %31
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %69, i32 0, i32 5
  %71 = call float @dispersion(ptr noundef %70)
  %72 = fcmp olt float %71, 1.500000e+01
  br i1 %72, label %73, label %88

73:                                               ; preds = %68
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  call void @noAnimation(ptr noundef %74)
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %75, i32 0, i32 6
  store i8 0, ptr %76, align 4, !tbaa !24
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %77, i32 0, i32 8
  %79 = load i8, ptr %78, align 4, !tbaa !25, !range !18, !noundef !19
  %80 = trunc i8 %79 to i1
  br i1 %80, label %87, label %81

81:                                               ; preds = %73
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %82, i32 0, i32 3
  %84 = load ptr, ptr %83, align 8, !tbaa !26
  call void @shortBeep(ptr noundef %84)
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %85, i32 0, i32 8
  store i8 1, ptr %86, align 4, !tbaa !25
  br label %87

87:                                               ; preds = %81, %73
  store i32 1, ptr %6, align 4
  br label %110

88:                                               ; preds = %68, %31
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %89, i32 0, i32 8
  %91 = load i8, ptr %90, align 4, !tbaa !25, !range !18, !noundef !19
  %92 = trunc i8 %91 to i1
  br i1 %92, label %109, label %93

93:                                               ; preds = %88
  %94 = load i16, ptr %7, align 2, !tbaa !21
  %95 = zext i16 %94 to i32
  %96 = load i16, ptr %8, align 2, !tbaa !21
  %97 = zext i16 %96 to i32
  %98 = icmp slt i32 %95, %97
  br i1 %98, label %99, label %109

99:                                               ; preds = %93
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %100, i32 0, i32 6
  %102 = load i8, ptr %101, align 4, !tbaa !24, !range !18, !noundef !19
  %103 = trunc i8 %102 to i1
  br i1 %103, label %108, label %104

104:                                              ; preds = %99
  %105 = load ptr, ptr %3, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %105, i32 0, i32 6
  store i8 1, ptr %106, align 4, !tbaa !24
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  call void @heating(ptr noundef %107)
  br label %108

108:                                              ; preds = %104, %99
  br label %109

109:                                              ; preds = %108, %93, %88
  store i32 0, ptr %6, align 4
  br label %110

110:                                              ; preds = %109, %87
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #4
  br label %111

111:                                              ; preds = %110, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  %112 = load i32, ptr %6, align 4
  switch i32 %112, label %114 [
    i32 0, label %113
    i32 1, label %113
  ]

113:                                              ; preds = %111, %111
  ret void

114:                                              ; preds = %111
  unreachable
}

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

declare zeroext i16 @getTemp(ptr noundef) #2

declare zeroext i16 @temp2humanUnits(ptr noundef, i16 noundef zeroext) #2

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

declare i64 @millis() #2

declare void @number(ptr noundef, i32 noundef, i8 noundef zeroext) #2

declare zeroext i16 @lastTemp(ptr noundef) #2

declare void @put(ptr noundef, i32 noundef) #2

declare i32 @average(ptr noundef) #2

declare zeroext i8 @appliedPower(ptr noundef) #2

declare void @percent(ptr noundef, i8 noundef zeroext) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

declare float @dispersion(ptr noundef) #2

declare void @noAnimation(ptr noundef) #2

declare void @shortBeep(ptr noundef) #2

declare void @heating(ptr noundef) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 112}
!10 = !{!"ScreenWorkStruct", !11, i64 0, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !15, i64 144, !12, i64 180, !14, i64 184, !12, i64 188}
!11 = !{!"ScreenStruct", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !13, i64 26, !14, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"HistoryStruct", !7, i64 0, !7, i64 4}
!16 = !{!10, !6, i64 120}
!17 = !{!10, !12, i64 24}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!10, !14, i64 184}
!21 = !{!13, !13, i64 0}
!22 = !{!14, !14, i64 0}
!23 = !{!7, !7, i64 0}
!24 = !{!10, !12, i64 180}
!25 = !{!10, !12, i64 188}
!26 = !{!10, !6, i64 128}


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

; Function Attrs: nounwind uwtable
define dso_local void @showScreenWork(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 112
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 120
  %5 = load ptr, ptr %4, align 8, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i8, ptr %6, align 8, !tbaa !16, !range !17, !noundef !18
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %15, label %9

9:                                                ; preds = %1
  %10 = tail call i64 @millis() #3
  %11 = getelementptr inbounds i8, ptr %0, i64 184
  %12 = load i32, ptr %11, align 8, !tbaa !19
  %13 = zext i32 %12 to i64
  %14 = icmp ult i64 %10, %13
  br i1 %14, label %54, label %15

15:                                               ; preds = %9, %1
  store i8 0, ptr %6, align 8, !tbaa !16
  %16 = tail call i64 @millis() #3
  %17 = trunc i64 %16 to i32
  %18 = add i32 %17, 1000
  %19 = getelementptr inbounds i8, ptr %0, i64 184
  store i32 %18, ptr %19, align 8, !tbaa !19
  %20 = tail call zeroext i16 @lastTemp(ptr noundef %3) #3
  %21 = tail call zeroext i16 @getTemp(ptr noundef %3) #3
  %22 = getelementptr inbounds i8, ptr %0, i64 144
  %23 = zext i16 %20 to i32
  tail call void @put(ptr noundef nonnull %22, i32 noundef %23) #3
  %24 = tail call i32 @average(ptr noundef nonnull %22) #3
  %25 = trunc i32 %24 to i16
  %26 = tail call zeroext i16 @temp2humanUnits(ptr noundef %3, i16 noundef zeroext %25) #3
  %27 = zext i16 %26 to i32
  tail call void @number(ptr noundef %5, i32 noundef %27, i8 noundef zeroext 0) #3
  %28 = tail call zeroext i8 @appliedPower(ptr noundef %3) #3
  tail call void @percent(ptr noundef %5, i8 noundef zeroext %28) #3
  %29 = zext i16 %21 to i32
  %30 = sub nsw i32 %29, %24
  %31 = tail call i32 @llvm.abs.i32(i32 %30, i1 true)
  %32 = icmp ult i32 %31, 4
  br i1 %32, label %33, label %44

33:                                               ; preds = %15
  %34 = tail call float @dispersion(ptr noundef nonnull %22) #3
  %35 = fcmp olt float %34, 1.500000e+01
  br i1 %35, label %36, label %44

36:                                               ; preds = %33
  tail call void @noAnimation(ptr noundef %5) #3
  %37 = getelementptr inbounds i8, ptr %0, i64 180
  store i8 0, ptr %37, align 4, !tbaa !20
  %38 = getelementptr inbounds i8, ptr %0, i64 188
  %39 = load i8, ptr %38, align 4, !tbaa !21, !range !17, !noundef !18
  %40 = trunc nuw i8 %39 to i1
  br i1 %40, label %54, label %41

41:                                               ; preds = %36
  %42 = getelementptr inbounds i8, ptr %0, i64 128
  %43 = load ptr, ptr %42, align 8, !tbaa !22
  tail call void @shortBeep(ptr noundef %43) #3
  store i8 1, ptr %38, align 4, !tbaa !21
  br label %54

44:                                               ; preds = %33, %15
  %45 = getelementptr inbounds i8, ptr %0, i64 188
  %46 = load i8, ptr %45, align 4, !tbaa !21, !range !17, !noundef !18
  %47 = trunc nuw i8 %46 to i1
  %48 = icmp uge i16 %26, %21
  %or.cond.not = select i1 %47, i1 true, i1 %48
  br i1 %or.cond.not, label %54, label %49

49:                                               ; preds = %44
  %50 = getelementptr inbounds i8, ptr %0, i64 180
  %51 = load i8, ptr %50, align 4, !tbaa !20, !range !17, !noundef !18
  %52 = trunc nuw i8 %51 to i1
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  store i8 1, ptr %50, align 4, !tbaa !20
  tail call void @heating(ptr noundef %5) #3
  br label %54

54:                                               ; preds = %41, %36, %49, %53, %44, %9
  ret void
}

declare zeroext i16 @getTemp(ptr noundef) local_unnamed_addr #1

declare zeroext i16 @temp2humanUnits(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

declare i64 @millis() local_unnamed_addr #1

declare void @number(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

declare zeroext i16 @lastTemp(ptr noundef) local_unnamed_addr #1

declare void @put(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @average(ptr noundef) local_unnamed_addr #1

declare zeroext i8 @appliedPower(ptr noundef) local_unnamed_addr #1

declare void @percent(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

declare float @dispersion(ptr noundef) local_unnamed_addr #1

declare void @noAnimation(ptr noundef) local_unnamed_addr #1

declare void @shortBeep(ptr noundef) local_unnamed_addr #1

declare void @heating(ptr noundef) local_unnamed_addr #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 = { "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !8, i64 112}
!6 = !{!"ScreenWorkStruct", !7, i64 0, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !14, i64 144, !11, i64 180, !13, i64 184, !11, i64 188}
!7 = !{!"ScreenStruct", !8, i64 0, !8, i64 8, !8, i64 16, !11, i64 24, !12, i64 26, !13, i64 28, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"_Bool", !9, i64 0}
!12 = !{!"short", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"HistoryStruct", !9, i64 0, !9, i64 4}
!15 = !{!6, !8, i64 120}
!16 = !{!6, !11, i64 24}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !13, i64 184}
!20 = !{!6, !11, i64 180}
!21 = !{!6, !11, i64 188}
!22 = !{!6, !8, i64 128}


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