#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
int sep_buf(char *buf, char *key, char *val) {
  char *p = strchr(buf, ' ');
  if (NULL != p) {
    *p++ = '\0';
    char *q = strstr(p, "\r\n");
    if (NULL != q)
      *q = '\0';
  } else {
    p = strstr(buf, "\r\n");
    if (NULL != p)
      *p = '\0';
  }
  strcpy(key, buf);
  strcpy(val, p);
  printf("key = %s,val = %s\n", key, val);
  return 0;
}


x86 assembly (clang, -O0):
<sep_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
je     11b0 <sep_buf+0x70>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
je     11ab <sep_buf+0x6b>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    11dc <sep_buf+0x9c>
mov    -0x8(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
je     11d7 <sep_buf+0x97>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    11dc <sep_buf+0x9c>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdfe(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sep_buf>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1180 <sep_buf+0x40>
mov    %rax,%rbx
add    $0x1,%rbx
movb   $0x0,(%rax)
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
jne    1197 <sep_buf+0x57>
jmp    119a <sep_buf+0x5a>
lea    0xe79(%rip),%rsi
mov    %r12,%rdi
call   1060 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d0 <sep_buf+0x90>
movb   $0x0,(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe4c(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
jmp    119a <sep_buf+0x5a>

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [19 x i8] c"key = %s,val = %s\0A\00"
define i32 @sep_buf(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i8* @strchr(i8* %9, i8 signext 32)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* null, %11
br i1 %12, label %13, label %23
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %7
store i8 0, i8* %14
%16 = load i8*, i8** %7
%17 = call i8* @strstr(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = icmp ne i8* null, %18
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = load i8*, i8** %8
store i8 0, i8* %21
br label %22
22: ; preds = %20, %13
br label %31
23: ; preds = %3
%24 = load i8*, i8** %4
%25 = call i8* @strstr(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp ne i8* null, %26
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = load i8*, i8** %7
store i8 0, i8* %29
br label %30
30: ; preds = %28, %23
br label %31
31: ; preds = %30, %22
%32 = load i8*, i8** %5
%33 = load i8*, i8** %4
%34 = call i32 @strcpy(i8* %32, i8* %33)
%35 = load i8*, i8** %6
%36 = load i8*, i8** %7
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = load i8*, i8** %5
%39 = load i8*, i8** %6
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [19 x i8] c"key = %s,val = %s\0A\00"
define i32 @sep_buf(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
store i8 0, i8* %4
%8 = tail call i8* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %16, label %13
10: ; preds = %3
%11 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10, %6
%14 = phi i8* [ %8, %6 ], [ %11, %10 ]
%15 = phi i8* [ %7, %6 ], [ %11, %10 ]
store i8 0, i8* %14
br label %16
16: ; preds = %13, %6, %10
%17 = phi i8* [ null, %10 ], [ %7, %6 ], [ %15, %13 ]
%18 = tail call i32 @strcpy(i8* %1, i8* %0)
%19 = tail call i32 @strcpy(i8* %2, i8* %17)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
ret i32 0
}