Skip to content

Instantly share code, notes, and snippets.

@zhuguoliang
Last active November 24, 2022 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhuguoliang/69c1bd7661728f5f06f3938c81ae5434 to your computer and use it in GitHub Desktop.
Save zhuguoliang/69c1bd7661728f5f06f3938c81ae5434 to your computer and use it in GitHub Desktop.
strlcpy.ll
target datalayout = "e-m:m-p:32:32-i8:8:32-i16:16:32-n32-S32"
target triple = "xxx-unknown-unknown"
; Function Attrs: noinline nounwind optnone
define dso_local i32 @strlcpy(i8* noundef %dst, i8* noundef %src, i32 noundef %dsize) #0 {
entry:
%dst.addr = alloca i8*, align 4
%src.addr = alloca i8*, align 4
%dsize.addr = alloca i32, align 4
%osrc = alloca i8*, align 4
%nleft = alloca i32, align 4
store i8* %dst, i8** %dst.addr, align 4
store i8* %src, i8** %src.addr, align 4
store i32 %dsize, i32* %dsize.addr, align 4
%0 = load i8*, i8** %src.addr, align 4
store i8* %0, i8** %osrc, align 4
%1 = load i32, i32* %dsize.addr, align 4
store i32 %1, i32* %nleft, align 4
%2 = load i32, i32* %nleft, align 4
%cmp = icmp ne i32 %2, 0
br i1 %cmp, label %if.then, label %if.end6
if.then: ; preds = %entry
br label %while.cond
while.cond: ; preds = %if.end, %if.then
%3 = load i32, i32* %nleft, align 4
%dec = add i32 %3, -1
store i32 %dec, i32* %nleft, align 4
%cmp1 = icmp ne i32 %dec, 0
br i1 %cmp1, label %while.body, label %while.end
while.body: ; preds = %while.cond
%4 = load i8*, i8** %src.addr, align 4
%incdec.ptr = getelementptr inbounds i8, i8* %4, i32 1
store i8* %incdec.ptr, i8** %src.addr, align 4
%5 = load i8, i8* %4, align 1
%6 = load i8*, i8** %dst.addr, align 4
%incdec.ptr2 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %incdec.ptr2, i8** %dst.addr, align 4
store i8 %5, i8* %6, align 1
%conv = sext i8 %5 to i32
%cmp3 = icmp eq i32 %conv, 0
br i1 %cmp3, label %if.then5, label %if.end
if.then5: ; preds = %while.body
br label %while.end
if.end: ; preds = %while.body
br label %while.cond, !llvm.loop !2
while.end: ; preds = %if.then5, %while.cond
br label %if.end6
if.end6: ; preds = %while.end, %entry
%7 = load i32, i32* %nleft, align 4
%cmp7 = icmp eq i32 %7, 0
br i1 %cmp7, label %if.then9, label %if.end18
if.then9: ; preds = %if.end6
%8 = load i32, i32* %dsize.addr, align 4
%cmp10 = icmp ne i32 %8, 0
br i1 %cmp10, label %if.then12, label %if.end13
if.then12: ; preds = %if.then9
%9 = load i8*, i8** %dst.addr, align 4
store i8 0, i8* %9, align 1
br label %if.end13
if.end13: ; preds = %if.then12, %if.then9
br label %while.cond14
while.cond14: ; preds = %while.body16, %if.end13
%10 = load i8*, i8** %src.addr, align 4
%incdec.ptr15 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %incdec.ptr15, i8** %src.addr, align 4
%11 = load i8, i8* %10, align 1
%tobool = icmp ne i8 %11, 0
br i1 %tobool, label %while.body16, label %while.end17
while.body16: ; preds = %while.cond14
br label %while.cond14, !llvm.loop !4
while.end17: ; preds = %while.cond14
br label %if.end18
if.end18: ; preds = %while.end17, %if.end6
%12 = load i8*, i8** %src.addr, align 4
%13 = load i8*, i8** %osrc, align 4
%sub.ptr.lhs.cast = ptrtoint i8* %12 to i32
%sub.ptr.rhs.cast = ptrtoint i8* %13 to i32
%sub.ptr.sub = sub i32 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
%sub = sub nsw i32 %sub.ptr.sub, 1
ret i32 %sub
}
attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="-long-calls" }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 15.0.0 ( dd1b06a7c075ab0c0919aeb5383804d427e66182)"}
!2 = distinct !{!2, !3}
!3 = !{!"llvm.loop.mustprogress"}
!4 = distinct !{!4, !3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment