int iscsiAuthClientStringCopy(char *stringOut, const char *stringIn,
                              unsigned int length) {
  if (!stringOut || !stringIn || length == 0) {
    return 1;
  }
  while ((*stringOut++ = *stringIn++) != '\0') {
    if (--length == 0) {
      stringOut--;
      *stringOut = '\0';
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<iscsiAuthClientStringCopy>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     112f <iscsiAuthClientStringCopy+0x2f>
cmpq   $0x0,-0x18(%rbp)
je     112f <iscsiAuthClientStringCopy+0x2f>
cmpl   $0x0,-0x1c(%rbp)
jne    113b <iscsiAuthClientStringCopy+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    11ab <iscsiAuthClientStringCopy+0xab>
jmp    1140 <iscsiAuthClientStringCopy+0x40>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
je     11a4 <iscsiAuthClientStringCopy+0xa4>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    119f <iscsiAuthClientStringCopy+0x9f>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11ab <iscsiAuthClientStringCopy+0xab>
jmp    1140 <iscsiAuthClientStringCopy+0x40>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<iscsiAuthClientStringCopy>:
mov    $0x1,%eax
test   %rdi,%rdi
je     1139 <iscsiAuthClientStringCopy+0x39>
test   %rsi,%rsi
je     1139 <iscsiAuthClientStringCopy+0x39>
test   %edx,%edx
je     1139 <iscsiAuthClientStringCopy+0x39>
mov    %edx,%r8d
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movzbl (%rsi,%rdx,1),%ecx
mov    %cl,(%rdi,%rdx,1)
test   %cl,%cl
je     113a <iscsiAuthClientStringCopy+0x3a>
add    $0x1,%rdx
cmp    %edx,%r8d
jne    1120 <iscsiAuthClientStringCopy+0x20>
movb   $0x0,-0x1(%rdi,%rdx,1)
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @iscsiAuthClientStringCopy(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13, %10, %3
store i32 1, i32* %4
br label %36
17: ; preds = %13
br label %18
18: ; preds = %34, %17
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %6
%21 = load i8, i8* %19
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
store i8 %21, i8* %22
%24 = sext i8 %21 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %18
%27 = load i32, i32* %7
%28 = add i32 %27, -1
store i32 %28, i32* %7
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %5
%33 = load i8*, i8** %5
store i8 0, i8* %33
store i32 1, i32* %4
br label %36
34: ; preds = %26
br label %18
35: ; preds = %18
store i32 0, i32* %4
br label %36
36: ; preds = %35, %30, %16
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @iscsiAuthClientStringCopy(i8* writeonly %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i32 %2, 0
%8 = or i1 %6, %7
br i1 %8, label %21, label %9
9: ; preds = %3, %15
%10 = phi i8* [ %16, %15 ], [ %0, %3 ]
%11 = phi i8* [ %17, %15 ], [ %1, %3 ]
%12 = phi i32 [ %18, %15 ], [ %2, %3 ]
%13 = load i8, i8* %11
store i8 %13, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = getelementptr inbounds i8, i8* %10, i64 1
%17 = getelementptr inbounds i8, i8* %11, i64 1
%18 = add i32 %12, -1
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %9
20: ; preds = %15
store i8 0, i8* %10
br label %21
21: ; preds = %9, %3, %20
%22 = phi i32 [ 1, %20 ], [ 1, %3 ], [ 0, %9 ]
ret i32 %22
}