#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*/ cfg_add(char *, char *, char *, int);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
char *strip(char *, int /*<<< orphan*/);
int /*<<< orphan*/ validchars(char *, int /*<<< orphan*/);
int cfg_cmd(const char *arg) {
  char *key, *val;
  char *buffer;
  buffer = strdup(arg);
  key = strip(buffer, 0);
  for (val = key; *val; val++) {
    if (*val == '=') {
      *val++ = '\0';
      break;
    }
  }
  if (*key == '\0' || *val == '\0') {
    free(buffer);
    return -1;
  }
  if (!validchars(key, 0)) {
    free(buffer);
    return -1;
  }
  cfg_add("", key, val, 1);
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<cfg_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1060 <strip@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ca <cfg_cmd+0x7a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
jne    11b4 <cfg_cmd+0x64>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
jmp    11ca <cfg_cmd+0x7a>
jmp    11b9 <cfg_cmd+0x69>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1180 <cfg_cmd+0x30>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ea <cfg_cmd+0x9a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ff <cfg_cmd+0xaf>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <cfg_cmd+0x101>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1050 <validchars@plt>
cmp    $0x0,%eax
jne    1228 <cfg_cmd+0xd8>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <cfg_cmd+0x101>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdc9(%rip),%rdi
mov    $0x1,%ecx
call   1040 <cfg_add@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfg_cmd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1070 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <strip@plt>
mov    %rax,%r15
mov    %rax,%rbx
nop
movzbl (%rbx),%eax
test   %al,%al
je     1188 <cfg_cmd+0x38>
cmp    $0x3d,%al
je     1181 <cfg_cmd+0x31>
add    $0x1,%rbx
jmp    1170 <cfg_cmd+0x20>
movb   $0x0,(%rbx)
add    $0x1,%rbx
mov    $0xffffffff,%ebp
cmpb   $0x0,(%r15)
je     11bf <cfg_cmd+0x6f>
cmpb   $0x0,(%rbx)
je     11bf <cfg_cmd+0x6f>
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <validchars@plt>
test   %eax,%eax
je     11bf <cfg_cmd+0x6f>
lea    0xe53(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x1,%ecx
call   1040 <cfg_add@plt>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @cfg_cmd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strdup(i8* %7)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = call i8* @strip(i8* %9, i32 0)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
store i8* %11, i8** %5
br label %12
12: ; preds = %25, %1
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 61
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
store i8 0, i8* %22
br label %28
24: ; preds = %16
br label %25
25: ; preds = %24
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
br label %12
28: ; preds = %21, %12
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33, %28
%39 = load i8*, i8** %6
%40 = call i32 @free(i8* %39)
store i32 -1, i32* %2
br label %54
41: ; preds = %33
%42 = load i8*, i8** %4
%43 = call i32 @validchars(i8* %42, i32 0)
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = load i8*, i8** %6
%47 = call i32 @free(i8* %46)
store i32 -1, i32* %2
br label %54
48: ; preds = %41
%49 = load i8*, i8** %4
%50 = load i8*, i8** %5
%51 = call i32 @cfg_add(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %49, i8* %50, i32 1)
%52 = load i8*, i8** %6
%53 = call i32 @free(i8* %52)
store i32 0, i32* %2
br label %54
54: ; preds = %48, %45, %38
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i32 @cfg_cmd(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i8* @strip(i8* %2, i32 0)
br label %4
4: ; preds = %9, %1
%5 = phi i8* [ %3, %1 ], [ %10, %9 ]
%6 = load i8, i8* %5
switch i8 %6, label %9 [
i8 0, label %11
i8 61, label %7
]
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
store i8 0, i8* %5
br label %11
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
11: ; preds = %4, %7
%12 = phi i8* [ %8, %7 ], [ %5, %4 ]
%13 = load i8, i8* %3
%14 = icmp eq i8 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %11
%16 = load i8, i8* %12
%17 = icmp eq i8 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = tail call i32 @validchars(i8* %3, i32 0)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 @cfg_add(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %12, i32 1)
br label %23
23: ; preds = %18, %11, %15, %21
%24 = phi i32 [ 0, %21 ], [ -1, %15 ], [ -1, %11 ], [ -1, %18 ]
%25 = tail call i32 @free(i8* %2)
ret i32 %24
}