#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strlen(char *);
char *strtok(char *, char *);
char *getkv(char *str) {
  static char buf[(128)];
  static char *p;
  if (str != NULL) {
    memset(buf, 0, sizeof(buf));
    memcpy(buf, str, strlen(str));
    p = strtok(buf, " \t");
  } else
    p = strtok(NULL, " \t");
  return p;
}


x86 assembly (clang, -O0):
<getkv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ac <getkv+0x6c>
lea    0x2ef2(%rip),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
lea    0x2ec8(%rip),%rdi
call   1050 <memcpy@plt>
lea    0x2ebc(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,0x2f29(%rip)
jmp    11c3 <getkv+0x83>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe49(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,0x2f0d(%rip)
mov    0x2f06(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getkv>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1179 <getkv+0x39>
mov    %rdi,%rbx
lea    0x2efd(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <memcpy@plt>
jmp    117c <getkv+0x3c>
xor    %r14d,%r14d
lea    0xe7d(%rip),%rsi
mov    %r14,%rdi
call   1060 <strtok@plt>
mov    %rax,0x2f3e(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@getkv.buf = internal global [128 x i8] zeroinitializer
@getkv.p = internal global i8* null
@.str = [3 x i8] c" \09\00"
define i8* @getkv(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = icmp ne i8* %3, null
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = call i32 @memset(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getkv.buf, i64 0, i64 0), i32 0, i32 128)
%7 = load i8*, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = call i32 @memcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getkv.buf, i64 0, i64 0), i8* %7, i32 %9)
%11 = call i8* @strtok(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getkv.buf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** @getkv.p
br label %14
12: ; preds = %1
%13 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** @getkv.p
br label %14
14: ; preds = %12, %5
%15 = load i8*, i8** @getkv.p
ret i8* %15
}

LLVM IR (-O2):
@getkv.buf = internal global [128 x i8] zeroinitializer
@getkv.p = internal unnamed_addr global i8* null
@.str = [3 x i8] c" \09\00"
define i8* @getkv(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = tail call i32 @memset(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getkv.buf, i64 0, i64 0), i32 0, i32 128)
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @memcpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getkv.buf, i64 0, i64 0), i8* %0, i32 %5)
br label %7
7: ; preds = %1, %3
%8 = phi i8* [ getelementptr inbounds ([128 x i8], [128 x i8]* @getkv.buf, i64 0, i64 0), %3 ], [ null, %1 ]
%9 = tail call i8* @strtok(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** @getkv.p
ret i8* %9
}