#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 strcmp(char *, char *);
int stringArrayIx(char *, char **, int);
int cmpStringOrder(char *a, char *b, char **orderFields, int orderCount) {
  int aIx = stringArrayIx(a, orderFields, orderCount);
  int bIx = stringArrayIx(b, orderFields, orderCount);
  if (aIx < 0) {
    if (bIx < 0)
      return (strcmp(a, b));
    else
      return 1;
  } else if (bIx < 0)
    return -1;
  else
    return aIx - bIx;
}


x86 assembly (clang, -O0):
<cmpStringOrder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <stringArrayIx@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <stringArrayIx@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1192 <cmpStringOrder+0x72>
cmpl   $0x0,-0x2c(%rbp)
jge    1186 <cmpStringOrder+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11b1 <cmpStringOrder+0x91>
movl   $0x1,-0x4(%rbp)
jmp    11b1 <cmpStringOrder+0x91>
cmpl   $0x0,-0x2c(%rbp)
jge    11a8 <cmpStringOrder+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <cmpStringOrder+0x91>
mov    -0x28(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmpStringOrder>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rsi
mov    %ecx,%edx
call   1040 <stringArrayIx@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1040 <stringArrayIx@plt>
mov    %eax,%ecx
test   %ebp,%ebp
js     1162 <cmpStringOrder+0x42>
sub    %ecx,%ebp
test   %ecx,%ecx
mov    $0xffffffff,%eax
cmovns %ebp,%eax
jmp    116b <cmpStringOrder+0x4b>
mov    $0x1,%eax
test   %ecx,%ecx
js     1174 <cmpStringOrder+0x54>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strcmp@plt>

LLVM IR (-O0):
define i32 @cmpStringOrder(i8* %0, i8* %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
%13 = load i8**, i8*** %8
%14 = load i32, i32* %9
%15 = call i32 @stringArrayIx(i8* %12, i8** %13, i32 %14)
store i32 %15, i32* %10
%16 = load i8*, i8** %7
%17 = load i8**, i8*** %8
%18 = load i32, i32* %9
%19 = call i32 @stringArrayIx(i8* %16, i8** %17, i32 %18)
store i32 %19, i32* %11
%20 = load i32, i32* %10
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %4
%23 = load i32, i32* %11
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = call i32 @strcmp(i8* %26, i8* %27)
store i32 %28, i32* %5
br label %38
29: ; preds = %22
store i32 1, i32* %5
br label %38
30: ; preds = %4
%31 = load i32, i32* %11
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 -1, i32* %5
br label %38
34: ; preds = %30
%35 = load i32, i32* %10
%36 = load i32, i32* %11
%37 = sub nsw i32 %35, %36
store i32 %37, i32* %5
br label %38
38: ; preds = %34, %33, %29, %25
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
define i32 @cmpStringOrder(i8* %0, i8* %1, i8** %2, i32 %3) {
%5 = tail call i32 @stringArrayIx(i8* %0, i8** %2, i32 %3)
%6 = tail call i32 @stringArrayIx(i8* %1, i8** %2, i32 %3)
%7 = icmp slt i32 %5, 0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = icmp slt i32 %6, 0
br i1 %9, label %10, label %16
10: ; preds = %8
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
br label %16
12: ; preds = %4
%13 = sub nsw i32 %5, %6
%14 = icmp sgt i32 %6, -1
%15 = select i1 %14, i32 %13, i32 -1
br label %16
16: ; preds = %12, %8, %10
%17 = phi i32 [ %11, %10 ], [ 1, %8 ], [ %15, %12 ]
ret i32 %17
}