#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 u_int8_t;

/* Variables and functions */
char *kore_text_trim(char *, int /*<<< orphan*/);
int /*<<< orphan*/ kore_validator_add(char *, int, char *);
int /*<<< orphan*/ printf(char *, ...);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int configure_validator(char *name) {
  u_int8_t type;
  char *tname, *value;
  if ((tname = strchr(name, ' ')) == NULL) {
    printf("missing validator name\n");
    return (0);
  }
  *(tname)++ = '\0';
  tname = kore_text_trim(tname, strlen(tname));
  if ((value = strchr(tname, ' ')) == NULL) {
    printf("missing validator value\n");
    return (0);
  }
  *(value)++ = '\0';
  value = kore_text_trim(value, strlen(value));
  if (!strcmp(tname, "regex")) {
    type = 1;
  } else if (!strcmp(tname, "function")) {
    type = 2;
  } else {
    printf("bad type for validator %s\n", tname);
    return (0);
  }
  if (!kore_validator_add(name, type, value)) {
    printf("bad validator specified: %s\n", tname);
    return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<configure_validator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a2 <configure_validator+0x42>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <configure_validator+0x187>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1080 <kore_text_trim@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    120a <configure_validator+0xaa>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <configure_validator+0x187>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1080 <kore_text_trim@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1261 <configure_validator+0x101>
movl   $0x1,-0x14(%rbp)
jmp    12a9 <configure_validator+0x149>
mov    -0x20(%rbp),%rdi
lea    0xdcb(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1286 <configure_validator+0x126>
movl   $0x2,-0x14(%rbp)
jmp    12a4 <configure_validator+0x144>
mov    -0x20(%rbp),%rsi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <configure_validator+0x187>
jmp    12a9 <configure_validator+0x149>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1030 <kore_validator_add@plt>
cmp    $0x0,%eax
jne    12e0 <configure_validator+0x180>
mov    -0x20(%rbp),%rsi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <configure_validator+0x187>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configure_validator>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x20,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1216 <configure_validator+0xa6>
mov    %rax,%rbp
add    $0x1,%rbp
movb   $0x0,(%rax)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1090 <kore_text_trim@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     121f <configure_validator+0xaf>
mov    %rax,%rbp
add    $0x1,%rbp
movb   $0x0,(%rax)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1090 <kore_text_trim@plt>
mov    %rax,%r15
lea    0xe1c(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcmp@plt>
mov    $0x1,%ebp
mov    $0x1,%esi
test   %eax,%eax
je     1234 <configure_validator+0xc4>
lea    0xe05(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
je     122f <configure_validator+0xbf>
lea    0xdfb(%rip),%rdi
jmp    124a <configure_validator+0xda>
lea    0xe42(%rip),%rdi
jmp    1226 <configure_validator+0xb6>
lea    0xe21(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
jmp    1256 <configure_validator+0xe6>
mov    $0x2,%esi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1030 <kore_validator_add@plt>
test   %eax,%eax
jne    1256 <configure_validator+0xe6>
lea    0xde0(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"missing validator name\0A\00"
@.str.1 = [25 x i8] c"missing validator value\0A\00"
@.str.2 = [6 x i8] c"regex\00"
@.str.3 = [9 x i8] c"function\00"
@.str.4 = [27 x i8] c"bad type for validator %s\0A\00"
@.str.5 = [29 x i8] c"bad validator specified: %s\0A\00"
define i32 @configure_validator(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 32)
store i8* %8, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %54
12: ; preds = %1
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
store i8 0, i8* %13
%15 = load i8*, i8** %5
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = call i8* @kore_text_trim(i8* %15, i32 %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = call i8* @strchr(i8* %19, i8 signext 32)
store i8* %20, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %54
24: ; preds = %12
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
store i8 0, i8* %25
%27 = load i8*, i8** %6
%28 = load i8*, i8** %6
%29 = call i32 @strlen(i8* %28)
%30 = call i8* @kore_text_trim(i8* %27, i32 %29)
store i8* %30, i8** %6
%31 = load i8*, i8** %5
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %24
store i32 1, i32* %4
br label %44
35: ; preds = %24
%36 = load i8*, i8** %5
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %35
store i32 2, i32* %4
br label %43
40: ; preds = %35
%41 = load i8*, i8** %5
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %41)
store i32 0, i32* %2
br label %54
43: ; preds = %39
br label %44
44: ; preds = %43, %34
%45 = load i8*, i8** %3
%46 = load i32, i32* %4
%47 = load i8*, i8** %6
%48 = call i32 @kore_validator_add(i8* %45, i32 %46, i8* %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %44
%51 = load i8*, i8** %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %51)
store i32 0, i32* %2
br label %54
53: ; preds = %44
store i32 1, i32* %2
br label %54
54: ; preds = %53, %50, %40, %22, %10
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@.str.2 = [6 x i8] c"regex\00"
@.str.3 = [9 x i8] c"function\00"
@.str.4 = [27 x i8] c"bad type for validator %s\0A\00"
@.str.5 = [29 x i8] c"bad validator specified: %s\0A\00"
@str = [24 x i8] c"missing validator value\00"
@str.6 = [23 x i8] c"missing validator name\00"
define i32 @configure_validator(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
br label %31
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %2, i64 1
store i8 0, i8* %2
%8 = tail call i32 @strlen(i8* %7)
%9 = tail call i8* @kore_text_trim(i8* %7, i32 %8)
%10 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 32)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %31
14: ; preds = %6
%15 = getelementptr inbounds i8, i8* %10, i64 1
store i8 0, i8* %10
%16 = tail call i32 @strlen(i8* %15)
%17 = tail call i8* @kore_text_trim(i8* %15, i32 %16)
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %14
%21 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %9)
br label %31
25: ; preds = %20, %14
%26 = phi i32 [ 1, %14 ], [ 2, %20 ]
%27 = tail call i32 @kore_validator_add(i8* %0, i32 %26, i8* %17)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %9)
br label %31
31: ; preds = %25, %29, %23, %12, %4
%32 = phi i32 [ 0, %4 ], [ 0, %12 ], [ 0, %23 ], [ 0, %29 ], [ 1, %25 ]
ret i32 %32
}