#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 {
  char *d_name;
};

/* Variables and functions */
int sscanf(char *, char *, char *, char *, int *, int *);
int strcmp(char *, char *);
int cramsort(const void *a, const void *b) {
  char name1[32], name2[32];
  char typ;
  int maj;
  int min;
  char *sa, *sb;
  sa = (*(const struct dirent **)a)->d_name;
  sb = (*(const struct dirent **)b)->d_name;
  if (sscanf(sa, "@%[a-zA-Z0-9_+-],%c,%d,%d", name1, &typ, &maj, &min) == 4)
    sa = name1;
  if (sscanf(sb, "@%[a-zA-Z0-9_+-],%c,%d,%d", name2, &typ, &maj, &min) == 4)
    sb = name2;
  return strcmp(sa, sb);
}


x86 assembly (clang, -O0):
<cramsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xea5(%rip),%rsi
lea    -0x51(%rbp),%rcx
lea    -0x58(%rbp),%r8
lea    -0x5c(%rbp),%r9
call   1040 <sscanf@plt>
cmp    $0x4,%eax
jne    117d <cramsort+0x5d>
lea    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x70(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe74(%rip),%rsi
lea    -0x51(%rbp),%rcx
lea    -0x58(%rbp),%r8
lea    -0x5c(%rbp),%r9
call   1040 <sscanf@plt>
cmp    $0x4,%eax
jne    11ae <cramsort+0x8e>
lea    -0x50(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x70(%rbp),%rsi
call   1030 <strcmp@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cramsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    (%rdi),%rax
mov    (%rax),%r14
mov    (%rsi),%rax
mov    (%rax),%rbx
lea    0xebf(%rip),%r15
lea    0x30(%rsp),%r12
lea    0x7(%rsp),%r13
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <sscanf@plt>
cmp    $0x4,%eax
cmove  %r12,%r14
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
call   1040 <sscanf@plt>
cmp    $0x4,%eax
cmove  %rbp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [26 x i8] c"@%[a-zA-Z0-9_+-],%c,%d,%d\00"
define i32 @cramsort(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%12 = load i8*, i8** %3
%13 = bitcast i8* %12 to %struct.dirent**
%14 = load %struct.dirent*, %struct.dirent** %13
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
store i8* %16, i8** %10
%17 = load i8*, i8** %4
%18 = bitcast i8* %17 to %struct.dirent**
%19 = load %struct.dirent*, %struct.dirent** %18
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 0
%21 = load i8*, i8** %20
store i8* %21, i8** %11
%22 = load i8*, i8** %10
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%24 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %7, i32* %8, i32* %9)
%25 = icmp eq i32 %24, 4
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
store i8* %27, i8** %10
br label %28
28: ; preds = %26, %2
%29 = load i8*, i8** %11
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%31 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %30, i8* %7, i32* %8, i32* %9)
%32 = icmp eq i32 %31, 4
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
store i8* %34, i8** %11
br label %35
35: ; preds = %33, %28
%36 = load i8*, i8** %10
%37 = load i8*, i8** %11
%38 = call i32 @strcmp(i8* %36, i8* %37)
ret i32 %38
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [26 x i8] c"@%[a-zA-Z0-9_+-],%c,%d,%d\00"
define i32 @cramsort(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = bitcast i8* %0 to %struct.dirent**
%13 = load %struct.dirent*, %struct.dirent** %12
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = bitcast i8* %1 to %struct.dirent**
%17 = load %struct.dirent*, %struct.dirent** %16
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %5, i32* %6, i32* %7)
%21 = icmp eq i32 %20, 4
%22 = select i1 %21, i8* %8, i8* %15
%23 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %5, i32* %6, i32* %7)
%24 = icmp eq i32 %23, 4
%25 = select i1 %24, i8* %9, i8* %19
%26 = call i32 @strcmp(i8* dereferenceable(1) %22, i8* dereferenceable(1) %25)
ret i32 %26
}