#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 list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ list_append(struct list *, char *);
struct list *list_create();
int /*<<< orphan*/ list_deep_free(struct list *);
char *malloc(size_t const);
int /*<<< orphan*/ memcpy(char *, char const *, size_t const);
struct list *imv_bind_parse_keys(const char *keys) {
  struct list *list = list_create();
  while (*keys) {
    if (*keys == '<') {
      const char *end = keys;
      while (*end && *end != '>') {
        ++end;
      }
      if (*end == '>') {
        const size_t key_len = end - keys;
        char *key = malloc(key_len);
        memcpy(key, keys + 1, key_len - 1);
        key[key_len - 1] = 0;
        list_append(list, key);
        keys = end + 1;
      } else {
        list_deep_free(list);
        return NULL;
      }
    } else {
      char *item = malloc(2);
      item[0] = *keys;
      item[1] = 0;
      list_append(list, item);
      ++keys;
    }
  }
  return list;
}


x86 assembly (clang, -O0):
<imv_bind_parse_keys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <list_create@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     12a0 <imv_bind_parse_keys+0x150>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3c,%eax
jne    1260 <imv_bind_parse_keys+0x110>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     11b1 <imv_bind_parse_keys+0x61>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3e,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11c1 <imv_bind_parse_keys+0x71>
jmp    11d2 <imv_bind_parse_keys+0x82>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118c <imv_bind_parse_keys+0x3c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3e,%eax
jne    1245 <imv_bind_parse_keys+0xf5>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <list_append@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    125b <imv_bind_parse_keys+0x10b>
mov    -0x18(%rbp),%rdi
call   1060 <list_deep_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a8 <imv_bind_parse_keys+0x158>
jmp    129b <imv_bind_parse_keys+0x14b>
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <list_append@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1167 <imv_bind_parse_keys+0x17>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imv_bind_parse_keys>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <list_create@plt>
mov    %rax,%r14
mov    (%r15),%bl
cmp    $0x3c,%bl
je     11a0 <imv_bind_parse_keys+0x50>
test   %bl,%bl
je     1213 <imv_bind_parse_keys+0xc3>
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %bl,(%rax)
movb   $0x0,0x1(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <list_append@plt>
add    $0x1,%r15
jmp    1166 <imv_bind_parse_keys+0x16>
nopw   0x0(%rax,%rax,1)
xor    %r13d,%r13d
test   %bl,%bl
je     1208 <imv_bind_parse_keys+0xb8>
nopw   0x0(%rax,%rax,1)
cmp    $0x3e,%bl
je     11d0 <imv_bind_parse_keys+0x80>
movzbl 0x1(%r15,%r13,1),%ebx
add    $0x1,%r13
test   %bl,%bl
jne    11b0 <imv_bind_parse_keys+0x60>
jmp    1208 <imv_bind_parse_keys+0xb8>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
lea    0x1(%r15),%rsi
lea    -0x1(%r13),%rdx
mov    %rax,%rdi
call   1040 <memcpy@plt>
movb   $0x0,-0x1(%r12,%r13,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <list_append@plt>
add    %r13,%r15
add    $0x1,%r15
jmp    1166 <imv_bind_parse_keys+0x16>
mov    %r14,%rdi
call   1060 <list_deep_free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.list = type { i32 }
define %struct.list* @imv_bind_parse_keys(i8* %0) {
%2 = alloca %struct.list*
%3 = alloca i8*
%4 = alloca %struct.list*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
%9 = call %struct.list* (...) @list_create()
store %struct.list* %9, %struct.list** %4
br label %10
10: ; preds = %81, %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %82
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 60
br i1 %18, label %19, label %68
19: ; preds = %14
%20 = load i8*, i8** %3
store i8* %20, i8** %5
br label %21
21: ; preds = %33, %19
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 62
br label %31
31: ; preds = %26, %21
%32 = phi i1 [ false, %21 ], [ %30, %26 ]
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
br label %21
36: ; preds = %31
%37 = load i8*, i8** %5
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 62
br i1 %40, label %41, label %64
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = load i8*, i8** %3
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
store i64 %46, i64* %6
%47 = load i64, i64* %6
%48 = call i8* @malloc(i64 %47)
store i8* %48, i8** %7
%49 = load i8*, i8** %7
%50 = load i8*, i8** %3
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = load i64, i64* %6
%53 = sub i64 %52, 1
%54 = call i32 @memcpy(i8* %49, i8* %51, i64 %53)
%55 = load i8*, i8** %7
%56 = load i64, i64* %6
%57 = sub i64 %56, 1
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 0, i8* %58
%59 = load %struct.list*, %struct.list** %4
%60 = load i8*, i8** %7
%61 = call i32 @list_append(%struct.list* %59, i8* %60)
%62 = load i8*, i8** %5
%63 = getelementptr inbounds i8, i8* %62, i64 1
store i8* %63, i8** %3
br label %67
64: ; preds = %36
%65 = load %struct.list*, %struct.list** %4
%66 = call i32 @list_deep_free(%struct.list* %65)
store %struct.list* null, %struct.list** %2
br label %84
67: ; preds = %41
br label %81
68: ; preds = %14
%69 = call i8* @malloc(i64 2)
store i8* %69, i8** %8
%70 = load i8*, i8** %3
%71 = load i8, i8* %70
%72 = load i8*, i8** %8
%73 = getelementptr inbounds i8, i8* %72, i64 0
store i8 %71, i8* %73
%74 = load i8*, i8** %8
%75 = getelementptr inbounds i8, i8* %74, i64 1
store i8 0, i8* %75
%76 = load %struct.list*, %struct.list** %4
%77 = load i8*, i8** %8
%78 = call i32 @list_append(%struct.list* %76, i8* %77)
%79 = load i8*, i8** %3
%80 = getelementptr inbounds i8, i8* %79, i32 1
store i8* %80, i8** %3
br label %81
81: ; preds = %68, %67
br label %10
82: ; preds = %10
%83 = load %struct.list*, %struct.list** %4
store %struct.list* %83, %struct.list** %2
br label %84
84: ; preds = %82, %64
%85 = load %struct.list*, %struct.list** %2
ret %struct.list* %85
}

LLVM IR (-O2):
%struct.list = type { i32 }
define %struct.list* @imv_bind_parse_keys(i8* %0) {
%2 = tail call %struct.list* (...) @list_create()
br label %3
3: ; preds = %28, %1
%4 = phi i8* [ %0, %1 ], [ %30, %28 ]
%5 = load i8, i8* %4
switch i8 %5, label %24 [
i8 0, label %31
i8 60, label %6
]
6: ; preds = %3, %9
%7 = phi i8 [ %11, %9 ], [ %5, %3 ]
%8 = phi i8* [ %10, %9 ], [ %4, %3 ]
switch i8 %7, label %9 [
i8 62, label %12
i8 0, label %22
]
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = load i8, i8* %10
br label %6
12: ; preds = %6
%13 = ptrtoint i8* %8 to i64
%14 = ptrtoint i8* %4 to i64
%15 = sub i64 %13, %14
%16 = tail call i8* @malloc(i64 %15)
%17 = getelementptr inbounds i8, i8* %4, i64 1
%18 = add i64 %15, -1
%19 = tail call i32 @memcpy(i8* %16, i8* %17, i64 %18)
%20 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %20
%21 = tail call i32 @list_append(%struct.list* %2, i8* %16)
br label %28
22: ; preds = %6
%23 = tail call i32 @list_deep_free(%struct.list* %2)
br label %31
24: ; preds = %3
%25 = tail call dereferenceable_or_null(2) i8* @malloc(i64 2)
store i8 %5, i8* %25
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8 0, i8* %26
%27 = tail call i32 @list_append(%struct.list* %2, i8* %25)
br label %28
28: ; preds = %12, %24
%29 = phi i8* [ %4, %24 ], [ %8, %12 ]
%30 = getelementptr inbounds i8, i8* %29, i64 1
br label %3
31: ; preds = %3, %22
%32 = phi %struct.list* [ null, %22 ], [ %2, %3 ]
ret %struct.list* %32
}