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

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

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

29:                                               ; preds = %22
  store i32 1, ptr %6, align 4
  br label %60

30:                                               ; preds = %22, %1
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ScreenPowerStruct, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %struct.ScreenStruct, ptr %32, i32 0, i32 3
  store i8 0, ptr %33, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = call zeroext i16 @Iron_temp(ptr noundef %34)
  store i16 %35, ptr %7, align 2, !tbaa !21
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ScreenPowerStruct, ptr %36, i32 0, i32 6
  %38 = load i16, ptr %7, align 2, !tbaa !21
  %39 = zext i16 %38 to i32
  call void @put(ptr noundef %37, i32 noundef %39)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ScreenPowerStruct, ptr %40, i32 0, i32 6
  %42 = call i32 @average(ptr noundef %41)
  store i32 %42, ptr %8, align 4, !tbaa !22
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !22
  %45 = trunc i32 %44 to i16
  %46 = call zeroext i16 @temp2humanUnits(ptr noundef %43, i16 noundef zeroext %45)
  store i16 %46, ptr %7, align 2, !tbaa !21
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i16, ptr %7, align 2, !tbaa !21
  %49 = zext i16 %48 to i32
  call void @number(ptr noundef %47, i32 noundef %49, i8 noundef zeroext 0)
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  call void @noAnimation(ptr noundef %50)
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call zeroext i8 @appliedPower(ptr noundef %51)
  store i8 %52, ptr %9, align 1, !tbaa !23
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i8, ptr %9, align 1, !tbaa !23
  call void @percent(ptr noundef %53, i8 noundef zeroext %54)
  %55 = call i64 @millis()
  %56 = add i64 %55, 500
  %57 = trunc i64 %56 to i32
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ScreenPowerStruct, ptr %58, i32 0, i32 4
  store i32 %57, ptr %59, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  store i32 0, ptr %6, align 4
  br label %60

60:                                               ; preds = %30, %29
  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
  %61 = load i32, ptr %6, align 4
  switch i32 %61, label %63 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  ret void

63:                                               ; preds = %60
  unreachable
}

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

; 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 zeroext i16 @Iron_temp(ptr noundef) #2

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

declare i32 @average(ptr noundef) #2

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

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

declare void @noAnimation(ptr noundef) #2

declare zeroext i8 @appliedPower(ptr noundef) #2

declare void @percent(ptr noundef, i8 noundef zeroext) #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 112}
!10 = !{!"ScreenPowerStruct", !11, i64 0, !6, i64 112, !6, i64 120, !6, i64 128, !14, i64 136, !12, i64 140, !15, i64 144, !7, i64 180}
!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 136}
!21 = !{!13, !13, i64 0}
!22 = !{!14, !14, i64 0}
!23 = !{!7, !7, i64 0}


; 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 @showScreenPower(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() #2
  %11 = getelementptr inbounds i8, ptr %0, i64 136
  %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 %28, label %15

15:                                               ; preds = %9, %1
  store i8 0, ptr %6, align 8, !tbaa !16
  %16 = tail call zeroext i16 @Iron_temp(ptr noundef %3) #2
  %17 = getelementptr inbounds i8, ptr %0, i64 144
  %18 = zext i16 %16 to i32
  tail call void @put(ptr noundef nonnull %17, i32 noundef %18) #2
  %19 = tail call i32 @average(ptr noundef nonnull %17) #2
  %20 = trunc i32 %19 to i16
  %21 = tail call zeroext i16 @temp2humanUnits(ptr noundef %3, i16 noundef zeroext %20) #2
  %22 = zext i16 %21 to i32
  tail call void @number(ptr noundef %5, i32 noundef %22, i8 noundef zeroext 0) #2
  tail call void @noAnimation(ptr noundef %5) #2
  %23 = tail call zeroext i8 @appliedPower(ptr noundef %3) #2
  tail call void @percent(ptr noundef %5, i8 noundef zeroext %23) #2
  %24 = tail call i64 @millis() #2
  %25 = trunc i64 %24 to i32
  %26 = add i32 %25, 500
  %27 = getelementptr inbounds i8, ptr %0, i64 136
  store i32 %26, ptr %27, align 8, !tbaa !19
  br label %28

28:                                               ; preds = %9, %15
  ret void
}

declare i64 @millis() local_unnamed_addr #1

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 zeroext i16 @temp2humanUnits(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

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

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

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 112}
!6 = !{!"ScreenPowerStruct", !7, i64 0, !8, i64 112, !8, i64 120, !8, i64 128, !13, i64 136, !11, i64 140, !14, i64 144, !9, i64 180}
!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 136}


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