#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 */
scalar_t__ xstrcasecmp(char *, char *);
int validate_sorted_tokens(char *toks[]) {
  char **pp;
  char *p, *q;
  if (!toks) {
    return (-1);
  }
  if ((pp = toks) && *pp) {
    for (p = *pp++, q = *pp++; q; p = q, q = *pp++) {
      if (xstrcasecmp(p, q) > 0)
        return (-1);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<validate_sorted_tokens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <validate_sorted_tokens+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <validate_sorted_tokens+0xd1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11da <validate_sorted_tokens+0xca>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11da <validate_sorted_tokens+0xca>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d5 <validate_sorted_tokens+0xc5>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <xstrcasecmp@plt>
cmp    $0x0,%rax
jle    11ad <validate_sorted_tokens+0x9d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <validate_sorted_tokens+0xd1>
jmp    11b2 <validate_sorted_tokens+0xa2>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    117f <validate_sorted_tokens+0x6f>
jmp    11da <validate_sorted_tokens+0xca>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_sorted_tokens>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     1162 <validate_sorted_tokens+0x52>
mov    %rdi,%rbx
mov    (%rdi),%rbp
test   %rbp,%rbp
je     115f <validate_sorted_tokens+0x4f>
mov    0x8(%rbx),%rax
test   %rax,%rax
je     115f <validate_sorted_tokens+0x4f>
add    $0x10,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rax,%rbp
mov    %rax,%rsi
call   1030 <xstrcasecmp@plt>
test   %rax,%rax
jg     1162 <validate_sorted_tokens+0x52>
mov    (%rbx),%rax
add    $0x8,%rbx
test   %rax,%rax
jne    1140 <validate_sorted_tokens+0x30>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @validate_sorted_tokens(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 = icmp ne i8** %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 -1, i32* %2
br label %41
10: ; preds = %1
%11 = load i8**, i8*** %3
store i8** %11, i8*** %4
%12 = icmp ne i8** %11, null
br i1 %12, label %13, label %40
13: ; preds = %10
%14 = load i8**, i8*** %4
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %40
17: ; preds = %13
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i32 1
store i8** %19, i8*** %4
%20 = load i8*, i8** %18
store i8* %20, i8** %5
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i32 1
store i8** %22, i8*** %4
%23 = load i8*, i8** %21
store i8* %23, i8** %6
br label %24
24: ; preds = %34, %17
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = load i8*, i8** %5
%29 = load i8*, i8** %6
%30 = call i64 @xstrcasecmp(i8* %28, i8* %29)
%31 = icmp sgt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 -1, i32* %2
br label %41
33: ; preds = %27
br label %34
34: ; preds = %33
%35 = load i8*, i8** %6
store i8* %35, i8** %5
%36 = load i8**, i8*** %4
%37 = getelementptr inbounds i8*, i8** %36, i32 1
store i8** %37, i8*** %4
%38 = load i8*, i8** %36
store i8* %38, i8** %6
br label %24
39: ; preds = %24
br label %40
40: ; preds = %39, %13, %10
store i32 0, i32* %2
br label %41
41: ; preds = %40, %32, %9
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
define i32 @validate_sorted_tokens(i8** %0) {
%2 = icmp eq i8** %0, null
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8*, i8** %0, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8*, i8** %0, i64 2
br label %16
12: ; preds = %16
%13 = getelementptr inbounds i8*, i8** %19, i64 1
%14 = load i8*, i8** %19
%15 = icmp eq i8* %14, null
br i1 %15, label %22, label %16
16: ; preds = %10, %12
%17 = phi i8* [ %14, %12 ], [ %8, %10 ]
%18 = phi i8* [ %17, %12 ], [ %4, %10 ]
%19 = phi i8** [ %13, %12 ], [ %11, %10 ]
%20 = tail call i64 @xstrcasecmp(i8* %18, i8* %17)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %12
22: ; preds = %16, %12, %6, %3, %1
%23 = phi i32 [ -1, %1 ], [ 0, %3 ], [ 0, %6 ], [ -1, %16 ], [ 0, %12 ]
ret i32 %23
}