#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*/ fprintf(int /*<<< orphan*/, char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
int parse_key_value(char *key, int *value) {
  char *tok;
  char k[2 * 30];
  int sofar = 0;
  int ret = 0;
  tok = strtok(NULL, ",");
  if (tok == NULL) {
    fprintf(stderr, "No key supplied!\n");
    return 0;
  }
  strncpy(k, tok, 30 + 1);
  tok = strtok(NULL, ",");
  if (tok == NULL || sscanf(tok, "%d", value) != 1) {
    ret = 0;
  } else {
    ret = 1;
  }
  tok = strtok(k, " \t\n");
  if (tok == NULL) {
    fprintf(stderr, "No key supplied!\n");
    return 0;
  }
  do {
    if (sofar != 0) {
      key[sofar] = ' ';
      sofar++;
    }
    strncpy(key + sofar, tok, 30 + 1);
    sofar += strlen(tok);
  } while ((tok = strtok(NULL, " \t\n")) != NULL);
  return ret + 1;
}


x86 assembly (clang, -O0):
<parse_key_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe87(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ae <parse_key_value+0x5e>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c9 <parse_key_value+0x179>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe35(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11fc <parse_key_value+0xac>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe26(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1208 <parse_key_value+0xb8>
movl   $0x0,-0x68(%rbp)
jmp    120f <parse_key_value+0xbf>
movl   $0x1,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    124f <parse_key_value+0xff>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c9 <parse_key_value+0x179>
jmp    1254 <parse_key_value+0x104>
cmpl   $0x0,-0x64(%rbp)
je     1273 <parse_key_value+0x123>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x64(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0x64(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x64(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd6a(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1254 <parse_key_value+0x104>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_key_value>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xe96(%rip),%rsi
xor    %r14d,%r14d
xor    %edi,%edi
call   1070 <strtok@plt>
test   %rax,%rax
je     11be <parse_key_value+0x6e>
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
lea    0xe70(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
test   %rax,%rax
je     11d8 <parse_key_value+0x88>
lea    0xe71(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1060 <sscanf@plt>
xor    %r14d,%r14d
cmp    $0x1,%eax
sete   %r14b
add    $0x1,%r14d
jmp    11de <parse_key_value+0x8e>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1260 <parse_key_value+0x110>
mov    $0x1,%r14d
lea    0xe32(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     1248 <parse_key_value+0xf8>
mov    %rax,%r13
xor    %ebx,%ebx
lea    0xe19(%rip),%r15
jmp    1230 <parse_key_value+0xe0>
movslq %eax,%rbx
lea    (%r12,%rbx,1),%rdi
mov    %r13,%rsi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
add    %eax,%ebx
xor    %edi,%edi
mov    %r15,%rsi
call   1070 <strtok@plt>
mov    %rax,%r13
test   %rax,%rax
je     1260 <parse_key_value+0x110>
mov    $0x0,%eax
test   %ebx,%ebx
je     1200 <parse_key_value+0xb0>
movslq %ebx,%rax
movb   $0x20,(%r12,%rax,1)
add    $0x1,%ebx
mov    %ebx,%eax
jmp    1200 <parse_key_value+0xb0>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
call   1050 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"No key supplied!\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c" \09\0A\00"
define i32 @parse_key_value(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca [60 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %8
store i32 0, i32* %9
%10 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %68
16: ; preds = %2
%17 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%18 = load i8*, i8** %6
%19 = call i32 @strncpy(i8* %17, i8* %18, i32 31)
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp eq i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %16
%24 = load i8*, i8** %6
%25 = load i32*, i32** %5
%26 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %25)
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %23, %16
store i32 0, i32* %9
br label %30
29: ; preds = %23
store i32 1, i32* %9
br label %30
30: ; preds = %29, %28
%31 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%32 = call i8* @strtok(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, 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 %38
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %68
38: ; preds = %30
br label %39
39: ; preds = %62, %38
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = load i8*, i8** %4
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 32, i8* %46
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %49
49: ; preds = %42, %39
%50 = load i8*, i8** %4
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8*, i8** %6
%55 = call i32 @strncpy(i8* %53, i8* %54, i32 31)
%56 = load i8*, i8** %6
%57 = call i64 @strlen(i8* %56)
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = add nsw i64 %59, %57
%61 = trunc i64 %60 to i32
store i32 %61, i32* %8
br label %62
62: ; preds = %49
%63 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i8* %63, i8** %6
%64 = icmp ne i8* %63, null
br i1 %64, label %39, label %65
65: ; preds = %62
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %3
br label %68
68: ; preds = %65, %35, %13
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"No key supplied!\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c" \09\0A\00"
define i32 @parse_key_value(i8* %0, i32* %1) {
%3 = alloca [60 x i8]
%4 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %43
10: ; preds = %2
%11 = call i32 @strncpy(i8* %4, i8* %5, i32 31)
%12 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%16 = icmp eq i32 %15, 1
%17 = select i1 %16, i32 2, i32 1
br label %18
18: ; preds = %14, %10
%19 = phi i32 [ 1, %10 ], [ %17, %14 ]
%20 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %43
25: ; preds = %18, %33
%26 = phi i8* [ %41, %33 ], [ %20, %18 ]
%27 = phi i32 [ %40, %33 ], [ 0, %18 ]
%28 = icmp eq i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = sext i32 %27 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
store i8 32, i8* %31
%32 = add nsw i32 %27, 1
br label %33
33: ; preds = %29, %25
%34 = phi i32 [ %32, %29 ], [ 0, %25 ]
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = call i32 @strncpy(i8* %36, i8* %26, i32 31)
%38 = call i64 @strlen(i8* dereferenceable(1) %26)
%39 = trunc i64 %38 to i32
%40 = add i32 %34, %39
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %25
43: ; preds = %33, %22, %7
%44 = phi i32 [ 0, %7 ], [ 0, %22 ], [ %19, %33 ]
ret i32 %44
}