; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto (nem)

; 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.nem_transaction_ctx = type { [32 x i8], ptr, i64, i64 }

; 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
declare dso_local zeroext i1 @nem_transaction_write_common(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_u32(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @nem_transaction_create_aggregate_modification(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5, i32 noundef %6, i1 noundef zeroext %7) #1 {
  %9 = alloca i1, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i8, align 1
  %18 = alloca i8, align 1
  %19 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store i8 %1, ptr %11, align 1, !tbaa !9
  store i32 %2, ptr %12, align 4, !tbaa !10
  store ptr %3, ptr %13, align 8, !tbaa !5
  store i64 %4, ptr %14, align 8, !tbaa !12
  store i32 %5, ptr %15, align 4, !tbaa !10
  store i32 %6, ptr %16, align 4, !tbaa !10
  %20 = zext i1 %7 to i8
  store i8 %20, ptr %17, align 1, !tbaa !14
  %21 = load ptr, ptr %13, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %27, label %23

23:                                               ; preds = %8
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.nem_transaction_ctx, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [32 x i8], ptr %25, i64 0, i64 0
  store ptr %26, ptr %13, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %23, %8
  call void @llvm.lifetime.start.p0(i64 1, ptr %18) #3
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = load i8, ptr %11, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = shl i32 %30, 24
  %32 = load i8, ptr %17, align 1, !tbaa !14, !range !16, !noundef !17
  %33 = trunc i8 %32 to i1
  %34 = zext i1 %33 to i64
  %35 = select i1 %33, i32 2, i32 1
  %36 = or i32 %31, %35
  %37 = load i32, ptr %12, align 4, !tbaa !10
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = load i64, ptr %14, align 8, !tbaa !12
  %40 = load i32, ptr %15, align 4, !tbaa !10
  %41 = call zeroext i1 @nem_transaction_write_common(ptr noundef %28, i32 noundef 4097, i32 noundef %36, i32 noundef %37, ptr noundef %38, i64 noundef %39, i32 noundef %40)
  %42 = zext i1 %41 to i8
  store i8 %42, ptr %18, align 1, !tbaa !14
  %43 = load i8, ptr %18, align 1, !tbaa !14, !range !16, !noundef !17
  %44 = trunc i8 %43 to i1
  br i1 %44, label %46, label %45

45:                                               ; preds = %27
  store i1 false, ptr %9, align 1
  store i32 1, ptr %19, align 4
  br label %55

46:                                               ; preds = %27
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i32, ptr %16, align 4, !tbaa !10
  %50 = call zeroext i1 @nem_write_u32(ptr noundef %48, i32 noundef %49)
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  store i1 false, ptr %9, align 1
  store i32 1, ptr %19, align 4
  br label %55

52:                                               ; preds = %47
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  store i1 true, ptr %9, align 1
  store i32 1, ptr %19, align 4
  br label %55

55:                                               ; preds = %54, %51, %45
  call void @llvm.lifetime.end.p0(i64 1, ptr %18) #3
  %56 = load i1, ptr %9, align 1
  ret i1 %56
}

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 = { inlinehint 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}


; 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
declare dso_local zeroext i1 @nem_transaction_write_common(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_u32(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @nem_transaction_create_aggregate_modification(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5, i32 noundef %6, i1 noundef zeroext %7) local_unnamed_addr #0 {
  %.not = icmp eq ptr %3, null
  %spec.select = select i1 %.not, ptr %0, ptr %3
  %9 = zext i8 %1 to i32
  %10 = shl nuw i32 %9, 24
  %11 = select i1 %7, i32 2, i32 1
  %12 = or disjoint i32 %11, %10
  %13 = tail call zeroext i1 @nem_transaction_write_common(ptr noundef %0, i32 noundef 4097, i32 noundef %12, i32 noundef %2, ptr noundef %spec.select, i64 noundef %4, i32 noundef %5)
  br i1 %13, label %14, label %16

14:                                               ; preds = %8
  %15 = tail call zeroext i1 @nem_write_u32(ptr noundef %0, i32 noundef %6)
  br label %16

16:                                               ; preds = %14, %8
  %.0 = phi i1 [ false, %8 ], [ %15, %14 ]
  ret i1 %.0
}

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 = { inlinehint 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" }

!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)"}


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