#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*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
scalar_t__ strlen(char *);
char *strtok_r(char *, char const *, char **);
int get_key_value(char *str, char **key, char **value) {
  char *lstr = strdup(str);
  const char s[2] = "=";
  char *lkey;
  char *lvalue;
  lkey = strtok_r(lstr, s, &lvalue);
  *key = (char *)malloc(strlen(lkey) + 1);
  *value = (char *)malloc(strlen(lvalue) + 1);
  strcpy(*key, lkey);
  strcpy(*value, lvalue);
  free(lstr);
  return (0);
}


x86 assembly (clang, -O0):
<get_key_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    0xe78(%rip),%ax
mov    %ax,-0x22(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x22(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_key_value>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r12
call   1080 <strdup@plt>
mov    %rax,%r14
movw   $0x3d,0xe(%rsp)
lea    0xe(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
call   1060 <strtok_r@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,(%r12)
mov    0x10(%rsp),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,(%r15)
mov    (%r12),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    (%r15),%rdi
mov    0x10(%rsp),%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.get_key_value.s = [2 x i8] c"=\00"
define i32 @get_key_value(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca [2 x i8]
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%11 = load i8*, i8** %4
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %7
%13 = bitcast [2 x i8]* %8 to i8*
%14 = load i8*, i8** %7
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%16 = call i8* @strtok_r(i8* %14, i8* %15, i8** %10)
store i8* %16, i8** %9
%17 = load i8*, i8** %9
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = call i64 @malloc(i64 %19)
%21 = inttoptr i64 %20 to i8*
%22 = load i8**, i8*** %5
store i8* %21, i8** %22
%23 = load i8*, i8** %10
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %24, 1
%26 = call i64 @malloc(i64 %25)
%27 = inttoptr i64 %26 to i8*
%28 = load i8**, i8*** %6
store i8* %27, i8** %28
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = load i8*, i8** %9
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8**, i8*** %6
%34 = load i8*, i8** %33
%35 = load i8*, i8** %10
%36 = call i32 @strcpy(i8* %34, i8* %35)
%37 = load i8*, i8** %7
%38 = call i32 @free(i8* %37)
ret i32 0
}

LLVM IR (-O2):
define i32 @get_key_value(i8* nocapture %0, i8** nocapture %1, i8** nocapture %2) {
%4 = alloca i16
%5 = alloca i8*
%6 = tail call i8* @strdup(i8* %0)
%7 = bitcast i16* %4 to i8*
store i16 61, i16* %4
%8 = bitcast i8** %5 to i8*
%9 = call i8* @strtok_r(i8* %6, i8* %7, i8** %5)
%10 = call i64 @strlen(i8* dereferenceable(1) %9)
%11 = add nsw i64 %10, 1
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %1
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* dereferenceable(1) %14)
%16 = add nsw i64 %15, 1
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %2
%19 = load i8*, i8** %1
%20 = call i32 @strcpy(i8* %19, i8* %9)
%21 = load i8*, i8** %2
%22 = load i8*, i8** %5
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = call i32 @free(i8* %6)
ret i32 0
}