; LLVM IR from parallella/pal :: examples/base (simple_example)

; 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.p_mem_t = type { ptr, i64, ptr, i32, ptr, ptr }
%struct.p_arg_t = type { ptr, i64, i8 }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca [20 x i8], align 16
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca [4 x %struct.p_mem_t], align 16
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store ptr @.str, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store ptr @.str.1, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 1, ptr %11, align 4, !tbaa !5
  %19 = load i32, ptr %11, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = call ptr @llvm.stacksave.p0()
  store ptr %21, ptr %12, align 8
  %22 = alloca %struct.p_arg_t, i64 %20, align 16
  store i64 %20, ptr %13, align 8
  call void @llvm.lifetime.start.p0(i64 20, ptr %14) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.start.p0(i64 192, ptr %18) #6
  %23 = call ptr @p_init(i32 noundef 6, i32 noundef 0)
  store ptr %23, ptr %15, align 8, !tbaa !9
  %24 = load ptr, ptr %15, align 8, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = call ptr @p_load(ptr noundef %24, ptr noundef %25, i32 noundef 0)
  store ptr %26, ptr %16, align 8, !tbaa !9
  %27 = load ptr, ptr %15, align 8, !tbaa !9
  %28 = call i32 @p_query(ptr noundef %27, i32 noundef 1)
  store i32 %28, ptr %10, align 4, !tbaa !5
  %29 = load ptr, ptr %15, align 8, !tbaa !9
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = call ptr @p_open(ptr noundef %29, i32 noundef 0, i32 noundef %30)
  store ptr %31, ptr %17, align 8, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %55, %2
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %58

36:                                               ; preds = %32
  %37 = getelementptr inbounds [20 x i8], ptr %14, i64 0, i64 0
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %37, ptr noundef @.str.2, i32 noundef %38) #6
  %40 = getelementptr inbounds [20 x i8], ptr %14, i64 0, i64 0
  %41 = getelementptr inbounds %struct.p_arg_t, ptr %22, i64 0
  %42 = getelementptr inbounds %struct.p_arg_t, ptr %41, i32 0, i32 0
  store ptr %40, ptr %42, align 16, !tbaa !11
  %43 = getelementptr inbounds [20 x i8], ptr %14, i64 0, i64 0
  %44 = call i64 @strnlen(ptr noundef %43, i64 noundef 10) #7
  %45 = getelementptr inbounds %struct.p_arg_t, ptr %22, i64 0
  %46 = getelementptr inbounds %struct.p_arg_t, ptr %45, i32 0, i32 1
  store i64 %44, ptr %46, align 8, !tbaa !15
  %47 = getelementptr inbounds %struct.p_arg_t, ptr %22, i64 0
  %48 = getelementptr inbounds %struct.p_arg_t, ptr %47, i32 0, i32 2
  store i8 0, ptr %48, align 16, !tbaa !16
  %49 = load ptr, ptr %16, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = load ptr, ptr %17, align 8, !tbaa !9
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = load i32, ptr %11, align 4, !tbaa !5
  %54 = call i32 @p_run(ptr noundef %49, ptr noundef %50, ptr noundef %51, i32 noundef %52, i32 noundef 1, i32 noundef %53, ptr noundef %22, i32 noundef 0)
  store i32 %54, ptr %8, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %36
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %9, align 4, !tbaa !5
  br label %32, !llvm.loop !17

58:                                               ; preds = %32
  %59 = load ptr, ptr %17, align 8, !tbaa !9
  %60 = call i32 @p_wait(ptr noundef %59)
  %61 = load ptr, ptr %17, align 8, !tbaa !9
  %62 = call i32 @p_close(ptr noundef %61)
  %63 = load ptr, ptr %15, align 8, !tbaa !9
  %64 = call i32 @p_finalize(ptr noundef %63)
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 192, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 20, ptr %14) #6
  %65 = load ptr, ptr %12, align 8
  call void @llvm.stackrestore.p0(ptr %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %66 = load i32, ptr %3, align 4
  ret i32 %66
}

; 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
declare ptr @llvm.stacksave.p0() #2

declare ptr @p_init(i32 noundef, i32 noundef) #3

declare ptr @p_load(ptr noundef, ptr noundef, i32 noundef) #3

declare i32 @p_query(ptr noundef, i32 noundef) #3

declare ptr @p_open(ptr noundef, i32 noundef, i32 noundef) #3

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #4

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strnlen(ptr noundef, i64 noundef) #5

declare i32 @p_run(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #3

declare i32 @p_wait(ptr noundef) #3

declare i32 @p_close(ptr noundef) #3

declare i32 @p_finalize(ptr noundef) #3

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { "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 "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"p_arg_t", !10, i64 0, !13, i64 8, !14, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !13, i64 8}
!16 = !{!12, !14, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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"

%struct.p_arg_t = type { ptr, i64, i8 }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca [20 x i8], align 16
  %4 = alloca %struct.p_arg_t, align 16
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %3) #5
  %5 = tail call ptr @p_init(i32 noundef 6, i32 noundef 0) #5
  %6 = tail call ptr @p_load(ptr noundef %5, ptr noundef nonnull @.str, i32 noundef 0) #5
  %7 = tail call i32 @p_query(ptr noundef %5, i32 noundef 1) #5
  %8 = tail call ptr @p_open(ptr noundef %5, i32 noundef 0, i32 noundef %7) #5
  %9 = icmp sgt i32 %7, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  %11 = getelementptr inbounds i8, ptr %4, i64 16
  br label %12

12:                                               ; preds = %.lr.ph, %12
  %.019 = phi i32 [ 0, %.lr.ph ], [ %16, %12 ]
  %13 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.019) #5
  store ptr %3, ptr %4, align 16, !tbaa !5
  %14 = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) %3, i64 noundef 10) #6
  store i64 %14, ptr %10, align 8, !tbaa !12
  store i8 0, ptr %11, align 16, !tbaa !13
  %15 = call i32 @p_run(ptr noundef %6, ptr noundef nonnull @.str.1, ptr noundef %8, i32 noundef %.019, i32 noundef 1, i32 noundef 1, ptr noundef nonnull %4, i32 noundef 0) #5
  %16 = add nuw nsw i32 %.019, 1
  %exitcond.not = icmp eq i32 %16, %7
  br i1 %exitcond.not, label %._crit_edge, label %12, !llvm.loop !14

._crit_edge:                                      ; preds = %12, %2
  %17 = call i32 @p_wait(ptr noundef %8) #5
  %18 = call i32 @p_close(ptr noundef %8) #5
  %19 = call i32 @p_finalize(ptr noundef %5) #5
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %3) #5
  ret i32 0
}

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

declare ptr @p_init(i32 noundef, i32 noundef) local_unnamed_addr #2

declare ptr @p_load(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @p_query(ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @p_open(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strnlen(ptr nocapture noundef, i64 noundef) local_unnamed_addr #4

declare i32 @p_run(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @p_wait(ptr noundef) local_unnamed_addr #2

declare i32 @p_close(ptr noundef) local_unnamed_addr #2

declare i32 @p_finalize(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress 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 = { nofree nounwind "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 = { 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 #5 = { nounwind }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"p_arg_t", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !11, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass