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

/* Variables and functions */
int /*<<< orphan*/ getext(int /*<<< orphan*/);
int ialphasort(void const *, void const *);
int strcoll(int /*<<< orphan*/, int /*<<< orphan*/);
int extsort(const void *a, const void *b) {
  struct dirent **a2 = (struct dirent **)a;
  struct dirent **b2 = (struct dirent **)b;
  int result = strcoll(getext((*a2)->d_name), getext((*b2)->d_name));
  return result == 0 ? ialphasort(a, b) : result;
}


x86 assembly (clang, -O0):
<extsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1040 <getext@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1040 <getext@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%esi
call   1050 <strcoll@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    119b <extsort+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ialphasort@plt>
mov    %eax,-0x2c(%rbp)
jmp    11a1 <extsort+0x71>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extsort>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rax
mov    (%rax),%edi
call   1040 <getext@plt>
mov    %eax,%ebp
mov    (%r14),%rax
mov    (%rax),%edi
call   1040 <getext@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <strcoll@plt>
test   %eax,%eax
je     1162 <extsort+0x32>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <ialphasort@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
define i32 @extsort(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.dirent**
%6 = alloca %struct.dirent**
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to %struct.dirent**
store %struct.dirent** %9, %struct.dirent*** %5
%10 = load i8*, i8** %4
%11 = bitcast i8* %10 to %struct.dirent**
store %struct.dirent** %11, %struct.dirent*** %6
%12 = load %struct.dirent**, %struct.dirent*** %5
%13 = load %struct.dirent*, %struct.dirent** %12
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @getext(i32 %15)
%17 = load %struct.dirent**, %struct.dirent*** %6
%18 = load %struct.dirent*, %struct.dirent** %17
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @getext(i32 %20)
%22 = call i32 @strcoll(i32 %16, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %2
%26 = load i8*, i8** %3
%27 = load i8*, i8** %4
%28 = call i32 @ialphasort(i8* %26, i8* %27)
br label %31
29: ; preds = %2
%30 = load i32, i32* %7
br label %31
31: ; preds = %29, %25
%32 = phi i32 [ %28, %25 ], [ %30, %29 ]
ret i32 %32
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
define i32 @extsort(i8* %0, i8* %1) {
%3 = bitcast i8* %0 to %struct.dirent**
%4 = bitcast i8* %1 to %struct.dirent**
%5 = load %struct.dirent*, %struct.dirent** %3
%6 = getelementptr inbounds %struct.dirent, %struct.dirent* %5, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @getext(i32 %7)
%9 = load %struct.dirent*, %struct.dirent** %4
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @getext(i32 %11)
%13 = tail call i32 @strcoll(i32 %8, i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 @ialphasort(i8* %0, i8* %1)
br label %17
17: ; preds = %2, %15
%18 = phi i32 [ %16, %15 ], [ %13, %2 ]
ret i32 %18
}