#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*/ printf(char *);
scalar_t__ strcasecmp(char *, char *);
char *strtok_r(char *, char *, char **);
int check_sort_criteria(char *sortCriteria) {
  char *item, *saveptr;
  int i, ret, reverse, title_sorted = 0;
  int ret_value = 0;
  item = strtok_r(sortCriteria, ",", &saveptr);
  for (i = 0; item != NULL; i++) {
    reverse = 0;
    if (*item == '+') {
      item++;
    } else if (*item == '-') {
      reverse = 1;
      item++;
    } else {
      {};
      ret_value = -1;
      goto unhandled_order;
    }
    if (strcasecmp(item, "upnp:class") == 0) {
    } else if (strcasecmp(item, "dc:title") == 0) {
    } else if (strcasecmp(item, "dc:date") == 0) {
    } else if (strcasecmp(item, "upnp:originalTrackNumber") == 0) {
    } else if (strcasecmp(item, "upnp:album") == 0) {
    } else {
      {};
      ret_value = -1;
      printf("unhandled sort Criteria\n");
      goto unhandled_order;
    }
  unhandled_order:
    if (ret_value == -1)
      return ret_value;
    item = strtok_r(NULL, ",", &saveptr);
  }
  return ret_value;
}


x86 assembly (clang, -O0):
<check_sort_criteria>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12dc <check_sort_criteria+0x1ac>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    119c <check_sort_criteria+0x6c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11d5 <check_sort_criteria+0xa5>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11c4 <check_sort_criteria+0x94>
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11d0 <check_sort_criteria+0xa0>
movl   $0xffffffff,-0x34(%rbp)
jmp    12a1 <check_sort_criteria+0x171>
jmp    11d5 <check_sort_criteria+0xa5>
mov    -0x18(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11f4 <check_sort_criteria+0xc4>
jmp    129c <check_sort_criteria+0x16c>
mov    -0x18(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1213 <check_sort_criteria+0xe3>
jmp    1297 <check_sort_criteria+0x167>
mov    -0x18(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1232 <check_sort_criteria+0x102>
jmp    1292 <check_sort_criteria+0x162>
mov    -0x18(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1251 <check_sort_criteria+0x121>
jmp    128d <check_sort_criteria+0x15d>
mov    -0x18(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1270 <check_sort_criteria+0x140>
jmp    1288 <check_sort_criteria+0x158>
movl   $0xffffffff,-0x34(%rbp)
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
jmp    12a1 <check_sort_criteria+0x171>
jmp    128d <check_sort_criteria+0x15d>
jmp    1292 <check_sort_criteria+0x162>
jmp    1297 <check_sort_criteria+0x167>
jmp    129c <check_sort_criteria+0x16c>
jmp    12a1 <check_sort_criteria+0x171>
cmpl   $0xffffffff,-0x34(%rbp)
jne    12b6 <check_sort_criteria+0x186>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12e2 <check_sort_criteria+0x1b2>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd3f(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1169 <check_sort_criteria+0x39>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_sort_criteria>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rsi
mov    %rsp,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     120e <check_sort_criteria+0xde>
mov    %rax,%rbp
lea    0xea5(%rip),%r14
lea    0xe9c(%rip),%r15
mov    %rsp,%r12
lea    0xe9f(%rip),%r13
jmp    118b <check_sort_criteria+0x5b>
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1210 <check_sort_criteria+0xe0>
movzbl 0x0(%rbp),%eax
mov    $0xffffffff,%ebx
cmp    $0x2d,%al
je     119c <check_sort_criteria+0x6c>
cmp    $0x2b,%al
jne    1210 <check_sort_criteria+0xe0>
add    $0x1,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1170 <check_sort_criteria+0x40>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1170 <check_sort_criteria+0x40>
mov    %rbp,%rdi
lea    0xe4c(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1170 <check_sort_criteria+0x40>
mov    %rbp,%rdi
lea    0xe40(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1170 <check_sort_criteria+0x40>
mov    %rbp,%rdi
lea    0xe45(%rip),%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1170 <check_sort_criteria+0x40>
lea    0xe3b(%rip),%rdi
call   1040 <puts@plt>
jmp    1210 <check_sort_criteria+0xe0>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [11 x i8] c"upnp:class\00"
@.str.2 = [9 x i8] c"dc:title\00"
@.str.3 = [8 x i8] c"dc:date\00"
@.str.4 = [25 x i8] c"upnp:originalTrackNumber\00"
@.str.5 = [11 x i8] c"upnp:album\00"
@.str.6 = [25 x i8] c"unhandled sort Criteria\0A\00"
define i32 @check_sort_criteria(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i8*, i8** %3
%12 = call i8* @strtok_r(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
store i8* %12, i8** %4
store i32 0, i32* %6
br label %13
13: ; preds = %73, %1
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %76
16: ; preds = %13
store i32 0, i32* %8
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 43
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %4
br label %34
24: ; preds = %16
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 45
br i1 %28, label %29, label %32
29: ; preds = %24
store i32 1, i32* %8
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
br label %33
32: ; preds = %24
store i32 -1, i32* %10
br label %66
33: ; preds = %29
br label %34
34: ; preds = %33, %21
%35 = load i8*, i8** %4
%36 = call i64 @strcasecmp(i8* %35, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
br label %65
39: ; preds = %34
%40 = load i8*, i8** %4
%41 = call i64 @strcasecmp(i8* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
br label %64
44: ; preds = %39
%45 = load i8*, i8** %4
%46 = call i64 @strcasecmp(i8* %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44
br label %63
49: ; preds = %44
%50 = load i8*, i8** %4
%51 = call i64 @strcasecmp(i8* %50, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %49
br label %62
54: ; preds = %49
%55 = load i8*, i8** %4
%56 = call i64 @strcasecmp(i8* %55, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %54
br label %61
59: ; preds = %54
store i32 -1, i32* %10
%60 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %66
61: ; preds = %58
br label %62
62: ; preds = %61, %53
br label %63
63: ; preds = %62, %48
br label %64
64: ; preds = %63, %43
br label %65
65: ; preds = %64, %38
br label %66
66: ; preds = %65, %59, %32
%67 = load i32, i32* %10
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %71
69: ; preds = %66
%70 = load i32, i32* %10
store i32 %70, i32* %2
br label %78
71: ; preds = %66
%72 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
store i8* %72, i8** %4
br label %73
73: ; preds = %71
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %13
76: ; preds = %13
%77 = load i32, i32* %10
store i32 %77, i32* %2
br label %78
78: ; preds = %76, %69
%79 = load i32, i32* %2
ret i32 %79
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [11 x i8] c"upnp:class\00"
@.str.2 = [9 x i8] c"dc:title\00"
@.str.3 = [8 x i8] c"dc:date\00"
@.str.4 = [25 x i8] c"upnp:originalTrackNumber\00"
@.str.5 = [11 x i8] c"upnp:album\00"
@str = [24 x i8] c"unhandled sort Criteria\00"
define i32 @check_sort_criteria(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %30, label %6
6: ; preds = %1, %27
%7 = phi i8* [ %28, %27 ], [ %4, %1 ]
%8 = load i8, i8* %7
switch i8 %8, label %30 [
i8 43, label %9
i8 45, label %9
]
9: ; preds = %6, %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = call i64 @strcasecmp(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %9
%14 = call i64 @strcasecmp(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = call i64 @strcasecmp(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %16
%20 = call i64 @strcasecmp(i8* %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = call i64 @strcasecmp(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %30
27: ; preds = %13, %19, %22, %16, %9
%28 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %6
30: ; preds = %6, %27, %1, %25
%31 = phi i32 [ -1, %25 ], [ 0, %1 ], [ -1, %6 ], [ 0, %27 ]
ret i32 %31
}