int msg_hdr_name_parse(char *dest, char *src) {
  if (!src || !dest) {
    printf("%s, Src is NULL\n", __FUNCTION__);
    return -1;
  }
  while (*src != '\0' && *src != ' ') {
    *dest++ = *src++;
  }
  if (*src == '\0') {
    printf("%s, header(%s) is error\n", __FUNCTION__, src);
    return -1;
  }
  *dest = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<msg_hdr_name_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1136 <msg_hdr_name_parse+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    1157 <msg_hdr_name_parse+0x47>
lea    0xec3(%rip),%rdi
lea    0xecd(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <msg_hdr_name_parse+0xeb>
jmp    115c <msg_hdr_name_parse+0x4c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1181 <msg_hdr_name_parse+0x71>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1191 <msg_hdr_name_parse+0x81>
jmp    11b8 <msg_hdr_name_parse+0xa8>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    115c <msg_hdr_name_parse+0x4c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ed <msg_hdr_name_parse+0xdd>
mov    -0x18(%rbp),%rdx
lea    0xe51(%rip),%rdi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <msg_hdr_name_parse+0xeb>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msg_hdr_name_parse>:
push   %rax
test   %rdi,%rdi
je     1137 <msg_hdr_name_parse+0x27>
mov    %rsi,%rdx
test   %rsi,%rsi
je     1137 <msg_hdr_name_parse+0x27>
xchg   %ax,%ax
movzbl (%rdx),%eax
test   %al,%al
je     114e <msg_hdr_name_parse+0x3e>
cmp    $0x20,%al
je     116a <msg_hdr_name_parse+0x5a>
add    $0x1,%rdx
mov    %al,(%rdi)
add    $0x1,%rdi
jmp    1120 <msg_hdr_name_parse+0x10>
lea    0xec2(%rip),%rdi
lea    0xecc(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1163 <msg_hdr_name_parse+0x53>
lea    0xecf(%rip),%rdi
lea    0xeb5(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
movb   $0x0,(%rdi)
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"%s, Src is NULL\0A\00"
@__FUNCTION__.msg_hdr_name_parse = [19 x i8] c"msg_hdr_name_parse\00"
@.str.1 = [25 x i8] c"%s, header(%s) is error\0A\00"
define i32 @msg_hdr_name_parse(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8, %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @__FUNCTION__.msg_hdr_name_parse, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
13: ; preds = %8
br label %14
14: ; preds = %26, %13
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 32
br label %24
24: ; preds = %19, %14
%25 = phi i1 [ false, %14 ], [ %23, %19 ]
br i1 %25, label %26, label %32
26: ; preds = %24
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
%29 = load i8, i8* %27
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
store i8 %29, i8* %30
br label %14
32: ; preds = %24
%33 = load i8*, i8** %5
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i8*, i8** %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @__FUNCTION__.msg_hdr_name_parse, i64 0, i64 0), i8* %38)
store i32 -1, i32* %3
br label %42
40: ; preds = %32
%41 = load i8*, i8** %4
store i8 0, i8* %41
store i32 0, i32* %3
br label %42
42: ; preds = %40, %37, %11
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [17 x i8] c"%s, Src is NULL\0A\00"
@__FUNCTION__.msg_hdr_name_parse = [19 x i8] c"msg_hdr_name_parse\00"
@.str.1 = [25 x i8] c"%s, header(%s) is error\0A\00"
define i32 @msg_hdr_name_parse(i8* writeonly %0, i8* %1) {
%3 = icmp ne i8* %1, null
%4 = icmp ne i8* %0, null
%5 = and i1 %4, %3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @__FUNCTION__.msg_hdr_name_parse, i64 0, i64 0))
br label %18
8: ; preds = %2, %12
%9 = phi i8* [ %14, %12 ], [ %0, %2 ]
%10 = phi i8* [ %13, %12 ], [ %1, %2 ]
%11 = load i8, i8* %10
switch i8 %11, label %12 [
i8 0, label %15
i8 32, label %17
]
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %11, i8* %9
br label %8
15: ; preds = %8
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @__FUNCTION__.msg_hdr_name_parse, i64 0, i64 0), i8* %10)
br label %18
17: ; preds = %8
store i8 0, i8* %9
br label %18
18: ; preds = %17, %15, %6
%19 = phi i32 [ -1, %15 ], [ 0, %17 ], [ -1, %6 ]
ret i32 %19
}