#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 *strchr(char *, char);
size_t strlen(char *);
char *trim(char *);
int fconf_readkv(char *line, char **key, char **value) {
  *key = NULL;
  *value = NULL;
  size_t lenofline = strlen(line);
  if (lenofline == 0) {
    return -1;
  }
  char *loc = strchr(line, '=');
  if (!loc) {
    return -2;
  }
  *key = line;
  *value = loc + 1;
  *loc = '\0';
  *key = trim(*key);
  *value = trim(*value);
  if (strchr(*key, ' ')) {
    return -3;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fconf_readkv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117e <fconf_readkv+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <fconf_readkv+0xf2>
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a7 <fconf_readkv+0x77>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1222 <fconf_readkv+0xf2>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <trim@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <trim@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     121b <fconf_readkv+0xeb>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1222 <fconf_readkv+0xf2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fconf_readkv>:
push   %r15
push   %r14
push   %rbx
movq   $0x0,(%rsi)
movq   $0x0,(%rdx)
cmpb   $0x0,(%rdi)
je     1193 <fconf_readkv+0x73>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x3d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     119a <fconf_readkv+0x7a>
mov    %rbx,(%r15)
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,(%r14)
movb   $0x0,(%rax)
mov    (%r15),%rdi
call   1040 <trim@plt>
mov    %rax,(%r15)
mov    (%r14),%rdi
call   1040 <trim@plt>
mov    %rax,(%r14)
mov    (%r15),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,2),%eax
add    $0xfffffffd,%eax
jmp    119f <fconf_readkv+0x7f>
mov    $0xffffffff,%eax
jmp    119f <fconf_readkv+0x7f>
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @fconf_readkv(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = load i8**, i8*** %6
store i8* null, i8** %10
%11 = load i8**, i8*** %7
store i8* null, i8** %11
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %8
%14 = load i64, i64* %8
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %44
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = call i8* @strchr(i8* %18, i8 signext 61)
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %17
store i32 -2, i32* %4
br label %44
23: ; preds = %17
%24 = load i8*, i8** %5
%25 = load i8**, i8*** %6
store i8* %24, i8** %25
%26 = load i8*, i8** %9
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8**, i8*** %7
store i8* %27, i8** %28
%29 = load i8*, i8** %9
store i8 0, i8* %29
%30 = load i8**, i8*** %6
%31 = load i8*, i8** %30
%32 = call i8* @trim(i8* %31)
%33 = load i8**, i8*** %6
store i8* %32, i8** %33
%34 = load i8**, i8*** %7
%35 = load i8*, i8** %34
%36 = call i8* @trim(i8* %35)
%37 = load i8**, i8*** %7
store i8* %36, i8** %37
%38 = load i8**, i8*** %6
%39 = load i8*, i8** %38
%40 = call i8* @strchr(i8* %39, i8 signext 32)
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %43
42: ; preds = %23
store i32 -3, i32* %4
br label %44
43: ; preds = %23
store i32 0, i32* %4
br label %44
44: ; preds = %43, %42, %22, %16
%45 = load i32, i32* %4
ret i32 %45
}

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