#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 *);
scalar_t__ strncmp(char *, char *, int);
int strtol(char *, char **, int);
int chromNameComp(const void *a, const void *b) {
  int an = 0, bn = 0;
  char *ac, *bc;
  char *atrailing, *btrailing;
  ac = (char *)*(char **)a;
  bc = (char *)*(char **)b;
  if (strncmp(ac, "chr", 3) == 0) {
    an = strtol(ac + 3, &atrailing, 10);
  } else {
    an = strtol(ac, &atrailing, 10);
  }
  if (strncmp(bc, "chr", 3) == 0) {
    bn = strtol(bc + 3, &btrailing, 10);
  } else {
    bn = strtol(bc, &btrailing, 10);
  }
  if (an > 0 && bn > 0) {
    if (an == bn) {
      return strcmp(atrailing, btrailing);
    } else {
      return (an < bn ? -1 : 1);
    }
  } else {
    return strcmp(ac, bc);
  }
}


x86 assembly (clang, -O0):
<chromNameComp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%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    0xe91(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11a1 <chromNameComp+0x71>
mov    -0x28(%rbp),%rdi
add    $0x3,%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x1c(%rbp)
jmp    11b6 <chromNameComp+0x86>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f3 <chromNameComp+0xc3>
mov    -0x30(%rbp),%rdi
add    $0x3,%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x20(%rbp)
jmp    1208 <chromNameComp+0xd8>
mov    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    125a <chromNameComp+0x12a>
cmpl   $0x0,-0x20(%rbp)
jle    125a <chromNameComp+0x12a>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    123d <chromNameComp+0x10d>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    126a <chromNameComp+0x13a>
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%esi
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    126a <chromNameComp+0x13a>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chromNameComp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%rbx
mov    (%rsi),%r14
lea    0xebb(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1161 <chromNameComp+0x31>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
jmp    116a <chromNameComp+0x3a>
lea    0x3(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ebp
lea    0xe83(%rip),%rsi
mov    %r14,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1197 <chromNameComp+0x67>
mov    %rsp,%rsi
mov    %r14,%rdi
jmp    119e <chromNameComp+0x6e>
lea    0x3(%r14),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
test   %ebp,%ebp
jle    11bf <chromNameComp+0x8f>
test   %eax,%eax
jle    11bf <chromNameComp+0x8f>
cmp    %eax,%ebp
jne    11d2 <chromNameComp+0xa2>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
jmp    11c5 <chromNameComp+0x95>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <strcmp@plt>
setae  %al
movzbl %al,%eax
add    %eax,%eax
add    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"chr\00"
define i32 @chromNameComp(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
%12 = load i8*, i8** %4
%13 = bitcast i8* %12 to i8**
%14 = load i8*, i8** %13
store i8* %14, i8** %8
%15 = load i8*, i8** %5
%16 = bitcast i8* %15 to i8**
%17 = load i8*, i8** %16
store i8* %17, i8** %9
%18 = load i8*, i8** %8
%19 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = load i8*, i8** %8
%23 = getelementptr inbounds i8, i8* %22, i64 3
%24 = call i32 @strtol(i8* %23, i8** %10, i32 10)
store i32 %24, i32* %6
br label %28
25: ; preds = %2
%26 = load i8*, i8** %8
%27 = call i32 @strtol(i8* %26, i8** %10, i32 10)
store i32 %27, i32* %6
br label %28
28: ; preds = %25, %21
%29 = load i8*, i8** %9
%30 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i8*, i8** %9
%34 = getelementptr inbounds i8, i8* %33, i64 3
%35 = call i32 @strtol(i8* %34, i8** %11, i32 10)
store i32 %35, i32* %7
br label %39
36: ; preds = %28
%37 = load i8*, i8** %9
%38 = call i32 @strtol(i8* %37, i8** %11, i32 10)
store i32 %38, i32* %7
br label %39
39: ; preds = %36, %32
%40 = load i32, i32* %6
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %59
42: ; preds = %39
%43 = load i32, i32* %7
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %59
45: ; preds = %42
%46 = load i32, i32* %6
%47 = load i32, i32* %7
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i8*, i8** %10
%51 = load i8*, i8** %11
%52 = call i32 @strcmp(i8* %50, i8* %51)
store i32 %52, i32* %3
br label %63
53: ; preds = %45
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = icmp slt i32 %54, %55
%57 = zext i1 %56 to i64
%58 = select i1 %56, i32 -1, i32 1
store i32 %58, i32* %3
br label %63
59: ; preds = %42, %39
%60 = load i8*, i8** %8
%61 = load i8*, i8** %9
%62 = call i32 @strcmp(i8* %60, i8* %61)
store i32 %62, i32* %3
br label %63
63: ; preds = %59, %53, %49
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [4 x i8] c"chr\00"
define i32 @chromNameComp(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = bitcast i8* %0 to i8**
%8 = load i8*, i8** %7
%9 = bitcast i8* %1 to i8**
%10 = load i8*, i8** %9
%11 = tail call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = getelementptr inbounds i8, i8* %8, i64 3
%15 = call i32 @strtol(i8* %14, i8** %3, i32 10)
br label %18
16: ; preds = %2
%17 = call i32 @strtol(i8* %8, i8** %3, i32 10)
br label %18
18: ; preds = %16, %13
%19 = phi i32 [ %15, %13 ], [ %17, %16 ]
%20 = tail call i64 @strncmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = getelementptr inbounds i8, i8* %10, i64 3
%24 = call i32 @strtol(i8* %23, i8** %4, i32 10)
br label %27
25: ; preds = %18
%26 = call i32 @strtol(i8* %10, i8** %4, i32 10)
br label %27
27: ; preds = %25, %22
%28 = phi i32 [ %24, %22 ], [ %26, %25 ]
%29 = icmp sgt i32 %19, 0
%30 = icmp sgt i32 %28, 0
%31 = select i1 %29, i1 %30, i1 false
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = icmp eq i32 %19, %28
br i1 %33, label %34, label %38
34: ; preds = %32
%35 = load i8*, i8** %3
%36 = load i8*, i8** %4
%37 = tail call i32 @strcmp(i8* dereferenceable(1) %35, i8* dereferenceable(1) %36)
br label %43
38: ; preds = %32
%39 = icmp ult i32 %19, %28
%40 = select i1 %39, i32 -1, i32 1
br label %43
41: ; preds = %27
%42 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(1) %10)
br label %43
43: ; preds = %41, %38, %34
%44 = phi i32 [ %37, %34 ], [ %40, %38 ], [ %42, %41 ]
ret i32 %44
}