#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 *strstr(char *, char *);
int parse_buffer(char *buf, char **val) {
  char *ptr;
  *val = NULL;
  if (buf[0] == '#') {
    return 0;
  }
  ptr = buf;
  while (*ptr != '\n') {
    ptr++;
  }
  if (ptr == buf) {
    return 0;
  }
  *ptr = '\0';
  ptr = strstr(buf, "=");
  if (ptr == NULL) {
    return -1;
  }
  *ptr = '\0';
  do {
    ptr++;
  } while (*ptr == ' ');
  *val = ptr;
  return 1;
}


x86 assembly (clang, -O0):
<parse_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1147 <parse_buffer+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <parse_buffer+0xe1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1170 <parse_buffer+0x60>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114f <parse_buffer+0x3f>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    118a <parse_buffer+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    11f1 <parse_buffer+0xe1>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bc <parse_buffer+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <parse_buffer+0xe1>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     11c3 <parse_buffer+0xb3>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_buffer>:
push   %rbx
movq   $0x0,(%rsi)
mov    (%rdi),%cl
xor    %eax,%eax
cmp    $0xa,%cl
je     1172 <parse_buffer+0x62>
cmp    $0x23,%cl
je     1172 <parse_buffer+0x62>
mov    %rsi,%rbx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
cmpb   $0xa,0x1(%rdi,%rax,1)
lea    0x1(%rax),%rax
jne    1130 <parse_buffer+0x20>
test   %rax,%rax
je     1174 <parse_buffer+0x64>
movb   $0x0,(%rdi,%rax,1)
mov    $0x3d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1178 <parse_buffer+0x68>
movb   $0x0,(%rax)
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x20,0x1(%rax)
lea    0x1(%rax),%rax
je     1160 <parse_buffer+0x50>
mov    %rax,(%rbx)
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

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

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