#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 */
char *get_char_pointer(char *, char);
int /*<<< orphan*/ printf(char *, char *, ...);
char *skip_blank(char *);
int parse_line(char *buf, char **key, char **value) {
  char *first_non_blank = buf;
  char *char_equal;
  char *char_end;
  printf("line: %s\n", buf);
  first_non_blank = skip_blank(buf);
  if (!first_non_blank)
    goto end;
  if (*first_non_blank == '\n')
    return -1;
  char_equal = first_non_blank + 1;
  char_equal = get_char_pointer(char_equal, '=');
  if (!char_equal)
    goto end;
  *char_equal = '\0';
  char_end = get_char_pointer(char_equal + 1, '\n');
  if (!char_end)
    *char_end = '\0';
  *key = first_non_blank;
  *value = char_equal + 1;
  printf("key:%s, value:%s\n", first_non_blank, char_equal + 1);
  return 0;
end:
  return -1;
}


x86 assembly (clang, -O0):
<parse_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <skip_blank@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117b <parse_line+0x4b>
jmp    1234 <parse_line+0x104>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1197 <parse_line+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <parse_line+0x10b>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <get_char_pointer@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c5 <parse_line+0x95>
jmp    1234 <parse_line+0x104>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    $0xa,%esi
call   1050 <get_char_pointer@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11f4 <parse_line+0xc4>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
add    $0x1,%rdx
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123b <parse_line+0x10b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeb8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <skip_blank@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
je     11b7 <parse_line+0x87>
mov    %rax,%rbx
cmpb   $0xa,(%rax)
je     11b7 <parse_line+0x87>
mov    %rbx,%rdi
add    $0x1,%rdi
mov    $0x3d,%esi
call   1050 <get_char_pointer@plt>
test   %rax,%rax
je     11b7 <parse_line+0x87>
mov    %rax,%rbp
movb   $0x0,(%rax)
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
call   1050 <get_char_pointer@plt>
mov    %rbx,(%r15)
mov    %rbp,(%r14)
lea    0xe63(%rip),%rdi
xor    %r12d,%r12d
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"line: %s\0A\00"
@.str.1 = [18 x i8] c"key:%s, value:%s\0A\00"
define i32 @parse_line(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = load i8*, i8** %5
store i8* %11, i8** %8
%12 = load i8*, i8** %5
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %5
%15 = call i8* @skip_blank(i8* %14)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %3
br label %52
19: ; preds = %3
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -1, i32* %4
br label %53
25: ; preds = %19
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = call i8* @get_char_pointer(i8* %28, i8 signext 61)
store i8* %29, i8** %9
%30 = load i8*, i8** %9
%31 = icmp ne i8* %30, null
br i1 %31, label %33, label %32
32: ; preds = %25
br label %52
33: ; preds = %25
%34 = load i8*, i8** %9
store i8 0, i8* %34
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = call i8* @get_char_pointer(i8* %36, i8 signext 10)
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = icmp ne i8* %38, null
br i1 %39, label %42, label %40
40: ; preds = %33
%41 = load i8*, i8** %10
store i8 0, i8* %41
br label %42
42: ; preds = %40, %33
%43 = load i8*, i8** %8
%44 = load i8**, i8*** %6
store i8* %43, i8** %44
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8**, i8*** %7
store i8* %46, i8** %47
%48 = load i8*, i8** %8
%49 = load i8*, i8** %9
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %48, i8* %50)
store i32 0, i32* %4
br label %53
52: ; preds = %32, %18
store i32 -1, i32* %4
br label %53
53: ; preds = %52, %42, %24
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@.str = [10 x i8] c"line: %s\0A\00"
@.str.1 = [18 x i8] c"key:%s, value:%s\0A\00"
define i32 @parse_line(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i8* @skip_blank(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %19, label %7
7: ; preds = %3
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 10
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = tail call i8* @get_char_pointer(i8* %11, i8 signext 61)
%13 = icmp eq i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %10
store i8 0, i8* %12
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = tail call i8* @get_char_pointer(i8* %15, i8 signext 10)
%17 = icmp ne i8* %16, null
tail call void @llvm.assume(i1 %17)
store i8* %5, i8** %1
store i8* %15, i8** %2
%18 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %15)
br label %19
19: ; preds = %3, %10, %7, %14
%20 = phi i32 [ 0, %14 ], [ -1, %7 ], [ -1, %10 ], [ -1, %3 ]
ret i32 %20
}