#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 */
short memcmp(char *, char *, int);
int dirsort(char *p1, char *p2) {
  short j;
  if (j = memcmp(p1, p2, 12))
    return j;
  if ((j = (p1[14] * 32 + p1[12]) - (p2[14] * 32 + p2[12])) > 0)
    return -1;
  else
    return 1;
}


x86 assembly (clang, -O0):
<dirsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1030 <memcmp@plt>
mov    %ax,-0x1a(%rbp)
cmp    $0x0,%ax
je     114c <dirsort+0x3c>
movswl -0x1a(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1199 <dirsort+0x89>
mov    -0x10(%rbp),%rax
movsbl 0xe(%rax),%eax
shl    $0x5,%eax
mov    -0x10(%rbp),%rcx
movsbl 0xc(%rcx),%ecx
add    %ecx,%eax
mov    -0x18(%rbp),%rcx
movsbl 0xe(%rcx),%ecx
shl    $0x5,%ecx
mov    -0x18(%rbp),%rdx
movsbl 0xc(%rdx),%edx
add    %edx,%ecx
sub    %ecx,%eax
mov    %ax,-0x1a(%rbp)
cwtl
cmp    $0x0,%eax
jle    1192 <dirsort+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <dirsort+0x89>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirsort>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0xc,%edx
call   1030 <memcmp@plt>
test   %ax,%ax
je     112c <dirsort+0x1c>
cwtl
jmp    1155 <dirsort+0x45>
movsbl 0xe(%rbx),%eax
shl    $0x5,%eax
movsbl 0xc(%rbx),%ecx
add    %eax,%ecx
movsbl 0xe(%r14),%eax
shl    $0x5,%eax
movsbl 0xc(%r14),%edx
add    %eax,%edx
xor    %eax,%eax
cmp    %dx,%cx
setle  %al
add    %eax,%eax
add    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @dirsort(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i16
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i8*, i8** %5
%9 = call signext i16 @memcmp(i8* %7, i8* %8, i32 12)
store i16 %9, i16* %6
%10 = icmp ne i16 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i16, i16* %6
%13 = sext i16 %12 to i32
store i32 %13, i32* %3
br label %41
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 14
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = mul nsw i32 %18, 32
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 12
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = add nsw i32 %19, %23
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 14
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = mul nsw i32 %28, 32
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 12
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = add nsw i32 %29, %33
%35 = sub nsw i32 %24, %34
%36 = trunc i32 %35 to i16
store i16 %36, i16* %6
%37 = sext i16 %36 to i32
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %14
store i32 -1, i32* %3
br label %41
40: ; preds = %14
store i32 1, i32* %3
br label %41
41: ; preds = %40, %39, %11
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @dirsort(i8* %0, i8* %1) {
%3 = tail call signext i16 @memcmp(i8* %0, i8* %1, i32 12)
%4 = icmp eq i16 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = sext i16 %3 to i32
br label %26
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %0, i64 14
%9 = load i8, i8* %8
%10 = sext i8 %9 to i16
%11 = shl nsw i16 %10, 5
%12 = getelementptr inbounds i8, i8* %0, i64 12
%13 = load i8, i8* %12
%14 = sext i8 %13 to i16
%15 = add nsw i16 %11, %14
%16 = getelementptr inbounds i8, i8* %1, i64 14
%17 = load i8, i8* %16
%18 = sext i8 %17 to i16
%19 = shl nsw i16 %18, 5
%20 = getelementptr inbounds i8, i8* %1, i64 12
%21 = load i8, i8* %20
%22 = sext i8 %21 to i16
%23 = add nsw i16 %19, %22
%24 = icmp sgt i16 %15, %23
%25 = select i1 %24, i32 -1, i32 1
br label %26
26: ; preds = %7, %5
%27 = phi i32 [ %6, %5 ], [ %25, %7 ]
ret i32 %27
}