#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 ENOMEM;
int /*<<< orphan*/ free(char *);
char *strchr(char *, char);
char *strdup(char *);
int parse_key_value(char *str, char **key, char **val) {
  char *eq = strchr(str, '=');
  if (eq) {
    *eq = '\0';
    *val = strdup(eq + 1);
  } else {
    *val = strdup("true");
  }
  if (!*val) {
    return ENOMEM;
  }
  *key = strdup(str);
  if (!*key) {
    free(*val);
    return ENOMEM;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_key_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1184 <parse_key_value+0x54>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    119a <parse_key_value+0x6a>
lea    0xe75(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b9 <parse_key_value+0x89>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fe <parse_key_value+0xce>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11f7 <parse_key_value+0xc7>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fe <parse_key_value+0xce>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_key_value>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x3d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1159 <parse_key_value+0x29>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
jmp    1160 <parse_key_value+0x30>
lea    0xea0(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     118a <parse_key_value+0x5a>
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    %rax,(%r14)
xor    %eax,%eax
test   %rcx,%rcx
jne    1193 <parse_key_value+0x63>
mov    (%r15),%rdi
call   1030 <free@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"true\00"
@ENOMEM = global i32 0
define i32 @parse_key_value(i8* %0, i8** nocapture writeonly %1, i8** nocapture %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 61)
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
store i8 0, i8* %4
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = tail call i8* @strdup(i8* %7)
br label %11
9: ; preds = %3
%10 = tail call dereferenceable_or_null(5) i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = phi i8* [ %10, %9 ], [ %8, %6 ]
store i8* %12, i8** %2
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = load i32, i32* @ENOMEM
br label %23
16: ; preds = %11
%17 = tail call i8* @strdup(i8* %0)
store i8* %17, i8** %1
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = tail call i32 @free(i8* %20)
%22 = load i32, i32* @ENOMEM
br label %23
23: ; preds = %16, %19, %14
%24 = phi i32 [ %22, %19 ], [ %15, %14 ], [ 0, %16 ]
ret i32 %24
}