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

; 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.ScreenTuneStruct = type { %struct.ScreenStruct, ptr, ptr, ptr, ptr, ptr, i8, i8, i32, [2 x i16], %struct.HistoryStruct, 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 @showScreenTune(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 i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %9, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %10, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  store ptr %15, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.ScreenStruct, ptr %17, i32 0, i32 3
  %19 = load i8, ptr %18, align 8, !tbaa !17, !range !18, !noundef !19
  %20 = trunc i8 %19 to i1
  br i1 %20, label %29, label %21

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

28:                                               ; preds = %21
  store i32 1, ptr %6, align 4
  br label %80

29:                                               ; preds = %21, %1
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.ScreenStruct, ptr %31, i32 0, i32 3
  store i8 0, ptr %32, align 8, !tbaa !17
  %33 = call i64 @millis()
  %34 = add i64 %33, 1000
  %35 = trunc i64 %34 to i32
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %36, i32 0, i32 8
  store i32 %35, ptr %37, align 4, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = call zeroext i16 @Iron_temp(ptr noundef %38)
  store i16 %39, ptr %7, align 2, !tbaa !21
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %40, i32 0, i32 10
  %42 = load i16, ptr %7, align 2, !tbaa !21
  %43 = sext i16 %42 to i32
  call void @put(ptr noundef %41, i32 noundef %43)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %44, i32 0, i32 10
  %46 = call i32 @average(ptr noundef %45)
  %47 = trunc i32 %46 to i16
  store i16 %47, ptr %7, align 2, !tbaa !21
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i16, ptr %7, align 2, !tbaa !21
  %50 = sext i16 %49 to i32
  call void @number(ptr noundef %48, i32 noundef %50, i8 noundef zeroext 0)
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %51, i32 0, i32 6
  %53 = load i8, ptr %52, align 8, !tbaa !22, !range !18, !noundef !19
  %54 = trunc i8 %53 to i1
  br i1 %54, label %55, label %57

55:                                               ; preds = %29
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  call void @upper(ptr noundef %56)
  br label %59

57:                                               ; preds = %29
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  call void @lower(ptr noundef %58)
  br label %59

59:                                               ; preds = %57, %55
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call zeroext i8 @appliedPower(ptr noundef %60)
  store i8 %61, ptr %8, align 1, !tbaa !23
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load i8, ptr %8, align 1, !tbaa !23
  call void @percent(ptr noundef %62, i8 noundef zeroext %63)
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %64, i32 0, i32 7
  %66 = load i8, ptr %65, align 1, !tbaa !24, !range !18, !noundef !19
  %67 = trunc i8 %66 to i1
  br i1 %67, label %68, label %79

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

73:                                               ; preds = %68
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %74, i32 0, i32 4
  %76 = load ptr, ptr %75, align 8, !tbaa !25
  call void @shortBeep(ptr noundef %76)
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %77, i32 0, i32 7
  store i8 0, ptr %78, align 1, !tbaa !24
  br label %79

79:                                               ; preds = %73, %68, %59
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  store i32 0, ptr %6, align 4
  br label %80

80:                                               ; preds = %79, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %81 = load i32, ptr %6, align 4
  switch i32 %81, label %83 [
    i32 0, label %82
    i32 1, label %82
  ]

82:                                               ; preds = %80, %80
  ret void

83:                                               ; preds = %80
  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 @Iron_temp(ptr noundef) #2

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

declare i32 @average(ptr noundef) #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 void @upper(ptr noundef) #2

declare void @lower(ptr noundef) #2

declare zeroext i8 @appliedPower(ptr noundef) #2

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

declare float @dispersion(ptr noundef) #2

declare void @shortBeep(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 = { 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 120}
!10 = !{!"ScreenTuneStruct", !11, i64 0, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !12, i64 152, !12, i64 153, !14, i64 156, !7, i64 160, !15, i64 164, !7, i64 200}
!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 112}
!17 = !{!10, !12, i64 24}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!10, !14, i64 156}
!21 = !{!13, !13, i64 0}
!22 = !{!10, !12, i64 152}
!23 = !{!7, !7, i64 0}
!24 = !{!10, !12, i64 153}
!25 = !{!10, !6, i64 136}


; 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 @showScreenTune(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 120
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 112
  %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() #2
  %11 = getelementptr inbounds i8, ptr %0, i64 156
  %12 = load i32, ptr %11, align 4, !tbaa !19
  %13 = zext i32 %12 to i64
  %14 = icmp ult i64 %10, %13
  br i1 %14, label %41, label %15

15:                                               ; preds = %9, %1
  store i8 0, ptr %6, align 8, !tbaa !16
  %16 = tail call i64 @millis() #2
  %17 = trunc i64 %16 to i32
  %18 = add i32 %17, 1000
  %19 = getelementptr inbounds i8, ptr %0, i64 156
  store i32 %18, ptr %19, align 4, !tbaa !19
  %20 = tail call zeroext i16 @Iron_temp(ptr noundef %5) #2
  %21 = getelementptr inbounds i8, ptr %0, i64 164
  %22 = sext i16 %20 to i32
  tail call void @put(ptr noundef nonnull %21, i32 noundef %22) #2
  %23 = tail call i32 @average(ptr noundef nonnull %21) #2
  %sext = shl i32 %23, 16
  %24 = ashr exact i32 %sext, 16
  tail call void @number(ptr noundef %3, i32 noundef %24, i8 noundef zeroext 0) #2
  %25 = getelementptr inbounds i8, ptr %0, i64 152
  %26 = load i8, ptr %25, align 8, !tbaa !20, !range !17, !noundef !18
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %28, label %29

28:                                               ; preds = %15
  tail call void @upper(ptr noundef %3) #2
  br label %30

29:                                               ; preds = %15
  tail call void @lower(ptr noundef %3) #2
  br label %30

30:                                               ; preds = %29, %28
  %31 = tail call zeroext i8 @appliedPower(ptr noundef %5) #2
  tail call void @percent(ptr noundef %3, i8 noundef zeroext %31) #2
  %32 = getelementptr inbounds i8, ptr %0, i64 153
  %33 = load i8, ptr %32, align 1, !tbaa !21, !range !17, !noundef !18
  %34 = trunc nuw i8 %33 to i1
  br i1 %34, label %35, label %41

35:                                               ; preds = %30
  %36 = tail call float @dispersion(ptr noundef nonnull %21) #2
  %37 = fcmp olt float %36, 1.500000e+01
  br i1 %37, label %38, label %41

38:                                               ; preds = %35
  %39 = getelementptr inbounds i8, ptr %0, i64 136
  %40 = load ptr, ptr %39, align 8, !tbaa !22
  tail call void @shortBeep(ptr noundef %40) #2
  store i8 0, ptr %32, align 1, !tbaa !21
  br label %41

41:                                               ; preds = %30, %35, %38, %9
  ret void
}

declare zeroext i16 @Iron_temp(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 i64 @millis() local_unnamed_addr #1

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

declare void @upper(ptr noundef) local_unnamed_addr #1

declare void @lower(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

declare float @dispersion(ptr noundef) local_unnamed_addr #1

declare void @shortBeep(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 = { 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 120}
!6 = !{!"ScreenTuneStruct", !7, i64 0, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !8, i64 144, !11, i64 152, !11, i64 153, !13, i64 156, !9, i64 160, !14, i64 164, !9, i64 200}
!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 112}
!16 = !{!6, !11, i64 24}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !13, i64 156}
!20 = !{!6, !11, i64 152}
!21 = !{!6, !11, i64 153}
!22 = !{!6, !8, i64 136}


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