; 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 willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; 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) #2

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_u64(ptr noundef, i64 noundef) #3

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

29:                                               ; preds = %10
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.nem_transaction_ctx, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [32 x i8], ptr %31, i64 0, i64 0
  store ptr %32, ptr %15, align 8, !tbaa !5
  br label %33

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

47:                                               ; preds = %33
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %104

48:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #4
  %49 = load ptr, ptr %18, align 8, !tbaa !5
  %50 = call i64 @strlen(ptr noundef %49) #5
  store i64 %50, ptr %24, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #4
  %51 = load ptr, ptr %19, align 8, !tbaa !5
  %52 = call i64 @strlen(ptr noundef %51) #5
  store i64 %52, ptr %25, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #4
  %53 = load i64, ptr %24, align 8, !tbaa !12
  %54 = add i64 4, %53
  %55 = add i64 %54, 4
  %56 = load i64, ptr %25, align 8, !tbaa !12
  %57 = add i64 %55, %56
  store i64 %57, ptr %26, align 8, !tbaa !12
  br label %58

58:                                               ; preds = %48
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = load i64, ptr %26, align 8, !tbaa !12
  %61 = trunc i64 %60 to i32
  %62 = call zeroext i1 @nem_write_u32(ptr noundef %59, i32 noundef %61)
  br i1 %62, label %64, label %63

63:                                               ; preds = %58
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %103

64:                                               ; preds = %58
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = load ptr, ptr %18, align 8, !tbaa !5
  %70 = load i64, ptr %24, align 8, !tbaa !12
  %71 = trunc i64 %70 to i32
  %72 = call zeroext i1 @nem_write_tagged(ptr noundef %68, ptr noundef %69, i32 noundef %71)
  br i1 %72, label %74, label %73

73:                                               ; preds = %67
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %103

74:                                               ; preds = %67
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = load ptr, ptr %19, align 8, !tbaa !5
  %80 = load i64, ptr %25, align 8, !tbaa !12
  %81 = trunc i64 %80 to i32
  %82 = call zeroext i1 @nem_write_tagged(ptr noundef %78, ptr noundef %79, i32 noundef %81)
  br i1 %82, label %84, label %83

83:                                               ; preds = %77
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %103

84:                                               ; preds = %77
  br label %85

85:                                               ; preds = %84
  br label %86

86:                                               ; preds = %85
  br label %87

87:                                               ; preds = %86
  %88 = load ptr, ptr %12, align 8, !tbaa !5
  %89 = load i32, ptr %20, align 4, !tbaa !10
  %90 = call zeroext i1 @nem_write_u32(ptr noundef %88, i32 noundef %89)
  br i1 %90, label %92, label %91

91:                                               ; preds = %87
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %103

92:                                               ; preds = %87
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = load i64, ptr %21, align 8, !tbaa !12
  %98 = call zeroext i1 @nem_write_u64(ptr noundef %96, i64 noundef %97)
  br i1 %98, label %100, label %99

99:                                               ; preds = %95
  store i1 false, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %103

100:                                              ; preds = %95
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101
  store i1 true, ptr %11, align 1
  store i32 1, ptr %23, align 4
  br label %103

103:                                              ; preds = %102, %99, %91, %83, %73, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #4
  br label %104

104:                                              ; preds = %103, %47
  call void @llvm.lifetime.end.p0(i64 1, ptr %22) #4
  %105 = load i1, ptr %11, align 1
  ret i1 %105
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 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 = { 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #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) local_unnamed_addr #1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @nem_write_u64(ptr noundef, i64 noundef) local_unnamed_addr #2

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

15:                                               ; preds = %10
  %16 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %6) #3
  %17 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %7) #3
  %18 = add i64 %16, 8
  %19 = add i64 %18, %17
  %20 = trunc i64 %19 to i32
  %21 = tail call zeroext i1 @nem_write_u32(ptr noundef %0, i32 noundef %20)
  br i1 %21, label %22, label %32

22:                                               ; preds = %15
  %23 = trunc i64 %16 to i32
  %24 = tail call zeroext i1 @nem_write_tagged(ptr noundef %0, ptr noundef %6, i32 noundef %23)
  br i1 %24, label %25, label %32

25:                                               ; preds = %22
  %26 = trunc i64 %17 to i32
  %27 = tail call zeroext i1 @nem_write_tagged(ptr noundef %0, ptr noundef %7, i32 noundef %26)
  br i1 %27, label %28, label %32

28:                                               ; preds = %25
  %29 = tail call zeroext i1 @nem_write_u32(ptr noundef %0, i32 noundef %8)
  br i1 %29, label %30, label %32

30:                                               ; preds = %28
  %31 = tail call zeroext i1 @nem_write_u64(ptr noundef %0, i64 noundef %9)
  br label %32

32:                                               ; preds = %15, %22, %25, %28, %30, %10
  %.1 = phi i1 [ false, %10 ], [ false, %15 ], [ false, %22 ], [ false, %25 ], [ false, %28 ], [ %31, %30 ]
  ret i1 %.1
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 willreturn memory(read) }

!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