#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 */
struct param {
  int dummy;
};

/* Variables and functions */
int ENOMEM;
struct param *add_param(char const *, int, char const *, int, char const *, int,
                        struct param **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
scalar_t__ strcmp(char const *, char *);
int strlen(char const *);
int process_parm(const char *key, const char *value, struct param **params) {
  const char *name, *param, *type;
  int namelen, paramlen, typelen;
  struct param *it;
  const char *colon = strchr(value, ':');
  if (colon == NULL) {
    fprintf(stderr,
            "ERROR: "
            "Found invalid \"%s=%s\": missing ':'\n",
            key, value);
    return 0;
  }
  name = value;
  namelen = colon - value;
  if (strcmp(key, "parm") == 0) {
    param = colon + 1;
    paramlen = strlen(param);
    type = NULL;
    typelen = 0;
  } else {
    param = NULL;
    paramlen = 0;
    type = colon + 1;
    typelen = strlen(type);
  }
  it = add_param(name, namelen, param, paramlen, type, typelen, params);
  if (it == NULL) {
    fprintf(stderr, "ERROR: "
                    "Out of memory!\n");
    return -ENOMEM;
  }
  return 0;
}


x86 assembly (clang, -O0):
<process_parm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    11ac <process_parm+0x5c>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1292 <process_parm+0x142>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1208 <process_parm+0xb8>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
jmp    122f <process_parm+0xdf>
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x40(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x44(%rbp),%r9d
mov    -0x20(%rbp),%rax
mov    %rax,(%rsp)
call   1070 <add_param@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    128b <process_parm+0x13b>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    0x2d5f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1292 <process_parm+0x142>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_parm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%r13
mov    %rsi,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     120b <process_parm+0xbb>
mov    %rax,%rbx
mov    %rbp,0x10(%rsp)
mov    %ebx,%r15d
sub    %r14d,%r15d
lea    0xe99(%rip),%rsi
mov    %r13,%rdi
call   1050 <strcmp@plt>
mov    %rax,%rbp
add    $0x1,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %r12d,%r12d
test   %rbp,%rbp
cmovne %rbx,%rbp
mov    $0x0,%ecx
cmove  %eax,%ecx
cmove  %r12d,%eax
cmovne %r12,%rbx
mov    0x10(%rsp),%rdx
mov    %rdx,(%rsp)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %rbp,%r8
mov    %eax,%r9d
call   1070 <add_param@plt>
test   %rax,%rax
jne    122b <process_parm+0xdb>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
xor    %r12d,%r12d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2dda(%rip),%rax
sub    (%rax),%r12d
jmp    122b <process_parm+0xdb>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
xor    %r12d,%r12d
mov    %r13,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.param = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"ERROR: Found invalid \22%s=%s\22: missing ':'\0A\00"
@.str.1 = [5 x i8] c"parm\00"
@.str.2 = [23 x i8] c"ERROR: Out of memory!\0A\00"
@ENOMEM = global i32 0
define i32 @process_parm(i8* %0, i8* %1, %struct.param** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.param**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.param*
%15 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store %struct.param** %2, %struct.param*** %7
%16 = load i8*, i8** %6
%17 = call i8* @strchr(i8* %16, i8 signext 58)
store i8* %17, i8** %15
%18 = load i8*, i8** %15
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %23)
store i32 0, i32* %4
br label %63
25: ; preds = %3
%26 = load i8*, i8** %6
store i8* %26, i8** %8
%27 = load i8*, i8** %15
%28 = load i8*, i8** %6
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
store i32 %32, i32* %11
%33 = load i8*, i8** %5
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %25
%37 = load i8*, i8** %15
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8* %38, i8** %9
%39 = load i8*, i8** %9
%40 = call i32 @strlen(i8* %39)
store i32 %40, i32* %12
store i8* null, i8** %10
store i32 0, i32* %13
br label %46
41: ; preds = %25
store i8* null, i8** %9
store i32 0, i32* %12
%42 = load i8*, i8** %15
%43 = getelementptr inbounds i8, i8* %42, i64 1
store i8* %43, i8** %10
%44 = load i8*, i8** %10
%45 = call i32 @strlen(i8* %44)
store i32 %45, i32* %13
br label %46
46: ; preds = %41, %36
%47 = load i8*, i8** %8
%48 = load i32, i32* %11
%49 = load i8*, i8** %9
%50 = load i32, i32* %12
%51 = load i8*, i8** %10
%52 = load i32, i32* %13
%53 = load %struct.param**, %struct.param*** %7
%54 = call %struct.param* @add_param(i8* %47, i32 %48, i8* %49, i32 %50, i8* %51, i32 %52, %struct.param** %53)
store %struct.param* %54, %struct.param** %14
%55 = load %struct.param*, %struct.param** %14
%56 = icmp eq %struct.param* %55, null
br i1 %56, label %57, label %62
57: ; preds = %46
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%60 = load i32, i32* @ENOMEM
%61 = sub nsw i32 0, %60
store i32 %61, i32* %4
br label %63
62: ; preds = %46
store i32 0, i32* %4
br label %63
63: ; preds = %62, %57, %20
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
%struct.param = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"ERROR: Found invalid \22%s=%s\22: missing ':'\0A\00"
@.str.1 = [5 x i8] c"parm\00"
@.str.2 = [23 x i8] c"ERROR: Out of memory!\0A\00"
@ENOMEM = global i32 0
define i32 @process_parm(i8* %0, i8* %1, %struct.param** %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %29
9: ; preds = %3
%10 = ptrtoint i8* %4 to i64
%11 = ptrtoint i8* %1 to i64
%12 = sub i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
%16 = getelementptr inbounds i8, i8* %4, i64 1
%17 = tail call i32 @strlen(i8* %16)
%18 = select i1 %15, i8* null, i8* %16
%19 = select i1 %15, i32 %17, i32 0
%20 = select i1 %15, i32 0, i32 %17
%21 = select i1 %15, i8* %16, i8* null
%22 = tail call %struct.param* @add_param(i8* %1, i32 %13, i8* %21, i32 %19, i8* %18, i32 %20, %struct.param** %2)
%23 = icmp eq %struct.param* %22, null
br i1 %23, label %24, label %29
24: ; preds = %9
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @ENOMEM
%28 = sub nsw i32 0, %27
br label %29
29: ; preds = %9, %24, %6
%30 = phi i32 [ 0, %6 ], [ %28, %24 ], [ 0, %9 ]
ret i32 %30
}