#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int stat(char const *, struct stat *);
int strcasecmp(char const *, char const *);
int diralphasort(const void *va, const void *vb) {
  struct stat fileinfo;
  const char *a = *(char *const *)va, *b = *(char *const *)vb;
  int aisdir = stat(a, &fileinfo) != -1 && S_ISDIR(fileinfo.st_mode);
  int bisdir = stat(b, &fileinfo) != -1 && S_ISDIR(fileinfo.st_mode);
  if (aisdir != 0 && bisdir == 0)
    return -1;
  if (aisdir == 0 && bisdir != 0)
    return 1;
  return strcasecmp(a, b);
}


x86 assembly (clang, -O0):
<diralphasort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x39(%rbp)
je     1185 <diralphasort+0x55>
mov    -0x20(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x3a(%rbp)
je     11bf <diralphasort+0x8f>
mov    -0x20(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11ea <diralphasort+0xba>
cmpl   $0x0,-0x38(%rbp)
jne    11ea <diralphasort+0xba>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <diralphasort+0xea>
cmpl   $0x0,-0x34(%rbp)
jne    120a <diralphasort+0xda>
cmpl   $0x0,-0x38(%rbp)
je     120a <diralphasort+0xda>
movl   $0x1,-0x4(%rbp)
jmp    121a <diralphasort+0xea>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcasecmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diralphasort>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%rbx
mov    (%rsi),%r14
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     1162 <diralphasort+0x32>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
setne  %bpl
jmp    1164 <diralphasort+0x34>
xor    %ebp,%ebp
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     1187 <diralphasort+0x57>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
setne  %cl
jmp    1189 <diralphasort+0x59>
xor    %ecx,%ecx
mov    %ecx,%edx
xor    $0x1,%dl
mov    $0xffffffff,%eax
test   %dl,%bpl
jne    11a5 <diralphasort+0x75>
not    %bpl
mov    $0x1,%eax
test   %cl,%bpl
je     11ae <diralphasort+0x7e>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strcasecmp@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @diralphasort(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to i8**
%13 = load i8*, i8** %12
store i8* %13, i8** %7
%14 = load i8*, i8** %5
%15 = bitcast i8* %14 to i8**
%16 = load i8*, i8** %15
store i8* %16, i8** %8
%17 = load i8*, i8** %7
%18 = call i32 @stat(i8* %17, %struct.stat* %6)
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @S_ISDIR(i32 %22)
%24 = icmp ne i64 %23, 0
br label %25
25: ; preds = %20, %2
%26 = phi i1 [ false, %2 ], [ %24, %20 ]
%27 = zext i1 %26 to i32
store i32 %27, i32* %9
%28 = load i8*, i8** %8
%29 = call i32 @stat(i8* %28, %struct.stat* %6)
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i64 @S_ISDIR(i32 %33)
%35 = icmp ne i64 %34, 0
br label %36
36: ; preds = %31, %25
%37 = phi i1 [ false, %25 ], [ %35, %31 ]
%38 = zext i1 %37 to i32
store i32 %38, i32* %10
%39 = load i32, i32* %9
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = load i32, i32* %10
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 -1, i32* %3
br label %56
45: ; preds = %41, %36
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* %10
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %48
store i32 1, i32* %3
br label %56
52: ; preds = %48, %45
%53 = load i8*, i8** %7
%54 = load i8*, i8** %8
%55 = call i32 @strcasecmp(i8* %53, i8* %54)
store i32 %55, i32* %3
br label %56
56: ; preds = %52, %51, %44
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @diralphasort(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = bitcast i8* %0 to i8**
%6 = load i8*, i8** %5
%7 = bitcast i8* %1 to i8**
%8 = load i8*, i8** %7
%9 = call i32 @stat(i8* %6, %struct.stat* %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i64 @S_ISDIR(i32 %13)
%15 = icmp ne i64 %14, 0
br label %16
16: ; preds = %11, %2
%17 = phi i1 [ false, %2 ], [ %15, %11 ]
%18 = call i32 @stat(i8* %8, %struct.stat* %3)
%19 = icmp eq i32 %18, -1
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%22 = load i32, i32* %21
%23 = tail call i64 @S_ISDIR(i32 %22)
%24 = icmp ne i64 %23, 0
br label %25
25: ; preds = %20, %16
%26 = phi i1 [ false, %16 ], [ %24, %20 ]
%27 = xor i1 %26, true
%28 = select i1 %17, i1 %27, i1 false
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = xor i1 %17, true
%31 = select i1 %30, i1 %26, i1 false
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = tail call i32 @strcasecmp(i8* %6, i8* %8)
br label %34
34: ; preds = %29, %25, %32
%35 = phi i32 [ %33, %32 ], [ -1, %25 ], [ 1, %29 ]
ret i32 %35
}