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

; 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.IronStruct = type { %struct.HistoryStruct, i32, i8, i8, i32, i8, i8, i8, i32, [2 x i32], i8, i32, i32, i16, i16, i8, i16, i8, i8, i8, i16, i32, i32, i8, i32, i32, i32 }
%struct.HistoryStruct = type { i8, [8 x i32] }

; 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 zeroext i8 @getPower(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.IronStruct, ptr %4, i32 0, i32 4
  %6 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %6, ptr %3, align 4, !tbaa !15
  %7 = load i32, ptr %3, align 4, !tbaa !15
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !15
  br label %10

10:                                               ; preds = %9, %1
  %11 = load i32, ptr %3, align 4, !tbaa !15
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.IronStruct, ptr %12, i32 0, i32 17
  %14 = load i8, ptr %13, align 4, !tbaa !16
  %15 = zext i8 %14 to i32
  %16 = icmp sgt i32 %11, %15
  br i1 %16, label %17, label %22

17:                                               ; preds = %10
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.IronStruct, ptr %18, i32 0, i32 17
  %20 = load i8, ptr %19, align 4, !tbaa !16
  %21 = zext i8 %20 to i32
  store i32 %21, ptr %3, align 4, !tbaa !15
  br label %22

22:                                               ; preds = %17, %10
  %23 = load i32, ptr %3, align 4, !tbaa !15
  %24 = and i32 %23, 255
  %25 = trunc i32 %24 to i8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i8 %25
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 44}
!10 = !{!"IronStruct", !11, i64 0, !12, i64 36, !7, i64 40, !7, i64 41, !12, i64 44, !13, i64 48, !13, i64 49, !13, i64 50, !12, i64 52, !7, i64 56, !13, i64 64, !12, i64 68, !12, i64 72, !14, i64 76, !14, i64 78, !13, i64 80, !14, i64 82, !7, i64 84, !7, i64 85, !7, i64 86, !14, i64 88, !12, i64 92, !12, i64 96, !7, i64 100, !12, i64 104, !12, i64 108, !12, i64 112}
!11 = !{!"HistoryStruct", !7, i64 0, !7, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !7, i64 84}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local zeroext i8 @getPower(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 44
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %3, i32 0)
  %4 = getelementptr inbounds i8, ptr %0, i64 84
  %5 = load i8, ptr %4, align 4, !tbaa !13
  %6 = zext i8 %5 to i32
  %7 = icmp sgt i32 %3, %6
  %spec.select = select i1 %7, i32 %6, i32 %spec.store.select
  %8 = trunc i32 %spec.select to i8
  ret i8 %8
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !10, i64 44}
!6 = !{!"IronStruct", !7, i64 0, !10, i64 36, !8, i64 40, !8, i64 41, !10, i64 44, !11, i64 48, !11, i64 49, !11, i64 50, !10, i64 52, !8, i64 56, !11, i64 64, !10, i64 68, !10, i64 72, !12, i64 76, !12, i64 78, !11, i64 80, !12, i64 82, !8, i64 84, !8, i64 85, !8, i64 86, !12, i64 88, !10, i64 92, !10, i64 96, !8, i64 100, !10, i64 104, !10, i64 108, !10, i64 112}
!7 = !{!"HistoryStruct", !8, i64 0, !8, i64 4}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !8, i64 84}


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